help with the bar function

 
can anyone help with this
datetime time6=D'2024.07.10 07:15'; string symbol="EURUSD"; ENUM_TIMEFRAMES tf=PERIOD_M5; bool exact=false; //--- If there is no bar at the specified time, iBarShift will return the index of the nearest bar int bar_index=iBarShift(symbol,tf,time6,exact); Alert(bar_index); int baaar = bar_index-1; Alert(baaar); int start; if(prev_calculated==0) start=0; else start=prev_calculated-1; //--- calculate MACD for(int i=start; i<rates_total && !IsStopped(); i++) { double candle_range = close[baaar-i] - open[baaar-i]; ExtMacdBuffer[i] = candle_range; }
it is supposed to shift the indicator to right, so that it lags behind the real chart
 
Mad trader Trader:
can anyone help with this
it is supposed to shift the indicator to right, so that it lags behind the real chart

Have you tried this in OnInit?

PlotIndexSetInteger(index_number, PLOT_SHIFT, 1);
 
Mad trader Trader: it is supposed to shift the indicator to right, so that it lags behind the real chart

Your posted code creates four (4) initialized variables. That code doesn't do anything.