Switching TF in the Terminal causes sometimes(?) questionable results - any idea what to do?

 

Hi,

(preliminary comment: absolutely no line of code was changed during the following procedures!!)

I wrote in OOP a simple ema based on M1 for which I can define its TF and its paints it ema lines on the chart. Here you see TF of the ema and the chart = 60 (h1):


As you can see quite the same :) Red is my ema, yellow is the terminal ema with the same period and price.

The line shows the value of my ema and the difference to the terminal's ema (compared ALWAYS! to tf:h1!!)

If I change the TF in the chart (terminal) but not of my ema I see (so at each bar you see the value of the h1-tf):


Again, red is mine (tf:h1, period:6, price:close), yellow the terminal (tf:m15, period:6, price:close).

I got this just by clicking on the m15 button of the terminal and I get the same after another compilation.

Now I go down to m1:


Now I go up again switching to m5 (the same happens if I press Refresh (one of the mouse-options of the chart-window):


??? - Now I just press the compile button in the editor and I get:


Some times (??!!) it's fine to switch from m1 to m5 sometimes I got the flat line switching from m15 to m5??

From here I again switch up (no compilation) to m15:


no problem at all!!

Now I proceed to n30 and h1 again:



Again no problem at all!!

So why the hell do I have that 'singleton' problem of switching from m1 to m5, while a compilation shows the code is correct and all other switches between different TF do work absolutely correct.

Has anybody an idea what might cause this 'sometimes-problem'?

The log shows no error.

I have already placed a call of OnDeinit(0);  at the beginning of OnInit() to 'nullify' everything.

in OnCalculate() I do:

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[])
{
   int B,b = (prev_calculated == 0) ? iBars(EmaSym,PERIOD_M1) - 1 
                                    : rates_total - prev_calculated + 1;
  
   foreach(b) {
      ¢Ema.calc(iTime(EmaSym,PERIOD_M1,b),...);
      B = iBarShift(EmaSym,_Period,iTime(EmaSym,PERIOD_M1,b));
      EmaBuffer[B]   = ¢Ema.getVal(0);
   }
   Comment( ¢Ema.showValueLine(),
   "\n\nRunTime: "+DoubleToString(Sum,0)," mSec per Run    mem: "+(string)mem," MB");

   
//--- return value of prev_calculated for next call
   return(rates_total);
}
Reason: