OnTick does not update anything. It is an "event"! the function is called when a new tick arrives for the symbol of the chart the EA is attached to. While the function is being processed no further "new tick" events are reacted to until the function returns.
EDIT: From within the OnTick function you can get the current bid/ask prices from any symbol on the MarketWatch. On MT5 only, you can also fetch tick data from the tick history.
OnTick events only take place for the EA attached to a chart with that symbol. If no EA is attach to such a chart symbol, then no even is generated!
In order to "simulate" OnTick events for multiple symbols, from a single EA, you will have to write your own handler, but there is a CodeBase entry that does that already. I don't know how well it works, but you can analyse the code and see if it suits your needs.
![Multicurrency OnTick (string symbol) event handler Multicurrency OnTick (string symbol) event handler](https://c.mql5.com/36/47/multicurrency-ontick-string-symbol.jpg)
- www.mql5.com
OnTick events only take place for the EA attached to a chart with that symbol.
What you think, if I create an array along the code which will contain symbols of interest (theoretically can contain all MarketWatch) and check their bid and ask OnTimer each 200ms, then call OnTick() if any one of them is changed. Is it going to eat much resources? In other words, is so “non optimal” solution?
Did you not even look at the code of the publication in the CodeBase that I linked for you?
I have seen it but it uses spy indicator which must be attached to each chart.
OK, then use the OnTimer method and experiment for yourself to see if it is resource intensive or not!
There is a reason why they call it Research and Development, because we take the time to actually do some research and testing in order to develop things.
OK, then use the OnTimer method and experiment for yourself to see if it is resource intensive or not!
I have created GetAllSymbolTicks() function, which runs OnTimer() each 200ms and check whether any tick arrived in any symbol of interest, those symbols are puted into TickArray. Here is the function:
void GetAllSymbolTicks() { int list_size = ArraySize(TickArray); for(int i=0; i<list_size; i++) { string symbol_name = TickArray[i].Pair; double bid_price = SymbolInfoDouble(symbol_name, SYMBOL_BID); double ask_price = SymbolInfoDouble(symbol_name, SYMBOL_ASK); if(bid_price!=TickArray[i].BIDPrice || ask_price!=TickArray[i].ASKPrice) { //Print("New Tick: " + symbol_name + ", bid_price: " + bid_price + ", ask_price: " + ask_price); TickArray[i].Set(symbol_name,bid_price,ask_price); OnTick(); break; } } }
Then I have placed GetTickCount before and after function.
Initial experiment shows 16ms for each run of GetAllSymbolTicks(), regardless of the number of monitored symbols, if we use it with break, means once any tick found, OnTick() will be called and exit the loop. In this experiment 16ms includes the time to run OnTick(). Later I checked without OnTick(), with 40 monitored symbols the time to run this function was 0ms.
If we want to differentiate each Tick from which symbol came, then we can use without break, but in this case timing will be different, you might think. No, it was again 0ms for 40 symbols.
To display the results I was using label object instead of print.
Therefore, this pathway theoretically have following advantages:
- It is taking less than a millisecond and is quite recource effective.
- Different accuracies can be choosen for different type of EAs, i.e. can be run each 20ms lets say.
- Unlike Multicurrency OnTick (string symbol) event handler, doesnt require indicator to be runing on each chart.
I have created GetAllSymbolTicks() function, which runs OnTimer() each 200ms and check whether any tick arrived in any symbol of interest, those symbols are puted into TickArray. Here is the function:
Then I have placed GetTickCount before and after function.
Initial experiment shows 16ms for each run of GetAllSymbolTicks(), regardless of the number of monitored symbols, if we use it with break, means once any tick found, OnTick() will be called and exit the loop. In this experiment 16ms includes the time to run OnTick(). Later I checked without OnTick(), with 40 monitored symbols the time to run this function was 0ms.
If we want to differentiate each Tick from which symbol came, then we can use without break, but in this case timing will be different, you might think. No, it was again 0ms for 40 symbols.
To display the results I was using label object instead of print.
Therefore, this pathaw theoretically have following advantages:
- It is taking less than a millisecond and is quite recource effective.
- Different accuracies can be choosen for different type of EAs, i.e. can be run each 20ms lets say.
- Unlike Multicurrency OnTick (string symbol) event handler, doesnt require indicator to be runing on each chart.
You should not be calling OnTick() directly from another function. That is an event handler that is called by MetaTrader. I suspect that you would block it from being called by the event manager itself if they both got triggered at the same time, although I have never tested it. Instead, create your own separate Tick Handling function!
![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
Hi guys
Which symbols OnTick function updates, only current one or all symbols in market watch.
If any symbol is not in MarketWatch, its Bid or Ask can be fetched on tick?