MQL5 language provides a special group of trade functions designed for developing automated trading systems. Programs developed for automated trading with no human intervention are called Expert Advisors or trading robots. In order to create an Expert Advisor in MetaEditor, launch MQL5 Wizard and select one of the two options:
Trading functions can work only in Expert Advisors and scripts. Trading is not allowed for indicators.
In order to develop a reliable Expert Advisor capable of working without human intervention, it is necessary to arrange a set of important checks. First, we should programmatically check if trading is allowed at all. This is a basic check that is indispensable when developing any automated system.
The terminal settings provide you with an ability to allow or forbid automated trading for all programs.
You can switch automated trading option right on the terminal's Standard panel:
You can allow or forbid automated trading for a certain program when launching it. To do this, use the special check box in the program properties.
Automated trading can be disabled at the trade server side. Sample check:
If automated trading is disabled for a trading account, trading operations of Expert Advisors/scripts are not executed.
In some cases, any trading operations are disabled for a certain trading account neither manual nor automated trading can be performed. Sample check when an investor password has been used to connect to a trading account:
AccountInfoInteger(ACCOUNT_TRADE_ALLOWED) may return false in the following cases: