Creating an Expert Advisor
Many trading solutions rely on the ability to create a trading bot that scans the market and opens a pre-planned position. Learn to create one.
Creating an Expert Advisor
Before we start, several misconceptions should be destroyed at the outset: automated trading was not created to make life easier but decisions more objective. A human trader may decide not to abandon a losing trade in the unjustified hope that it may reverse, that last often guided by fear of what one’s spouse will say when they discover how much the trader lost. A trading bot does not care about your marriage problems: it is only concerned with the market reality of a given moment. Furthermore, humans need to eat and sleep; bots don’t. And finally, social trading is not a way to meet other traders – it is a means of creating a network of traders that can help maintain efficient markets.
As the field of online trading grows and retail traders proliferate more and more are drawn to social trading – both as a means and as a style. Many social trading solutions rely on the provider’s ability to create a viable trading bot – a mini-program that continuously scans the market or a set of assets awaiting a given situation to open a pre-planned position.
Even if you have no plans to automate your trading, it pays to understand how this is done in order to better evaluate the traders you choose to follow, in order to gauge what are the parameters they use and under what market conditions you should follow them.
MetaEditor and Builders
MetaEditor is a built-in tool that is included in the MT4-5 trading platform. It entails actually writing code a line at a time and could be daunting. The language used is MQL – MetaQuotes Lanquage, followed by a 4 or 5, depending on which trading platform is being used – MetaTrader 4 or 5 – respectively.
Alternatively, easy-to-use builders exist both online and off that create code, based on the inputs provided in a wizard, which can then be imported into MetaTrader. Foremost amongst these is the MQL4/5 Wizard, developed by the MQL community and provided as a plugin to the MetaTrader platform.
First, let’s look at some of the function types that can be created using MQL.
Custom Indicator:
Just as a technical indicator is a ready-made mathematical/ statistical construct that tries to extrapolate past price action to the future, a custom indicator is one created ad hoc by traders/users. Thus, regular indicators cannot be changed but only modified by changing numerical parameters. The workings of a moving average, for example cannot be changed. The user can merely specify which kind he/she wants (simple, exponential…) and its period (5-minute, 2-hour, 10-day…). A custom indicator, on the other hand, can be modified at the code level, thus altering the way it actually works.
Script
A script is a piece of code that executes a single time when its requirements are fulfilled. “Open position z when x is fulfilled” is a very simplistic example of a script. The moment the position is opened it cannot be opened again, i.e., it will not open a new and identical position if the condition arises again. The user creates the requirements, parameters and actions.
Expert Advisor
Like a script, this is an open coded construct, but it does not close down after a single instance. It can be seen as a trading robot that routinely analyses the market and undertakes trading activities autonomously. MetaTrader provides both Expert Advisors built by others and templates for independently creating one’s own EAs.
Creating an EA with the Wizard
When opening the MQL Wizard, the asset (symbol) and timeframe are set by default to the operating chart. However, you can change these later.
Click on “Next” to set the properties of the EA by selecting from MT4/5’s technical indicators. You can list up to 64 of these. Change the type and value of each if you feel the need.
Clicking on “Next” again will allow you to add trailing stops, risk and money management rules and so forth. And Finish generates a page of code, which should be compiled to check for errors.
And save for future use.