Handle multiple ticks in OnTick for multiple symbos

 

Hello,


I'm currently developing support for multiple Symbol experts and I'm facing the following problem:


Given the expert is attached to a chart, the documentation for OnTick says:


> The NewTick event is generated only for EAs upon receiving a new tick for a symbol of the chart the EA is attached to.


And that makes sense, but I'm wondering how do other developers develop multi symbol experts? Currently what I'm doing is keeping track of the last tick for each symbol, and upon receiving a new one that symbol will be processed. But OnTick will only be called once for each tick that happens to the current chart, so it's probable some symbols will miss some ticks. What would be the best approach to solve this situation?


Best regards 

 
Thank you very much!, will read it, seems very promising.
 

That Darwinex video is a great starting point. I now use what I consider to be a more advanced method but I started with the darwinex method at first and it still serves me well on many EA's so perhaps start with that at first. It's easier because it waits for a new bar to get its first tick so you know that index 1 is the last close if you check your buffers right after that happens. Other methods that seek to improve efficiency and reaction speed are tricky because you always need to check if the previous close is on index 0 or index 1 of a buffer (which can change from 1 millisecond to the next) and depending on how you do it things can start getting pretty complex. So for starters I would try that method and see if it's good enough for you.

If ever you insist on doing it with a more advanced technique, you'll need to get very familiar with functions such as iTime, iBarShift, CopyRates and OnTimer. Also, know that if you don't wait for a bar's first tick before checking indicator buffers, there's a slight chance (small % but not 0%) that the last close switches from index 0 to index 1 of an indicator buffer right in the middle of two commands. That happens if the previous bar has closed but the new bar didn't get its first tick yet, and happens if the first tick is received by your terminal right in the middle of two lines of code in your EA (perfect timing to the 1/10000 of a second). That's why I think it's best that you start with a simpler method like the one in the Darwinex video. I made a post last week trying to work out the issues with the more advanced technique but I honestly don't recommend it if you're still building your first multi-symbol EA.

 

@Jeepack Thank you for your reply.


I already started working with the approach mentioned in the link I posted, using OnChartEvent and EventChartCustom. I find it's one of the most clean and elegant solutions to process multiple ticks at once. Have you look at it? It's pretty interesting.

Bests

 
algui91 #:

@Jeepack Thank you for your reply.


I already started working with the approach mentioned in the link I posted, using OnChartEvent and EventChartCustom. I find it's one of the most clean and elegant solutions to process multiple ticks at once. Have you look at it? It's pretty interesting.

Bests

Yes I use OnTimer events now to detect new bars. The reason it's more complex though is you have to check if your 0 index bar has already closed because it will still be index 0 until the next bar receives its first tick. So sometimes, the last closed bar will be bar # 0 and other times it'll be bar # 1. You can check this with many methods, but just know that it can change between two command lines so unless you get all the rates info for a chart in one go using CopyRates, if you're copying data from multiple buffers instead, you might want to perform extra validations to check that a new bar wasn't formed between your first and last buffer query.