Custom Indicator Not Refreshing

 

Hi All,

I have a custom indicator that paints arrows on my chart when specific criteria is aligned. The problem is that it only re-paints when I refresh it, it should just do this automatically. The source code is below, can anyone tell me what code I can add to fix this?

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red

extern double Range=25;
extern int Arrow_Size=3;
int Spacing = 50;
double Up[],Dn[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorShortName("Candle Range");
   IndicatorDigits(Digits);
   SetIndexStyle(0,DRAW_ARROW,0,Arrow_Size);
   SetIndexArrow(0,233);
   SetIndexBuffer(0,Up);
   SetIndexStyle(1,DRAW_ARROW,0,Arrow_Size);
   SetIndexArrow(1,234);
   SetIndexBuffer(1,Dn);

   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {

   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   if(Bars<=3) return(0);
   int ExtCountedBars=IndicatorCounted();
   if(ExtCountedBars<0) return(-1);
   int limit=Bars-2;
   if(ExtCountedBars>100) limit=Bars-ExtCountedBars-100;
   int pos;
   double Delta;
   pos=limit;
   while(pos>=0)
     {
      Delta=Range*(High[pos]-Low[pos])/100.;
      if(Close[pos]>High[pos]-Delta)
        {
         Up[pos]=Low[pos]-Spacing*Point;
         Dn[pos]=EMPTY_VALUE;
        }
      else
        {
         if(Close[pos]<Low[pos]+Delta)
           {
            Up[pos]=EMPTY_VALUE;
            Dn[pos]=High[pos]+Spacing*Point;
           }
         else
           {
            Up[pos]=EMPTY_VALUE;
            Dn[pos]=EMPTY_VALUE;
           }
        }

      pos--;
     }
   return(0);
  }
//+------------------------------------------------------------------+
 
Volcom: can anyone tell me what code I can add to fix this?
  1. int limit=Bars-2;
       if(ExtCountedBars>100) limit=Bars-ExtCountedBars-100;
    Bogus. After the first time counted = Bars so limit is negative and nothing is drawn. Try int limit = Bars -1 -ExtCountedBars;

  2. You should stop using the old IndicatorCounted and start using the new Event Handling Functions - Functions - Language Basics - MQL4 Reference
  3. See also How to do your lookbacks correctly.

 
whroeder1:
  1. Bogus. After the first time counted = Bars so limit is negative and nothing is drawn. Try int limit = Bars 1 -ExtCountedBars;

  2. You should stop using the old IndicatorCounted and start using the new Event Handling Functions - Functions - Language Basics - MQL4 Reference
  3. See also How to do your lookbacks correctly.

Thanks a lot @whroeder1 ! That worked, appreciate it.
Reason: