Download MetaTrader 5

How to implement Alerts in my script correctly ...

To add comments, please log in or register
Bullworth
337
Bullworth 2015.03.23 16:10 

Hi,

 Im trying to implement alerts into my script but im not aware of howto. It should alert when two MA's crosses.

Most of the script is already working, its drawing the arrows at the right spot, but i also want to implement alerts when it crosses.

Right now my script is stressed out when i try to implement the alert because it iterates trough all of the bars and im getting bashed by soundalerts.

Can you guys give me some help implementing an alerts that only alerts on newly formed crosses not the existing crosses ...

 This is my code so far:

int start(){

   int limit, i, counter;
   double CurrentFastSignal,PreviousFastSisnal,CurrentSlowSignal,PreviousSlowSignal;
   double Range, AvgRange;
   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--;

   limit=Bars-counted_bars;

   for(i = 0; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      
//----Calculate average range      
      for (counter=i ; counter<=i+9; counter++) { AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]); }
//----Calculate range      
      Range=AvgRange/10;
      
//---- Get vars of the fast moving average      
      CurrentFastSignal = iMA(NULL, 0, FastMA_Period, 0, FastMA_Method, FastMA_Applied_Price, i);
      PreviousFastSisnal = iMA(NULL, 0, FastMA_Period, 0, FastMA_Method, FastMA_Applied_Price, i+1);
      
//---- Get vars of the slow moving average
      CurrentSlowSignal = iMA(NULL, 0, SlowMA_Period, 0, SlowMA_Method, SlowMA_Applied_Price, i);
      PreviousSlowSignal = iMA(NULL, 0, SlowMA_Period, 0, SlowMA_Method, SlowMA_Applied_Price, i+1);
      
//----Bearish Crossing Signal
      if (CurrentFastSignal < CurrentSlowSignal && PreviousFastSisnal > PreviousSlowSignal){
         CrossDown[i] = High[i] + Range*0.5;
         //if (SoundAlertOn){PlaySound("alert.wav");}
         //if (EmailAlertOn){ Alert("Bearish Crossing - ",Symbol()," ",CurrentTimeFrame()," at ",TimeToStr(TimeCurrent(),TIME_SECONDS)); }
         //if (NotifyAlertOn){ SendMail("Bearish Crossing","Bearish Crossing - "+Symbol()+" "+CurrentTimeFrame()+" at "+TimeToStr(TimeCurrent(),TIME_SECONDS)+" (server time)"); }
      }

//----Bullish Crossing Signal      
      if (CurrentSlowSignal < CurrentFastSignal && PreviousSlowSignal > PreviousFastSisnal){
         CrossUp[i] = Low[i] - Range*0.5;
         //if (SoundAlertOn){PlaySound("alert.wav");}
         //if (EmailAlertOn){ Alert("Bullish Crossing - ",Symbol()," ",CurrentTimeFrame()," at ",TimeToStr(TimeCurrent(),TIME_SECONDS)); }
         //if (NotifyAlertOn){ SendMail("Bullish Crossing","Bullish Crossing - "+Symbol()+" "+CurrentTimeFrame()+" at "+TimeToStr(TimeCurrent(),TIME_SECONDS)+" (server time)"); }
      }
      
      
   }
   

//---
   return(0);
}
Bullworth
337
Bullworth 2015.04.05 21:15  
Bullworth:

Hi,

 Im trying to implement alerts into my script but im not aware of howto. It should alert when two MA's crosses.

Most of the script is already working, its drawing the arrows at the right spot, but i also want to implement alerts when it crosses.

Right now my script is stressed out when i try to implement the alert because it iterates trough all of the bars and im getting bashed by soundalerts.

Can you guys give me some help implementing an alerts that only alerts on newly formed crosses not the existing crosses ...

 This is my code so far:

Did not need help, problem already solved.
To add comments, please log in or register