Timer in the Strategy Tester

 

I'm clearly missing something because the timer is not beating appropriately for me in the ST.

Here's my test program:

//+------------------------------------------------------------------+
//|                                                         test.mq5 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
 #include <Files\File.mqh>
#include <Files\FileTxt.mqh>

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
      
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   Print ("TT " + total_ticks);
   File.Close();
    
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int total_ticks;
void OnTick()
  {
//---
  }

//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
 CFileTxt     File;
 void OnTimer()
  {
  total_ticks = total_ticks+1;
  MqlDateTime time_now;
  TimeToStruct(TimeCurrent(),time_now);
  
  int fh = File.Open("times.txt",FILE_COMMON|FILE_WRITE|FILE_READ|FILE_BIN,9);
  FileSeek(fh,0,SEEK_END);
  FileWriteString(fh, TimeCurrent() +"\r\n");    
  
  }
//+------------------------------------------------------------------+

..and here's a bit of the output (many beats at the same time and then missing beats at other times):

2017.03.20 05:42:59

2017.03.20 05:53:59

2017.03.20 05:54:59

2017.03.20 05:54:59

2017.03.20 05:54:59

2017.03.20 05:54:59

2017.03.20 05:54:59

2017.03.20 05:59:59

2017.03.20 05:59:59

2017.03.20 06:02:00

2017.03.20 06:02:59

2017.03.20 06:03:30

2017.03.20 06:03:30

2017.03.20 06:03:30

2017.03.20 06:03:30

Thank you.

futures_track
futures_track
  • www.mql5.com
Trader's profile
 
futures_track: I'm clearly missing something because the timer is not beating appropriately for me in the ST.
  1. Because timer is not supported in the ST.
  2. In backtest OnTimer() not performs (M. Ali) - MQL4 forum
    Chart Event For MT4 Backtester (Migel) - MQL4 forum
 


Sorry, I'm in MT5 and I think the timer is supposed to be supported:


https://www.mql5.com/en/docs/runtime/testing#ontimer

Documentation on MQL5: MQL5 programs / Testing Trading Strategies
Documentation on MQL5: MQL5 programs / Testing Trading Strategies
  • www.mql5.com
MQL5 programs / Testing Trading Strategies - Reference on algorithmic/automated trading language for MetaTrader 5
 
whroeder1:

Could you please stop answering to mql5 topic with mql4 link.

Thank you.

 
futures_track:


Sorry, I'm in MT5 and I think the timer is supposed to be supported:


https://www.mql5.com/en/docs/runtime/testing#ontimer

Yes it is.

You save TimeCurrent() which is the time of last tick from server(history). Your output is correct, what are you expecting ?

 
Alain Verleyen:

Yes it is.

You save TimeCurrent() which is the time of last tick from server(history). Your output is correct, what are you expecting ?


Aha, yes, I was definitely missing something.  namely that TimeCurrent() is not the same as timeGMT().  


Thank you.

Reason: