Strategy Tester *SLOWED DOWN* by function in OnTimer??

 

I've noticed a surprising thing: An EA that I am coding has an OnTimer function call in it that I *thought* that the Strategy Tester would ignore. 

I inserted it there because during normal, non-testing runtime, I wanted it to run a utility every once a few minutes that would loop through history collecting changes, gather some metrics through indicators and show it in the Comment on screen.  I tested it on both MT4 and MT5, and it works just fine, and did not seem to impact live performance at all. 

But then the next day, I needed to run a battery of tests, and my EA was very, very slow.  A test that used to run 2 mins was now taking in excess of 20 mins.  I combed through the code commenting out many items, re-running tests to find the culprit.  Its a multi-symbol EA, and I included those new calls to cycle through recent history, but I had also added some correlation functionality, and the Comment update features -- so there was plenty for me to turn off bit by bit.

The last new functionality I could comment out was the function call inside of OnTimer() -- and that worked!  This is a good thing!  If that didn't work, I would have to turn my attention to older core functionality that had so far been performing just fine.

But, I thought that OnTimer() was ignored by MT5?  I have read so many posts on this forum to that effect.  However, now I notice in the recent docs for OnTimer it says:

"In general, when the timer period is reduced, the testing time is increased, as the handler of timer events is called more often..."


When did OnTimer start to be supported in strategy tester?

</facepalm>

 
Talky_Zebra: An EA that I am coding has an OnTimer function call in it that I *thought* that the Strategy Tester would ignore.

MT4: The tester does not call OnTimer. If your code calls it, your code calls it. Why does that surprise you?

Talky_Zebra: owever, now I notice in the recent docs for OnTimer it says:

"In general, when the timer period is reduced, the testing time is increased, as the handler of timer events is called more often..."

MT5: I don't see that.

The Timer event is periodically generated by the client terminal for the Expert Advisor that has activated the timer by the EventSetTimer function. Usually, this function is called by OnInit. Timer event processing is performed by the OnTimer function. After the operation of the Expert Advisor is completed, it is necessary to destroy the timer using the EventKillTimer function, which is usually called in the OnDeinit function.
          Client Terminal Events - MQL5 programs - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5

 

Hi William - I am a fan of your code!  Your code snippets and advice help quite a lot.  Thanks for sharing them.

Actually, that MT4 does not support OnTimer() in the strategy tester does not surprise me at all.  I had built my functionality to call OnTimer on the assumption that MT would ignore it entirely in the tester.  And, MT4 appears to do just that.

The version of MT5 I am running is 5.00 3337.  It did surprise me that it seems to support it, to some degree.  I have attached a screenshot from the docs that are supplied with the build. 

The same text is on the web page for the MQL5 docs: https://www.mql5.com/en/docs/event_handlers/ontimer

Admittedly, my initial assumption was based on what I had seen on this forum... and not based on the docs.


But, yes, I was surprised to see my EA slow down by such a factor, and then more so to find out that it was a functionality that I thought was not going to impact performance at all.

Documentation on MQL5: Event Handling / OnTimer
Documentation on MQL5: Event Handling / OnTimer
  • www.mql5.com
OnTimer - Event Handling - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
Capture.PNG  50 kb
 
Talky_Zebra #: Admittedly, my initial assumption was based on what I had seen on this forum... and not based on the docs.

Dealing with beta builds can will always be surprising.

Reason: