Time calculation in indicator causing issue in EA

 

Hi.

I have a fragment of code in an indicator causing an issue with CopyBuffer in my EA.

I have Googled and searched through the docs, they illustrate that this should work although I might have missed something.

https://www.mql5.com/en/articles/599#convert_add_substract

datetime now = TimeCurrent();
   
if (prev_calculated != 0 && now > time[0] + PeriodSeconds(PERIOD_CURRENT) - 6)
{
   PrintFormat("PreUpdate:  %s", TimeToString(now, TIME_SECONDS));
}
else
{
   return(rates_total);
}

When I build the indicator and attach to a chart it works as expected.

When I build an EA and run in the Strategy Tester, using iCustom, include the time calculation in the indicator, CopyBuffer returns zeros.


I have isolated the issue in the files below.

Any help appreciated.


Apologies, I have realized the example was not the same as my issue, since the EA is using OnTick and my issue was using the OnNewBar example in the docs.

https://www.mql5.com/en/articles/159


I have updated the files below

MQL5 Programming Basics: Time
MQL5 Programming Basics: Time
  • www.mql5.com
The article focuses on standard MQL5 functions for working with time, as well as programming techniques and practically useful functions for working with time that are required when creating Expert Advisors and indicators. Particular attention is paid to the general theory of time measurement. This article should be of interest primarily to novice MQL5 programmers.
Reason: