Change alert of 2 ma crossover

 

hello guys,

i need your help.

i want to change the alert of this indicator to: only give a alert with a pop up window (only once) when the arrow (up/down) appears. is this possible? currently it alerts every candle if the condition is true.

Thank you.

int start() {

   int limit, i, counter;

   double MA1now, MA2now, MA1previous, MA2previous, MA1after, MA2after;

   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;

      for (counter=i ;counter<=i+9;counter++)

      {

         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);

      }

      Range=AvgRange/10;

      

      MA1now = iMA(NULL, 0, MA1, 0, MA1Mode, PRICE_CLOSE, i);

      MA1previous = iMA(NULL, 0, MA1, 0, MA1Mode, PRICE_CLOSE, i+1);

      MA1after = iMA(NULL, 0, MA1, 0, MA1Mode, PRICE_CLOSE, i-1);


      MA2now = iMA(NULL, 0, MA2, 0, MA2Mode, PRICE_CLOSE, i);

      MA2previous = iMA(NULL, 0, MA2, 0, MA2Mode, PRICE_CLOSE, i+1);

      MA2after = iMA(NULL, 0, MA2, 0, MA2Mode, PRICE_CLOSE, i-1);

      

      if ((MA1now > MA2now) && (MA1previous < MA2previous) && (MA1after > MA2after)) {

                   CrossUp[i] = Low[i] - Range*1.5;

                   if (AlertOn && NewBar()) {

                      Alert(AlertPrefix+MA1short_name+" ("+MA1+") "+"crosses UP " + MA2short_name+" ("+MA2+")");

                   }  

                 if (SendAnEmail && NewBar()) {

                      SendMail(AlertPrefix,MA1short_name+" ("+MA1+") "+"crosses UP " + MA2short_name+" ("+MA2+")");

                 }

      }

      else if ((MA1now < MA2now) && (MA1previous > MA2previous) && (MA1after < MA2after)) {

                   CrossDown[i] = High[i] + Range*1.5;

                   if (AlertOn && NewBar()) {

                      Alert(AlertPrefix+MA1short_name+" ("+MA1+") "+"crosses DOWN " + MA2short_name+" ("+MA2+")");

                   }  

                 if (SendAnEmail && NewBar()) {

                      SendMail(AlertPrefix,MA1short_name+" ("+MA1+") "+"crosses DOWN " + MA2short_name+" ("+MA2+")");

                 }

      }

   }

   return(0);

}
 

Please use the SRC button when posting code.

I doubt that anyone will help you with this code because of

      MA1after = iMA(NULL, 0, MA1, 0, MA1Mode, PRICE_CLOSE, i-1);

when looking at historical bars the indicator looks into the "future"

This is bad code and should not be used.

Reason: