Help modify Stochastic Divergence alert

 
The attached code is my effort to create a Stochastic Oscillator Divergence indicator. This indicator is supposed to send the relevant alerts whenever there is a bullish or bearish divergence. I created the indicator by modifying the RSI_Divergence.mq5 code (which does not have alert features). The Stochastic Divergence Indicator draws the divergence lines but, apart from the alert sound, it does not end alert messages. Can anyone help me out with the correction. 
 
George Effanga:
The attached code is my effort to create a Stochastic Oscillator Divergence indicator. This indicator is supposed to send the relevant alerts whenever there is a bullish or bearish divergence. I created the indicator by modifying the RSI_Divergence.mq5 code (which does not have alert features). The Stochastic Divergence Indicator draws the divergence lines but, apart from the alert sound, it does not end alert messages. Can anyone help me out with the correction. 

Your code does not include any logic to stop//end alert messages.

What exactly are you aiming to achieve? 

 
@Oleksandr Medviediev. I'm trying to get native alerts, push notifications and email alerts whenever there's a bullish or bearish divergence. Alerts should include symbol, timeframe and type of divergence. 
 

To stop//end alert messages need to modify the manage Alerts function to include additional logic that checks conditions and stops sending alerts when those conditions are met.

Example:

//+------------------------------------------------------------------+
//| Manage alerts                                                    |
//+------------------------------------------------------------------+
void manageAlerts(const int rates_total)
  {
   static int last_alerted_bar = 0;
   static int divergence_count = 0;
   static bool alerts_stopped = false;

   int new_alerted_bar = rates_total - 1;
   if (last_alerted_bar < new_alerted_bar)
     {
      // Set the new alerted bar
      last_alerted_bar = new_alerted_bar;
      divergence_count++;

      // Check if the maximum number of divergences has been reached
      if (divergence_count >= 5 && !alerts_stopped)
        {
         // Stop sending alerts
         alerts_stopped = true;
         Print("Maximum number of divergences reached. Alerts stopped.");
        }

      // Send alerts only if alerts are not stopped
      if (!alerts_stopped)
        {
         if (alertsMessage)
            SendNotification("Stochastic Divergence Alert: A divergence has been detected.");
         if (alertsEmail)
            SendMail("Stochastic Divergence Alert", "A divergence has been detected.");
         if (alertsMobileApp)
            SendNotification("Stochastic Divergence Alert: A divergence has been detected.");
         if (alertsSound)
            PlaySound("alert.wav");
        }
     }
  }
 

Did you setup push notifications in MT5?

 
Yes, I set it up. I actually received push notifications but the notification was general. It did not have the symbol, timeframe and type of divergence. I only coded it to say that Divergence was detected. Another thing is that the notifications kept coming for a signal many times. 
 
Thank you for the modification. However, I have not been able to achieve my aim. I received push notifications when there was no divergence. Maybe I will try a different approach. I will try to create an EA that sends signals (instead of opening positions) whenever the bullish or bearish divergence arrows appears on the chart. 
 
George Effanga #:
@Oleksandr Medviediev. I'm trying to get native alerts, push notifications and email alerts whenever there's a bullish or bearish divergence. Alerts should include symbol, timeframe and type of divergence. 
Why not just use Alert() function
 
Conor Mcnamara #:
Why not just use Alert() function
For a pop-up window yes.
 
Oleksandr Medviediev #:
For a pop-up window yes.

I'm so sorry for the late reply. I have achieved my aim. Thank you very much for your time and patience.