Trying to code an indicator to show duration of bar for Renko charts

 

Hi,

I've been trying to code an indicator ( only my second one! ) that will enable be to show the duration of each bar. This is to be used on Renko charts. However I'm having some difficulties even though on the face of it it should be simple.  Below is the code, any suggestions gratefully received.

 

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Lime

//---- buffers
double ExtMapBuffer1[];

   
//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);

   string short_name = "Bar Duration";
   IndicatorShortName(short_name);
 //  ArrayInitialize(ExtMapBuffer1,0);

   return(0);
}

int deinit()
{
   return(0);
}

int start()

{

   int counted_bars=IndicatorCounted();
   //---- check for possible errors
   if (counted_bars<0) return(-1);
   //---- last counted bar will be recounted
   if (counted_bars>0) counted_bars--;

    //---- main calculation loop

   int pos=Bars-counted_bars;
   
   while ( pos>0)
   {
   ExtMapBuffer1[pos] = Time[pos-1]-Time[pos]; 
   pos--;
   }
      
      
      
return(0);
}
 

Thought I'd bump this in case anybody missed it that might be able to help.

Thanks. 

 

i dont c anywhere that u r calculating renko like: double renko = iCostom(....);

 
 
Counted_bars is initially zero, so your loop starts at Bars, which does not exist.
No need for the decrement Contradictory information on IndicatorCounted() - MQL4 forum
   if (counted_bars>0) counted_bars--;

    //---- main calculation loop

   int pos=Bars-counted_bars;
   
   while ( pos>0)
   {
   ExtMapBuffer1[pos] = Time[pos-1]-Time[pos];
   pos--;
   }
Handle your look back of one zero.
    //---- main calculation loop

   for(int pos=Bars-1-MathMax(1,counted_bars); pos >0 --pos)
      ExtMapBuffer1[pos] = Time[pos-1]-Time[pos];
Reason: