Indicator not synchronized with expert advisor in 1 minute ohlc

 

Hi, i have the following system:

An indicator working on M15 period acting only when a new bar is created, using a system similar to the one below

bool isNewBar()
{
    static datetime PeriodLastBarOpenTime;

    datetime CurrentBarOpenTime = iTime(Symbol(), Period(), 0);

    if (PeriodLastBarOpenTime != CurrentBarOpenTime)
    {
        PeriodLastBarOpenTime = CurrentBarOpenTime;
        return true;
    }
    else
        return false;
    
}

Also expert advisor checks for a new bar on M15 to update the buffer of the indicator using the same logic as previous to detect new bar.

What is happening is that if I use "every tick based on real" it works, but if I use "1 minute OHLC" the buffer of the indicator is delayed by 15 minutes.. is like in the instant of consulting the indicator, it is not already updated. I don't get why this is happening and also why this happens only with 1 minute OHLC.

I cannot provide you the code of indicator or expert advisor, I know that it is hard to determine an error without knowing the exact code, but I just need some advice and ideas on what can cause this! Thanks 

 

Try to use this command to see if that helps.

#property tester_everytick_calculate
 

Thanks for the answer! I was not aware of this mechanism... I have another question.

In the documentation, I came across the following explanation:

"In the Strategy Tester, indicators are only calculated when their data are accessed, i.e. when the values of indicator buffers are requested. This provides a significantly faster testing and optimization speed, if you do not need to obtain indicator values on each tick. "

However, a question arises: if I don't access an indicator for one year, what happens the first time I request it? Does it recover the year lost, essentially acting as if it never stopped, or does it return results with a gap of one year?
 

Hi, your code sample is produced by ChatGPT. Please do not trust the code generated by AI.

At present, AI does not have the ability to produce logically complete program codes. They can only provide program code inspiration.

This is the code I wrote, I hope it can solve your problem.

input string          G_TickToFramesSymbol   = "EURUSD";
input ENUM_TIMEFRAMES G_TickToFramesFrames   = PERIOD_M5;
      datetime        G_OldFramesTime        = D'1970.01.01 00:00:00';

void OnTick()
{
   if (!TickToFrames(AutoSymbol(G_TickToFramesSymbol), G_TickToFramesFrames, G_OldFramesTime))
   {
      return;
   }
   PutYourCodeHere(); // Put your code here.
}

bool TickToFrames(string P_Symbol, ENUM_TIMEFRAMES P_Frames, datetime& P_OldTime)
{
   bool L_TimeLoop = P_OldTime == iTime(P_Symbol, P_Frames, 0);
   if(!L_TimeLoop)
   {
      P_OldTime = iTime(P_Symbol, P_Frames, 0);
      return (true);
   }
   else
   {
      return (false);
   }
}

You need to declare a G_OldFramesTime variable in the public domain, so that when the TickToFrames function receives a time change, it will overwrite the original time of the G_OldFramesTime variable.

When the value of the G_OldFramesTime variable is the same as the current time, no action is taken.

Reason: