How to program only one Alert after closing the candle

 

Its my first indicator. And I want to make alerts. But idk how to make only one alert after closing candel. Now they appear to me throughout the entire period of the candle construction. Can anyone help me? I will be grateful.

My code -

#property copyright "Moje"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+


#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red

input int FasterEMA = 8;
input int SlowerEMA = 20;

double BufferFast[];
double BufforSlow[];
double CrossUp[];
double CrossDown[];

#define FastIndicator 0
#define SlowIndicator 1

int OnInit()
  {
  SetIndexStyle(0, DRAW_LINE, 2, 3, clrRed);
  SetIndexBuffer(0, BufferFast);
  SetIndexLabel(0, "Fast");
  
  SetIndexStyle(1, DRAW_LINE, 2, 3, clrGreen);
  SetIndexBuffer(1, BufforSlow);
  SetIndexLabel(1, "Slow");
  
  SetIndexStyle(2, DRAW_ARROW, EMPTY);
  SetIndexArrow(2, 233);
  SetIndexBuffer(2, CrossUp);
   
  SetIndexStyle(3, DRAW_ARROW, EMPTY);
  SetIndexArrow(3, 234);
  SetIndexBuffer(3, CrossDown);
  
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,      // size of input time series
                 const int prev_calculated,  // bars handled in previous call
                 const datetime& time[],     // Time
                 const double& open[],       // Open
                 const double& high[],       // High
                 const double& low[],        // Low
                 const double& close[],      // Close
                 const long& tick_volume[],  // Tick Volume
                 const long& volume[],       // Real Volume
                 const int& spread[]         // Spread
                 )
   {
   
   int limit;
   double fastMAprev, slowMAprev, fastMAnow, slowMAnow, fastMAprev2, slowMAprev2, slowMA, fastMA;
   
   if(rates_total<=SlowerEMA){
      return(0);
   }
      
   limit = rates_total-prev_calculated;
   
   if(prev_calculated>0){
      limit++;
   }
   
   for(int i = 0; i<limit; i++){
   
   
       fastMA = iMA(Symbol(), Period(), FasterEMA, 0, MODE_SMA, PRICE_CLOSE, i);
       slowMA = iMA(Symbol(), Period(), SlowerEMA, 0, MODE_SMA, PRICE_CLOSE, i);
      
      
       fastMAnow = iMA(NULL, 0, FasterEMA, 0, MODE_SMA, PRICE_CLOSE, i);
       fastMAprev2 = iMA(NULL, 0, FasterEMA, 0, MODE_SMA, PRICE_CLOSE, i+1);
       
       slowMAnow = iMA(NULL, 0, SlowerEMA, 0, MODE_SMA, PRICE_CLOSE, i);
       slowMAprev2 = iMA(NULL, 0, SlowerEMA, 0, MODE_SMA, PRICE_CLOSE, i+1); 
       
       if( (fastMAprev2<slowMAprev2) && (fastMAnow>slowMAnow)){
       CrossUp[i] = Low[i] - 0;
       BufferFast[i]=fastMA;
       BufforSlow[i]=slowMA;
       }
       
       else if((fastMAprev2>slowMAprev2) && (fastMAnow<slowMAnow)){
       CrossDown[i] = High[i]-0;
       BufferFast[i]=fastMA;
       BufforSlow[i]=slowMA;
       }

       else if(fastMA>slowMA){
       BufferFast[i]=fastMA;
       BufforSlow[i]=slowMA;
       }   
            
       else if(fastMA<slowMA){
       BufferFast[i]=fastMA;
       BufforSlow[i]=slowMA;
       }

       }
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
hikary3:

Its my first indicator. And I want to make alerts. But idk how to make only one alert after closing candel. Now they appear to me throughout the entire period of the candle construction. Can anyone help me? I will be grateful.

My code -


Use the time remaining for a candle to close and as soon as it get to zero execute an alert function

Reason: