show bar shift

 
//+------------------------------------------------------------------+
//|                                                                                                 |
//|                                                                  |
//+------------------------------------------------------------------+


#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1  Red
#property indicator_width1  3

double shift_Buffer[];
datetime barTime;


int init()
  {

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,shift_Buffer);
    SetIndexLabel(0,"shift");
         IndicatorShortName("shift");
 
 }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   for(int i=0; i<Bars;i++)
      barTime =iTime(NULL,0,i);
shift_Buffer[i]=iBarShift(NULL,0,barTime);


   return(0);
  }
//+------------------------------------------------------------------+

For manual back testing I need the "  Data Window " to show candle shift . The above code doesn't work . Any idea ?

thank you 

 

You are running through the loop and then applying a value only to index[Bars-1]

   for(int i=0; i<Bars;i++)
     {
      barTime=iTime(NULL,0,i);
      shift_Buffer[i]=iBarShift(NULL,0,barTime);
     }

 Use curly braces to define the loop

Maybe just an exercise. but you achieve the same with the simpler

   for(int i=0; i<Bars;i++)
     {
      shift_Buffer[i]=i;
     }

try it 

You may also want to set indicator digits to 0 

 
your suggestion works thank you very much
Reason: