Features of the mql5 language, subtleties and tricks - page 27

 

Forum on trading, automated trading systems and trading strategies testing

Bugs, bugs, questions

fxsaber, 2017.02.07 13:41

SymbolInfoTick in indicators works quite differently than in EAs.

In an indicator, it always returns the tick that was the initiator of OnCalculate call. These initiator ticks in the indicator should not be skipped - this is the ideology of the developers. The problem is in the formation of the queue of these ticks.

In the Expert Advisor, the SymbolInfoTick in OnTick does not return the tick that initiated the call of OnTick, but makes a full request for the current status.

 
fxsaber:

In other words:

The indicator will show the first tick of the whole pack when a pack of ticks arrives, and the Expert Advisor will show the last tick of the pack.

Am I reading this right?

 
Artyom Trishkin:

In other words:

The indicator will show the first tick of the whole pack when a pack of ticks arrives, and the Expert Advisor will show the last tick of the pack.

Do I understand it correctly?

Yes. OnCalculate will not be called at every tick of a pack in the order of priority.
 
fxsaber:
Yes. OnCalculate will not be called at every tick of a packet in order of priority.

On every tick? Because you didn't write it...

It turns out that with the arrival of a packet of ticks, the indicator will start in the order of the ticks in the incoming packet?

I wonder, if the packet was received at the opening of a new bar, how many times during this pack of ticks will the indicator perform the full recalculation?

 
Artyom Trishkin:

On every tick? Because you did NOT write...

I guess I didn't write a lot of things.

It turns out that with the arrival of a pack of ticks, the indicator will be started in the order of ticks in the incoming pack?

I wonder, what if the pack came at the opening of a new bar - how many times during this pack of ticks will the indicator make a full recalculation?

The Calculate event is generated at EVERY tick. Therefore, there is a tick queue for indicators. If it reaches a certain amount, the log displays a warning that the indicator is too slow.

The bars themselves are indicators by their nature and are formed according to Calculate-events. Therefore, if the TF M1 and it is 10:15:00.020 and a 50 ms pack is coming, then the first tick in it still has time 10:14:59.970. And all indicators are called first on this Calculate event - first, the timeseries indicator and then custom indicators with these timeseries. That is, in this layout, the 10:15-bar is not yet formed as a zero bar. And the zero bar is 10:14.


Then, when the pack starts to unwind through Calculate-events, the 10:15-bar will appear. I think I've covered this in detail.

 
fxsaber:

There's probably a lot I haven't written.

The Calculate event is generated on EVERY tick. Therefore, there is a tick queue for the indicators. If it reaches a certain amount, there is a warning in the log that the indicator is too slow.

The bars themselves are indicators by nature and are formed by Calculate-events. Therefore, if the TF M1 and it is 10:15:00.020 and a 50 ms pack is coming, then the first tick in it still has time 10:14:59.970. And all indicators are called first on this Calculate event - first, the timeseries indicator and then custom indicators with these timeseries. That is, in this layout, the 10:15-bar is not yet formed as a zero bar. And the zero bar is 10:14.


Then, when the pack starts to unwind through Calculate-events, the 10:15-bar will appear. I think I've covered this in detail.

Thank you.
 

As a consequence, it is quite normal when the EA has received a tick of a bar that has not yet been formed. But this is such a subtle moment that it would take a lot of effort even to reproduce it intentionally. In general, it is more theoretical than practical.


If you are paranoid about speed, using indicators (and bars, of course) is not an option. Everything is in the Expert Advisor.

 

fxsaber:

Next, when the pack starts to unwind through Calculate events, the 10:15-bar will also appear. I think I've covered this in detail.

Interesting information.
Is there any way to determine that a pack has arrived, ignore the first ticks from it and take only the last tick for processing?
 
Vasiliy Pushkaryov:
Is it somehow possible to determine that a pack came, ignore the first ticks from it and take only the last tick for processing?
In OnCalculate via CopyTicks.
 
fxsaber:
In OnCalculate via CopyTicks.
Thank you, I will take it into account.