Delay in update execution.

 

Hello All,

I am using 30 symbols and 9 time frame in EA.
I need to read indicator buffer. With according to buffer value i need to update arrow for each and every timeframe.

I am getting issue of delay in updating of arrow. All code is executing in On timer().
Timer event used 1 second, 5 second, 500 ms, 250 ms.

Please need your advices.

Thanks In advance,

Abhishek. 

 
abhishek_hpcs:

Hello All,

I am using 30 symbols and 9 time frame in EA.
I need to read indicator buffer. With according to buffer value i need to update arrow for each and every timeframe.

I am getting issue of delay in updating of arrow. All code is executing in On timer().
Timer event used 1 second, 5 second, 500 ms, 250 ms.

Please need your advices.

Thanks In advance,

Abhishek. 

Not sure what advice you expect, but accessing 30 symbols with 9 timeframes costs extensive memory use, but does not cause noticeable delay.

 
Ovo:

Not sure what advice you expect, but accessing 30 symbols with 9 timeframes costs extensive memory use, but does not cause noticeable delay.

Thanks for reply.

I need to update arrow at every change of buffer value of indicator.
But I am getting arrows update after two or three bar.

 

A bunch of things come into my mind now:

30 symbols x 9 time frames = 270 overall symbol and time frame executions.

The question would be whether your code is able to deal with that range of speed.

You probably need to do performance tests with your code.

E.g. on start of your OnTimer(); you need to get the current time in milliseconds.

On exit of your OnTimer(); you need to get the current time in milliseconds.

You need to subtract the time measured at the end with the time measured at the start and you get the overall execution time of your code. The true time that the code needs to process from OnTimer begin to end.

So you can't simply go and set the OnTimer to 1 second or 0.5 second or even less, if the code itself needs 2 seconds to operate for one symbol in one timeframe (just an example).

Now assume that you need to process that code 270 times to 2 seconds per call. that ends up in 540 seconds. Please note that these values are taken out of air. In reality your code might process faster.

With other words, you see these delays because of this.

Try optimizing your code:

  • Remove unnecessary initialisations of constants from loops and put them before loops. A value that won't change can be intialized once before the loop.
  • Reduce unnecessary calls to functions that return constant or same values. A value that won't change can be initialized before loops.
  • Try calculating only the difference or new candles or ticks or whatever, rather than re-calculating all over and over again.
  • Beware from unnecessary file i/o operations that might cause issues in timing.
  • Everything ends up in the requirements to profile and optimize your code.

Edit: The problem with the so called "compiling" of MQ4 code to EX4 is, that the compiler seems to be not able to optimize the code. Like gcc, clang and co. there are possibilities to optimize the code by unrolling loops, pass operations to a vector unit (different library for example) or simply optimize the code to use a better cpu mnemonic. This ends up in using different assembler generated code to optimize speed. E.g. if you want to multiply a value then the CPU code for it would be some mulu operands. These mulu operands use e.g. 70-80 tact cycles to process. You can achieve the same multiplication by shifting and swapping values. You end up using more operands in the assembler code but the overall execution time gets reduced from 70-80 (mulu) to e.g. 40 (using lsl and swap). A true compiler is able to do a lot more than what I believe the metaquotes compiler is able to do. Whenever I code some MQ4 stuff, I end up seeing it as "writing in basic". The code you enter is the code that is being processed afterwards. We even don't know (at least I don't) whether the code is being interpreted, pre-compiled in bytecode or truly assembled. Therefore it's even more important to optimize the code to it's best and use the time stuff to measure the execution speed of the function from entering till leaving.

 
i have issue i need a delay script for indicator i want my arrow signal appear if its appear in 30 sec if takes time more than 30 sec it shouldn't be appear .. please kindly anyone know about this please reply thanks
 
Indicators can not sleep. They can not delay. If the condition is true, the arrow appears.
 
it can be delay yeah sometime condition come true when its too late but for binary its not useful need script to make them sleep if they appear delay