show bar shift

Back to topics list To post a new topic, please log in or register
avatar
4
dergham 2015.08.28 10:00
 
//+------------------------------------------------------------------+
//|                                                                                                 |
//|                                                                  |
//+------------------------------------------------------------------+


#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 

avatar
Moderator
3406
GumRai 2015.08.28 10:32 #
 

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 

avatar
4
dergham 2015.08.28 10:37 #
 
your suggestion works thank you very much
Back to topics list  

To add comments, please log in or register