Bollinger band alert.

 
int start()
  {
  
   int    i,k;
   bool   BBSpeak=False;
   double deviation;
   double sum,oldval,newres;
   double BBFinishTime=TimeCurrent();
   
   //----
   if(Bars<=BandsDrawRange) return(0);
   

   //------------------------------------------------------------ Draw
   
   
   for(i=BandsDrawRange; i>=0; i--) 
   {
   
      if (BBMovingAverage>3 && BBMovingAverage<0) BBMovingAverage=0;
      if (BBAppliedPrice>6 && BBAppliedPrice<6 ) BBAppliedPrice=0;
   
      MovingBuffer[i]=iMA(NULL,0,BandsMAPeriod,BandsShift,BBMovingAverage,BBAppliedPrice,i);                   
          
      //---------------------
      sum=0.0;
      k=i+BandsMAPeriod-1;
      oldval=MovingBuffer[i];
      
      while(k>=i)
      {
        newres=Close[k]-oldval;
        sum+=newres*newres;
        k--;
      }   
      deviation=BandsDeviations*MathSqrt(sum/BandsMAPeriod);     
      if (oldval>0) UpperBuffer[i]=oldval+deviation;
      if (oldval>0) LowerBuffer[i]=oldval-deviation;                
         
                   
     } // ----------------------------------------- End Draw
     
     
     
     
     //-------------------------------------------- Start Speak
    
     BBSpeak=False;
     BBFinishTime=TimeLocal(); 
                                                   
     if ((BBFinishTime - BBTime) >= BBAlarmDelay )    // && pos==0)
       {       
           BBFinishTime=TimeLocal();
           BBTime=TimeLocal();
           BBSpeak=True;
           
       }        
   
     while (BBSpeak==True)
     {
        for(i=0; i<=BBCandleAlertRange; i++) 
        { 
          //--------------------------
          
          if (High[i] > UpperBuffer[i])
          { 
            if (BandsAlertBoxOn==True) Alert("Bands R2: Candle:"+i+" High Band Cross: "+High[i]);
            if (BandSoundAlertHighOn==True) PlaySound(WaveBandName);
            BBSpeak=False;
 
            
          }
          
          if (Low[i] < LowerBuffer[i])
          { 
            if (BandsAlertBoxOn==True) Alert("Bands R2: Candle:"+i+" Low Band Cross: "+Low[i]);
            if (BandSoundAlertLowOn==True) PlaySound(WaveBandName2);
            BBSpeak=False;

          }
       if (i >= BBCandleAlertRange) BBSpeak=False;
       }           
     }    
     
     //--------------------------------------------- End Speak
 
    
   return(0);
  }

Please can some one fix this for me alert keeps going continuously 

int start()

  {

  

   int    i,k;

   bool   BBSpeak=False;

   double deviation;

   double sum,oldval,newres;

   double BBFinishTime=TimeCurrent();

   

   //----

   if(Bars<=BandsDrawRange) return(0);

   


   //------------------------------------------------------------ Draw

   

   

   for(i=BandsDrawRange; i>=0; i--) 

   {

   

      if (BBMovingAverage>3 && BBMovingAverage<0) BBMovingAverage=0;

      if (BBAppliedPrice>6 && BBAppliedPrice<6 ) BBAppliedPrice=0;

   

      MovingBuffer[i]=iMA(NULL,0,BandsMAPeriod,BandsShift,BBMovingAverage,BBAppliedPrice,i);                   

          

      //---------------------

      sum=0.0;

      k=i+BandsMAPeriod-1;

      oldval=MovingBuffer[i];

      

      while(k>=i)

      {

        newres=Close[k]-oldval;

        sum+=newres*newres;

        k--;

      }   

      deviation=BandsDeviations*MathSqrt(sum/BandsMAPeriod);     

      if (oldval>0) UpperBuffer[i]=oldval+deviation;

      if (oldval>0) LowerBuffer[i]=oldval-deviation;                

         

                   

     } // ----------------------------------------- End Draw

     

     

     

     

     //-------------------------------------------- Start Speak

    

     BBSpeak=False;

     BBFinishTime=TimeLocal(); 

                                                   

     if ((BBFinishTime - BBTime) >= BBAlarmDelay )    // && pos==0)

       {       

           BBFinishTime=TimeLocal();

           BBTime=TimeLocal();

           BBSpeak=True;

           

       }        

   

     while (BBSpeak==True)

     {

        for(i=0; i<=BBCandleAlertRange; i++) 

        { 

          //--------------------------

          

          if (High[i] > UpperBuffer[i])

          { 

            if (BandsAlertBoxOn==True) Alert("Bands R2: Candle:"+i+" High Band Cross: "+High[i]);

            if (BandSoundAlertHighOn==True) PlaySound(WaveBandName);

            BBSpeak=False;

 

            

          }

          

          if (Low[i] < LowerBuffer[i])

          { 

            if (BandsAlertBoxOn==True) Alert("Bands R2: Candle:"+i+" Low Band Cross: "+Low[i]);

            if (BandSoundAlertLowOn==True) PlaySound(WaveBandName2);

            BBSpeak=False;


          }

       if (i >= BBCandleAlertRange) BBSpeak=False;

       }           

     }    

     

     //--------------------------------------------- End Speak

 

    

   return(0);

  }

MetaQuotes Software Corp.
MetaQuotes Software Corp.
  • www.metaquotes.net
Millions of traders and hundreds of brokers cannot be wrong — they have chosen MetaTrader 5 for trading Forex and financial markets! Learn more
Reason: