The OnStart() function is the Start event handler, which is automatically generated only for running scripts. It must be of void type, with no parameters:
void OnStart(); |
For the OnStart() function, the int return type can be specified.
The Start event is a special event for script activation after it is loaded. This event is processed by OnStart handler. The Start event is not send to Expert Advisors or custom indicators.
The NewTick event is generated for Expert Advisors only when a new tick for a symbol is received, to the chart of which the Expert Advisor is attached. It's useless to define the OnTick() function in a custom indicator or script, because the NewTick event is not generated for them.
The Tick event is generated only for Expert Advisors, but this does not mean that Expert Advisors required the OnTick() function, since not only NewTick events are generated for Expert Advisors, but also events of Timer, BookEvent and ChartEvent are generated. It must be declared as the void type, with no parameters:
void OnTick(); |
The NewTick event is generated if there are new quotes, it is processed by OnTick() of Expert Advisors attached. In case when OnTick function for the previous quote is being processed when a new quote is received, the new quote will be ignored by an Expert Advisor, because the corresponding event will not enqueued.
All new quotes that are received while the program is running are ignored until the OnTick() is completed. After that the function will run only after a new quote is received. The NewTick event is generated irrespective of whether automated trade is allowed or not ("Allow/prohibit Auto trading" button). The prohibition of automated trading denotes only that sending of trade requests from an Expert Advisor is not allowed, while the Expert Advisor keeps working.
The prohibition of automated trading by pressing the appropriate button will not stop the current execution of the OnTick() function. OnTick() is not started when the window of Expert Advisor properties is open.
New Function | EA | Indicator | Script |
---|---|---|---|
OnStart | Start | ||
OnInit | Init | Init | Init |
OnDeinit | Deinit | Deinit | Deinit |
OnTick | Start | ||
OnTimer | new | new | n/a |
OnTester | new | n/a | n/a |
OnChartEvent | new | new | n/a |
OnCalculate | Start |
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
what is deference between start() function and tick function in mql4?