"timer" not working in indicator when it is added to chart by an expert

Gholamhossein Eslamizadeh  

I was developing an expert that should add an indicator to a fresh opened chart when some conditions  are met  

it is not a complex thing just an indicator 

int OnInit(void)
  {
ResetLastError();
   if(!EventSetTimer(1))
     {
      int e = GetLastError();
      Print(_Symbol+"Cannot set Timer Error #", e);
     }

   return(INIT_SUCCEEDED);
}

void OnTimer()
  {
        Print("On timer reached");
}

and this indicator is added with "ChartIndicatorAdd" function.

To elucidate:

1- indicator is working just fine when it is added to any chart manually

2- on time is set in the Oninit as reference said so

3- this problem is occurring only when indicator is added to a separate chart by an expert

4- There are no Errors when timer is set in the log

Another weird thing is that indicator's life cycle is not attached to the newly opened chart but to the expert!!!

I also realized that "IndicatorRelease" function is not working as well. after using this function Indicator is still generating data and it is working on the EA thread!! , So obviously there are major bug in this section of mql5!!!

please please avoid leaving not relevant answers thanks in advance. this site is turning to a pile of questions with not relevant answers I just get a headache when I am trying to find answers for my problems. 

Documentation on MQL5: Chart Operations / ChartIndicatorAdd
Documentation on MQL5: Chart Operations / ChartIndicatorAdd
  • www.mql5.com
ChartIndicatorAdd - Chart Operations - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Gholamhossein Eslamizadeh  
William Roeder #:

I also get intermittent errors creating timers.
          Cannot set timer (60) - EA not working - MT4 - MQL4 programming forum #1 (2019)

I don't understand what you are trying to say duo to lack of explenation

1- it is a problem of MQL5 to MQL4

2- it is totally another problem I haven't get not set error !!!

3- Other related Questions in the forum that i search at least are not answered I can post links that I have read so don't comment me other posts please

No answer here as well:

https://www.mql5.com/en/forum/316556
Gholamhossein Eslamizadeh  

I just Wrote this solution I leave it here for others who has the same issue since I don't think this bug will be fixed anytime soon.

it is  not perfect at least it is something


datetime startTime=0;

int timerDelay = 4; // it is in seconds
int OnInit(void)
  {
ResetLastError();
   if(!EventSetTimer(1))
     {
      int e = GetLastError();
      Print(_Symbol+"Cannot set Timer Error #", e);
     }

startTime = TimeCurrent();

   return(INIT_SUCCEEDED);
}

void OnTimer()
  {
        Print("On timer reached");
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  { 
   datetime dt = TimeCurrent();

   if( (dt - startTime) > timerDelay) 
   {
   startTime =  dt;
   OnTimer(); 
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
Fernando Carreiro  
Gholamhossein Eslamizadeh #: I don't understand what you are trying to say duo to lack of explenation

He provided you with a link. On that linked post he explains it quite clearly and even gives a solution. Did you even read it?

Reason: