Download MetaTrader 5
To add comments, please log in or register
Read the Forum and improve your rating!
Steve Boardman
81
Steve Boardman 2010.09.30 15:23 

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);
}
Steve Boardman
81
Steve Boardman 2010.10.21 14:59  

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

Thanks. 

qjol
3243
qjol 2010.10.21 15:35  

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

pabloroacho
545
pabloroacho 2015.02.28 12:52  
whroeder1
13599
whroeder1 2015.02.28 13:13  
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];
/
To add comments, please log in or register