MT5 OnTmer() function

 

I use OnTimer function very often and I noticed if   "task" inside  timer function takes longer then next timer call  ..then entire EA is frozen/ stopped  ...So my question is :: is this "the way" the OnTimer() works , so everything inside have to be "done"  before next timer call "EventSetTimer()"     or  ...is there a way to set some flag/setting to automatically extend EventSetTimer  if previous call is not done yet    ....I tried to google the subject but is is not easy to find good question :)

I understand I always can  extend the value, but if there is another way to control this problem it would be nice :)

Thank You  and  Regards

 
Marcin Rutkowski:

I use OnTimer function very often and I noticed if   "task" inside  timer function takes longer then next timer call  ..then entire EA is frozen/ stopped  ...So my question is :: is this "the way" the OnTimer() works , so everything inside have to be "done"  before next timer call "EventSetTimer()"     or  ...is there a way to set some flag/setting to automatically extend EventSetTimer  if previous call is not done yet    ....I tried to google the subject but is is not easy to find good question :)

I understand I always can  extend the value, but if there is another way to control this problem it would be nice :)

Thank You  and  Regards

Did you check is there no deviding by zero? That could be a reason. MT must inform you about it in Expert tab.

 
void OnTimer()
{
     static bool workTimer = true;
     if( !workTimer )
          return;
//---
     workTimer = false;

     /* work */

     workTimer = true;
}
 
Vladimir Tkach:

Did you check is there no deviding by zero? That could be a reason. MT must inform you about it in Expert tab.

My test software was based on creating the dynamic array and later initialise each record with random numbers, and I created the class with methods to record time based on GetMicrosecondCount()  ..I was printing the results to the file     ..if  array init was less then timer event  then everything is working OK   ...but if  I increase FOR loop so creating array of this size will take longer then (timer event, in my case 5 sec)   ...then I will never see the results    first i tested the code OnInit() so I had no time restriction, measure  the "5s" size of the database  , and after I moved the code to OnTimer()     ...code is OK i think  (i don't know what is the best practice, i write how it works for me)

my test Loop

void OnTimer(void)
  {
   clsTStamp.metAddNewStamp("OnTime Call");
   int size=300000;
   int locTestVarib=0;

   
   int arrTest[];
   clsTStamp.metAddNewStamp("<<<<<<<<<<<<<<<<<<<<  FOR loop Start ");
   for(int e=0; e<size; e++)
     {

      if(e%10000==0)
        {
         Comment((string)e);
         clsTStamp.metAddNewStamp("....<<<<<<<<<<<<<<<<  For 10000 stepstime ");
        }

      locTestVarib=e;
      ArrayResize(arrTest,ArraySize(arrTest)+1);
      arrTest[e]=(int)funRandRange(1,10000);

     }
   clsTStamp.metAddNewStamp((string)locTestVarib+" ...<<<<<<<interuptr test "+(string)(size-1));   //in case for was interupted
   clsTStamp.metAddNewStamp("<<<<<<<<<<<<<<<<<<<<  FOR Loop STOP");

   clsTStamp.metFilePrint("0");  //   <<  each call separate file
  }

correction   ...sorry  software didn't stop   ...the array init time is not linear    ...last 30% of the size take super long time   ...i was not waiting not long enough for file to print :), so I discovered another issue in my case  :)   ...why the array  times grow with size ...sorry for this, i didn't expect it  ...I will attach my   timeStamp files is someone is interested

Thank You for reply  ...i have more testing to do :)

Reason: