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

Back to topics list To post a new topic, please log in or register
avatar
26
Stevetrade 2010.09.30 17: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);
}

 

 
avatar
26
avatar
3134
qjol 2010.10.21 17:35 #
 

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

avatar
5
pabloroacho 2015.02.28 13:52 #
 
avatar
13009
WHRoeder 2015.02.28 14: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];

Back to topics list  

To add comments, please log in or register