Question about Ontick() function

 

Goodmorning everyone. I have been a programmer for many years, but quite new to MQL5. I would like to clarify a doubt.

When I create an EA, the onTick() function (as well as for onCalculate() in indicators) is called when it receives a tick. But is this tick relative only to the symbol where the EA is placed, or is it also called when MT5 receives a tick from other symbols in the market watch ?

... and if it receives only from the symbol of the chart in which the EA is placed, how can I do to create an EA independent of the symbol of the chart to create a multi symbol EA that reacts to the arrival of multiple symbols (without obviously having to insert the EA on various charts with different symbols).

Thank you :)

 
Alessandro:

Goodmorning everyone. I have been a programmer for many years, but quite new to MQL5. I would like to clarify a doubt.

When I create an EA, the onTick() function (as well as for onCalculate() in indicators) is called when it receives a tick. But is this tick relative only to the symbol where the EA is placed, or is it also called when MT5 receives a tick from other symbols in the market watch ?

... and if it receives only from the symbol of the chart in which the EA is placed, how can I do to create an EA independent of the symbol of the chart to create a multi symbol EA that reacts to the arrival of multiple symbols (without obviously having to insert the EA on various charts with different symbols).

Thank you :)

OnTick works for the current symbol. For your purpose you could generate custom events notifications from different symbol chart to get their tick event. Still that would require all charts to be opened.
 

The tick is for the current chart symbol only. I recommend: Do not trade multiple currencies in one EA.

  1. You can't use any {MT4: predefined variables, MT5: predefined variables,}

  2. Must poll (not OnTick, unless you use specific indicators)
              The Implementation of a Multi-currency Mode in MetaTrader 5 - MQL5 Articles (2011)

  3. and usually other problems, e.g. A problem with iBarShift - MQL4 programming forum - Page 2

  4. You must handle History {MT4:4066/4073 errors: Download history in MQL4 EA - MQL4 programming forum, MT5: Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5.}

  5. Code it to trade the chart pair only. Look at the others if you must. Don't assume that Time[i] == iTime(otherPair, TF, i) always use iBarShift.

Then put it on other charts to trade the other pairs. Done.