Fractals Indicator is not refreshing automatically

 

Hi I am going to attach a code for drawing fractals indicator. The indicator is working great with many option, the only problem that I have to refresh the chart in MT4 in order to see the new fractals. Can anyone tell me what is wrong with the code to make it work right without refreshing the chart everytime? ... Thanks!

//+------------------------------------------------------------------+
//|                                                    sFractals.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DeepPink
#property indicator_color2 PaleGreen
#property indicator_width1 3
#property indicator_width2 3

//---- buffers
double ExtUpFractalsBuffer[];
double ExtDownFractalsBuffer[];

extern string Fractal_Desc=" ******* Fractal settings:";
extern int  CandlesBeforeAfter      = 7;
extern string ArrowShape_Desc="1 Arrow1,2 Arrow2,3 Arrow3,4 Arrow4,5 Circle1,6 Circle2,7 Circle3,8 Rectangle1,9 Rectangle2,10 Diamond1,11 Diamond2,12 Hand";
extern int  ArrowShape              = 1;
extern int  ArrowSize               = 0;
extern double  ArrowOffset          = 4;

extern string Alert_Desc=" ******* Alert settings:";
extern int  AlertCandle            = 0;
extern bool PopupAlerts            = FALSE;
extern bool EmailAlerts            = FALSE;
extern bool PushNotificationAlerts = FALSE;
extern bool SoundAlerts            = FALSE;
extern string SoundFileLong        = "alert.wav";
extern string SoundFileShort       = "alert2.wav";
datetime alert_time;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping  
    SetIndexBuffer(0, ExtUpFractalsBuffer);
    SetIndexBuffer(1, ExtDownFractalsBuffer); 
//----
    SetIndexDrawBegin(1,0);
    SetIndexDrawBegin(0,0);
    SetIndexEmptyValue(0, 0.0);
    SetIndexEmptyValue(1, 0.0);  
//---- drawing settings
    SetIndexStyle(0, DRAW_ARROW);
    SetIndexStyle(1, DRAW_ARROW);
//---- name for DataWindow
    SetIndexLabel(0, "sFractal Up");
    SetIndexLabel(1, "sFractal Down");
//---
    switch(ArrowShape){
       case 1:SetIndexArrow(0, 234);SetIndexArrow(1, 233);break;
       case 2:SetIndexArrow(0, 242);SetIndexArrow(1, 241);break;
       case 3:SetIndexArrow(0, 226);SetIndexArrow(1, 225);break;
       case 4:SetIndexArrow(0, 222);SetIndexArrow(1, 221);break;
       case 5:SetIndexArrow(0, 159);SetIndexArrow(1, 159);break;
       case 6:SetIndexArrow(0, 164);SetIndexArrow(1, 164);break;
       case 7:SetIndexArrow(0, 174);SetIndexArrow(1, 174);break;
       case 8:SetIndexArrow(0, 110);SetIndexArrow(1, 110);break;
       case 9:SetIndexArrow(0, 112);SetIndexArrow(1, 112);break;
       case 10:SetIndexArrow(0, 119);SetIndexArrow(1, 119);break;
       case 11:SetIndexArrow(0, 116);SetIndexArrow(1, 116);break;
       case 12:SetIndexArrow(0, 72);SetIndexArrow(1, 71);break;
    }
//---- Constants
    ArrowOffset=ArrowOffset/100;
//---- initialization done   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start(){
   int    i,i1, nCountedBars;
   bool   bFound;
   double dCurrent;
   
   nCountedBars = IndicatorCounted();
   if(nCountedBars<0) return(-1);
   //---- last counted bar will be recounted
   if(nCountedBars>0) nCountedBars--;
//----Up and Down Fractals
   for(i=Bars-nCountedBars;i >= CandlesBeforeAfter+1;i--){
      //----Fractals up
      bFound = false;
      dCurrent = High[i];
      for(i1=1;i1<=CandlesBeforeAfter;i1++){
         if(dCurrent >= High[i+i1]) bFound = true;
         else {bFound = false;break;}
         //
         if(dCurrent >= High[i-i1]) bFound = true;
         else {bFound = false;break;}
      }
      if(bFound){
         ExtUpFractalsBuffer[i] = dCurrent+ArrowOffset;
         if (Time[0] > alert_time){
            alert_time = Time[0];
            doAlerts("HIGH FRACTAL",SoundFileShort);
         }
      }             
      //----Fractals down
      bFound = false;
      dCurrent = Low[i];
      for(i1=1;i1<=CandlesBeforeAfter;i1++){
         if(dCurrent <= Low[i+i1]) bFound = true;
         else {bFound = false;break;}
         //
         if(dCurrent <= Low[i-i1]) bFound = true;
         else {bFound = false;break;}
      }
      if(bFound){
         ExtDownFractalsBuffer[i] = dCurrent-ArrowOffset;
         if (Time[0] > alert_time){
            alert_time = Time[0];
            doAlerts("LOW FRACTAL",SoundFileLong);
         }
      }                             
   }
   return(0);
  }
  
// Sending Emails and Alerts

void doAlerts(string msg,string SoundFile) {
   msg=WindowExpertName()+" "+msg+" "+Symbol()+", period "+TFtoStr(Period());
   string emailsubject="MT4 alert on acc. "+AccountNumber()+", "+WindowExpertName()+" - Alert on "+Symbol()+", period "+TFtoStr(Period());
   if (PopupAlerts) Alert(msg);
   if (EmailAlerts) SendMail(emailsubject,msg);
   if (PushNotificationAlerts) SendNotification(msg);
   if (SoundAlerts) PlaySound(SoundFile);
}//void doAlerts(string msg,string SoundFile) {

   string TFtoStr(int period) {
   if (period==0) period=Period();
   switch(period) {
      case 1     : return("M1");  break;
      case 5     : return("M5");  break;
      case 15    : return("M15"); break;
      case 30    : return("M30"); break;
      case 60    : return("H1");  break;
      case 240   : return("H4");  break;
      case 1440  : return("D1");  break;
      case 10080 : return("W1");  break;
      case 43200 : return("MN1"); break;
      default    : return(DoubleToStr(period,0));
   }
   return("UNKNOWN");
}//string TFtoStr(int period) {

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

 
int start()
  {
   int i,limit,pos,nCountedBars=IndicatorCounted();

   if(nCountedBars<0)
      return(-1);
//---- last counted bar will be recounted
   if(nCountedBars==0)
      limit=Bars -(CandlesBeforeAfter*2+1);
   else
      limit=Bars-nCountedBars;
//----Up and Down Fractals
   for(i=limit; i>=0; i--)
     {
      pos=ArrayMaximum(High,CandlesBeforeAfter*2+1,i);

      if(pos==i+CandlesBeforeAfter)
        {
         ExtUpFractalsBuffer[pos]=High[pos]+ArrowOffset;

         if(Time[0]>alert_time)
           {
            alert_time=Time[0];
            doAlerts("HIGH FRACTAL",SoundFileShort);
           }
        }

      pos=ArrayMinimum(Low,CandlesBeforeAfter*2+1,i);

      if(pos==i+CandlesBeforeAfter)
        {
         ExtDownFractalsBuffer[pos]=Low[pos]-ArrowOffset;

         if(Time[0]>alert_time)
           {
            alert_time=Time[0];
            doAlerts("LOW FRACTAL",SoundFileLong);
           }
        }
     }

   return(0);
  }
 
Naguisa Unada:

Thank you so much ... it works now just fine!