MQL4参考 MQL4 程序

MQL4 Programs

For the mql4-program to operate, it must be compiled (Compile button or F7 key). Compilation should pass without errors (some warnings are possible; they should be analyzed). At this process, an executable file with the same name and with EX4 extension must be created in the corresponding directory, terminal_dir\MQL4\Experts, terminal_dir\MQL4\indicators or terminal_dir\MQL4\scripts. This file can be run.

Operating features of MQL4 programs are described in the following sections:

Expert Advisors, custom indicators and scripts are attached to one of opened charts by Drag'n'Drop method from the Navigator window.

For an expert Advisor to stop operating, it should be removed from a chart. To do it select "Expert list" in chart context menu, then select an Expert Advisor from list and click "Remove" button. Operation of Expert Advisors is also affected by the state of the "AutoTrading" button.

In order to stop a custom indicator, it should be removed from a chart.

Custom indicators and Expert Advisors work until they are explicitly removed from a chart; information about attached Expert Advisors and Indicators is saved between client terminal sessions.

Scripts are executed once and are deleted automatically upon operation completion or change of the current chart state, or upon client terminal shutdown. After the restart of the client terminal scripts are not started, because the information about them is not saved.

Maximum one Expert Advisor, one script and unlimited number of indicators can operate in one chart.

 

What's new in MQL5

In MQL5, the entire program logic is based on handling events. The event handling functions allow you to develop trading algorithms, create user interfaces, as well as collect and visualize optimization results. The number of events has increased. The five most important ones are as follows:

  • NewTick –C occurs when new quotes arrive and handled in EAs by the OnTick() function
  • Calculate –C created only for indicators in case of any change in price data and handled by the OnCalculate() function
  • Trade –C generated upon completion of a trading operation on a trade server and handled by the OnTrade()
  • TradeTransaction –C sent by a trade server to the terminal in case of changes on a trading account and handled by the OnTradeTransaction() function
  • BookEvent –C reports Depth of Market changes and handled by the OnBookEvent() function.

Developers of trading robots will appreciate the new tester features described in the articles and documentation. The most notable advantages are as follows:

  • Automatic history download and synchronization of bars on all timeframes –C all the history required for testing is downloaded by the terminal automatically.
  • Using real ticks during a test –C now you can test your trading on history as accurately as possible. Arrival of ticks is emulated on all symbols.
  • Multi-currency testing allows users to develop strategies trading on multiple symbols, while ticks and bars are synchronized correctly on all symbols and the trading environment is emulated accurately, including spreads, margin requirements and profit calculation in the required deposit currency.
  • The OnTimer() and Sleep() functions work in the tester correctly and are available for debugging.
  • The multi-threaded tester uses all CPU cores allowing you to perform optimization on thousands of agents from MQL5 Cloud Network.