Threads, speed, ticks and global variables

 

From searching the forum, it seems that:

a) the start() function of an EA runs in a new thread created by an incoming tick. If its still running when a new tick arrives, the new tick gets 'missed' by the EA

b) custom indicators run in the main GUI/interface thread, unless called from an EA. Libraries also run in the thread of the calling EA.

Questions:

1. If I have CPU-intensive calculations, the best option seems to be to do these in an indicator, have the indicator running on the chart, and return the results via global variables to the EA? Ie, do NOT use iCustom.

2. Do custom indies running in the main chart thread also 'miss' ticks?

https://docs.mql4.com/runtime/start

 
HarriMQL4:


Questions:

1. If I have CPU-intensive calculations, the best option seems to be to do these in an indicator, have the indicator running on the chart, and return the results via global variables to the EA? Ie, do NOT use iCustom.

2. Do custom indies running in the main chart thread also 'miss' ticks?

https://docs.mql4.com/runtime/start


1. not sure . . . I would be very cautious about doing this, how will you know when the GV has been updated ?

2. yes, everything can miss ticks

 
RaptorUK:

1. not sure . . . I would be very cautious about doing this, how will you know when the GV has been updated ?

2. yes, everything can miss ticks

1. The same way as always. Since an indicator is doing the work, and I look always at bar 1 (ie, closed), I'd check if Time[0] has changed (or its equivalent since Im actually doing calcs on rangebars)

2. a)If everything (EA, scripts, custom indicators) can miss a (crucial) tick which could trigger a trade decison(close OR open), isnt it inherently risky?

2. b) Why is there no way (in MQL) to catch every tick? What about these so-called "tick-collectors", presumably they miss ticks as well? Is there a way, perhaps in a DLL, to catch everything?

 
HarriMQL4:

1. The same way as always. Since an indicator is doing the work, and I look always at bar 1 (ie, closed), I'd check if Time[0] has changed (or its equivalent since Im actually doing calcs on rangebars)

2. a)If everything (EA, scripts, custom indicators) can miss a (crucial) tick which could trigger a trade decison(close OR open), isnt it inherently risky?

2. b) Why is there no way (in MQL) to catch every tick? What about these so-called "tick-collectors", presumably they miss ticks as well? Is there a way, perhaps in a DLL, to catch everything?


2a that will depend on your Strategy and how you take into account that you can miss ticks.

2b if 2 ticks happen at the same time, Bid moves and Ask moves how can start() not miss one ? for the most part the people who write the tick collectors don't know/don't care about mossing ticks. There is no way to catch everything . . . as far as I am aware, I have tried. I created an indicator that could run as several instances so each would only catch 1/nth of the number of ticks . . . it still misses ticks. If the spread is opening and closing by 1 point and doing this repeatedly do you really want these ticks ?

 
HarriMQL4:

From searching the forum, it seems that:

a) the start() function of an EA runs in a new thread created by an incoming tick. If its still running when a new tick arrives, the new tick gets 'missed' by the EA

If this is the case, what's the point of creating new thread for every tick? This new thread for new tick scheme gives false impression that EA can processes multiple ticks in parallel.

 

There is one thread per EA see https://docs.mql4.com/runtime/start

The thread starts with the init(), then each time a tick is received the controller (MT) calls the start() for the relevant EA, unless the start() function is still running from the previous time it was called.

 
RaptorUK: If the spread is opening and closing by 1 point and doing this repeatedly do you really want these ticks ?
Probably not, but I may want to know if a larger than average tick comes in. If it does and the EA misses it and the next one as well.... I assume the MarketWatch window doesnt miss a tick though.
 
HarriMQL4:
Probably not, but I may want to know if a larger than average tick comes in. If it does and the EA misses it and the next one as well.... I assume the MarketWatch window doesnt miss a tick though.

I think your assumption is most probably wrong. One thing you don't need to miss . . . knowing that you have missed a tick. It's very easy to know that your code has missed a tick.
 

It is impossible to guarentee you will recieve every tick, regular internet congestion will cause some to get lost. I have even seen ticks arrive that do not get drawn on the chart, the bid line jumps down and back real fast, but on the chart the price bar doesnt show that tick ever happened.