MQL4 tick volume skipping.

 

Hi,

I'm sorry if this is a stupid question, but I am currently refining my EA that detects signals at the beginning of a new bar.

What it does internally is, roughly in psudo code:


if( Volume[0] == 1 ){

// run some code, here I run some dummy code on a few forex pairs I'm interested in and force them to fetch data into memory and disk. Because not all pairs are hitting tick 1 at the same speed, I run another one later to ensure all pairs have at least 1 tick on the new bar.

}

if( Volume[0] == 50 ){

// run some code

}

if( Volume[0] == 100 ){

// this is the code I'm actually going to run. What I found is, most of the time( about 90% - 95% ) this executes fine without problems, but every now and then, this if block gets ignored and skipped. 

// I haven't digged deep into it to see if the broker actually skips the tick feed on some numbers, or if it's too fast that after my previous if block finished, next time it runs it's already with a new tick number.

// I think my question here is if anyone has experienced similar issues, or know anything that might cause this?

// And specifically if ticks are coming in super fast, and in the code there are too many calculations need to be done, would MT4 skip to the latest OnTick() call or it'll keep running all the old unfinished calls?

return "Thank you very much guys!";

}

 

Actually after finishing writing the post I realised I could do 2 tests to see how the broker and MT4 behave around new ticks...

I'll come back with the test result in case if other people have similar issues.

Strategy Testing - Algorithmic Trading, Trading Robots - MetaTrader 5 Help
Strategy Testing - Algorithmic Trading, Trading Robots - MetaTrader 5 Help
  • www.metatrader5.com
The Strategy Tester allows you to test and optimize trading strategies (Expert Advisors) before using them for live trading. During testing, an Expert Advisor with initial parameters is once run on history data. During optimization, a trading strategy is run several times with different sets of parameters which allows selecting the most...
 

Okay I've written out each tick on a relatively medium paced pair at 9pm GMT.

In each OnTick() call the only operation is open a file, prepare the string, and write out to file, close the file. Fairly quick.

I printed out the gap between 2 adjacent ticks processed. They do have quite big gaps every now and then.

  1. Volume Gap:    >     1
  2. Volume Gap:    >>>     3
  3. Volume Gap:    >>>     3
  4. Volume Gap:    >     1
  5. Volume Gap:    >>>     3
  6. Volume Gap:    >     1
  7. Volume Gap:    >     1
  8. Volume Gap:    >>>     3
  9. Volume Gap:    >>     2
  10. Volume Gap:    >     1
  11. Volume Gap:    >>     2
  12. Volume Gap:    >>>     3
  13. Volume Gap:    >>>>     4
  14. Volume Gap:    >>     2
  15. Volume Gap:    >     1
  16. Volume Gap:    >     1
  17. Volume Gap:    >>>     3
  18. Volume Gap:    >     1
  19. Volume Gap:    >     1
  20. Volume Gap:    >     1
  21. Volume Gap:    >     1
  22. Volume Gap:    >>     2
  23. Volume Gap:    >     1
  24. Volume Gap:    >     1
  25. Volume Gap:    >     1
  26. Volume Gap:    >     1
  27. Volume Gap:    >     1
  28. Volume Gap:    >     1
  29. Volume Gap:    >     1
  30. Volume Gap:    >     1
  31. Volume Gap:    >     1
  32. Volume Gap:    >>>     3
  33. Volume Gap:    >     1
  34. Volume Gap:    >>     2
  35. Volume Gap:    >>>>     4
  36. Volume Gap:    >     1
  37. Volume Gap:    >     1
  38. Volume Gap:    >     1
  39. Volume Gap:    >     1
  40. Volume Gap:    >     1
  41. Volume Gap:    >     1
  42. Volume Gap:    >     1
  43. Volume Gap:    >     1
  44. Volume Gap:    >>     2
  45. Volume Gap:    >     1
  46. Volume Gap:    >     1
  47. Volume Gap:    >     1
  48. Volume Gap:    >>     2
  49. Volume Gap:    >     1
  50. Volume Gap:    >     1
  51. Volume Gap:    >     1
  52. Volume Gap:    >     1
  53. Volume Gap:    >>>     3
  54. Volume Gap:    >     1
  55. Volume Gap:    >     1
  56. Volume Gap:    >     1
  57. Volume Gap:    >     1
  58. Volume Gap:    >     1
  59. Volume Gap:    >     1
  60. Volume Gap:    >>     2
  61. Volume Gap:    >     1
  62. Volume Gap:    >     1
  63. Volume Gap:    >     1
  64. Volume Gap:    >     1
  65. Volume Gap:    >     1
  66. Volume Gap:    >>     2
  67. Volume Gap:    >     1
  68. Volume Gap:    >     1
  69. Volume Gap:    >>     2
  70. Volume Gap:    >     1
  71. Volume Gap:    >     1
  72. Volume Gap:    >>     2
  73. Volume Gap:    >     1
  74. Volume Gap:    >>     2
  75. Volume Gap:    >>     2
  76. Volume Gap:    >>     2
  77. Volume Gap:    >     1
  78. Volume Gap:    >>>     3
  79. Volume Gap:    >     1
  80. Volume Gap:    >     1
  81. Volume Gap:    >     1
  82. Volume Gap:    >     1
  83. Volume Gap:    >     1
  84. Volume Gap:    >     1
  85. Volume Gap:    >>     2
  86. Volume Gap:    >     1
  87. Volume Gap:    >>     2
  88. Volume Gap:    >     1
  89. Volume Gap:    >     1
  90. Volume Gap:    >     1
  91. Volume Gap:    >>     2
  92. Volume Gap:    >     1
  93. Volume Gap:    >     1
  94. Volume Gap:    >     1
  95. Volume Gap:    >     1
  96. Volume Gap:    >     1
  97. Volume Gap:    >     1
  98. Volume Gap:    >     1
  99. Volume Gap:    >>     2
  100. Volume Gap:    >>     2
  101. Volume Gap:    >>     2
  102. Volume Gap:    >>     2
  103. Volume Gap:    >     1
  104. Volume Gap:    >>     2
  105. Volume Gap:    >     1
  106. Volume Gap:    >     1
  107. Volume Gap:    >     1
  108. Volume Gap:    >     1
  109. Volume Gap:    >     1
  110. Volume Gap:    >     1
  111. Volume Gap:    >     1
  112. Volume Gap:    >     1

The following result comes from waiting for 15 seconds before writing out the file, which means the OnTick() function won't get to finish until 15 seconds have passed.

  1. Volume Gap:    >     1
  2. Volume Gap:    >     1
  3. Volume Gap:    >>>>     4
  4. Volume Gap:    >>>>>>     6
  5. Volume Gap:    >>     2
  6. Volume Gap:    >>>>>     5
  7. Volume Gap:    >>>>>>>     7
  8. Volume Gap:    >>     2
  9. Volume Gap:    >>>>>>>>     8
  10. Volume Gap:    >     1
  11. Volume Gap:    >>>>>>>>>>     10
  12. Volume Gap:    >>>     3
  13. Volume Gap:    >>>     3
  14. Volume Gap:    >>     2
  15. Volume Gap:    >>>>>>>>>     9
  16. Volume Gap:    >>>     3
  17. Volume Gap:    >     1
  18. Volume Gap:    >>>>     4
  19. Volume Gap:    >>>>>>>>>     9
  20. Volume Gap:    >>>>>>>     7
  21. Volume Gap:    >>>>>>>>>     9
  22. Volume Gap:    >>>>>>>     7
  23. Volume Gap:    >>>>>>     6
  24. Volume Gap:    >>>     3
  25. Volume Gap:    >     1
  26. Volume Gap:    >>>     3
  27. Volume Gap:    >>>     3
  28. Volume Gap:    >>>>>     5
  29. Volume Gap:    >>>>     4
  30. Volume Gap:    >>>>>>>>>     9
  31. Volume Gap:    >>>>>>>>>>>>>     13
  32. Volume Gap:    >>>     3
  33. Volume Gap:    >>     2
  34. Volume Gap:    >     1
  35. Volume Gap:    >>>>>     5
  36. Volume Gap:    >     1
  37. Volume Gap:    >     1
  38. Volume Gap:    >>>     3
  39. Volume Gap:    >     1
  40. Volume Gap:    >     1
  41. Volume Gap:    >     1
  42. Volume Gap:    >>>     3
  43. Volume Gap:    >>     2
  44. Volume Gap:    >     1
  45. Volume Gap:    >     1
  46. Volume Gap:    >     1
  47. Volume Gap:    >>>     3
  48. Volume Gap:    >>>>     4
  49. Volume Gap:    >     1

So these two tests showed, at least, MT4 won't wait for earlier OnTick() calls to finish before starting the current one. 

Using something like if( Volume[0] == number ) can't guarentee the block of code getting executed when the tick feed is fast or your computation is heavy in the code body.


Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
Reason: