Home Technical Indicator Post

Mastering the ColorXdinMA_Alert Indicator for MetaTrader 5

Attachments
17111.zip (22.91 KB, Download 0 times)

Author: dimeon

The ColorXdinMA indicator is a trend-based moving average tool for MetaTrader 5 that comes packed with alerts, email notifications, and push notifications directly to your mobile device.

Here’s a breakdown of the enhancements made to this indicator to include alerts and notifications:

  1. First up, we’ve declared an enumeration for the signal generation options globally, right before the input variables. This helps in organizing how signals are generated.
    //+----------------------------------------------------+
    //| Enumeration for signal generation options   |
    //+----------------------------------------------------+
    enum ENUM_SIGNAL_MODE
      {
       MODE_SIGNAL,  //Breakout signals
       MODE_TREND    //Breakout and trend signals
      };
  2. New input parameters have been introduced to customize alerts:
    //---- Input variables for alerts
    input ENUM_SIGNAL_MODE SignMode=MODE_SIGNAL; //Signal generation mode
    input uint NumberofBar=1;                    //Number of the bar to generate a signal
    input bool SoundON=true;                     //Enable alerts
    input uint NumberofAlerts=2;                 //Number of alerts
    input bool EMailON=false;                    //Enable mailing the signal
    input bool PushON=false;                     //Enable sending the signal to mobile devices
  3. We've also added three new functions at the end of the indicator code: BuySignal(), SellSignal(), and GetStringTimeframe().
    //+------------------------------------------------------------------+
    //| Buy signal function                                              |
    //+------------------------------------------------------------------+
    void BuySignal(string SignalSirname,// text of the indicator name for email and push messages
                   double &ColorArray[],// color index buffer
                   int ColorIndex,// color index in the color index buffer to generate a signal
                   const int Rates_total,     // the current number of bars
                   const int Prev_calculated, // the number of bars on the previous tick
                   const double &Close[],     // close price
                   const int &Spread[])       // spread
      {
    //---
       static uint counter=0;
       if(Rates_total!=Prev_calculated) counter=0;
    ...
  4. Finally, we made calls to BuySignal() and SellSignal() functions right after the indicator calculation cycles in the OnCalculate() block.
    //---    
       BuySignal("ColorXdinMA_Alert",ColorXdinMA,1,rates_total,prev_calculated,close,spread);
       SellSignal("ColorXdinMA_Alert",ColorXdinMA,2,rates_total,prev_calculated,close,spread);
    //--- 

In this context, ColorXdinMA refers to the color index buffer that stores the colors of the indicator. The numbers 1 and 2 correspond to the colors indicating whether the moving average is trending upwards or downwards, respectively.

It's worth noting that you will only use one call to the BuySignal() and SellSignal() functions in the OnCalculate() block of the indicator code.

For this indicator to work seamlessly, ensure that you have the SmoothAlgorithms.mqh library in place (copy it to <terminal_data_folder>\MQL5\Include). You can find a detailed explanation of these classes in the article "Averaging Price Series for Intermediate Calculations Without Using Additional Buffers".

Fig1. The ColorXdinMA_Alert indicator on the chart

Fig1. The ColorXdinMA_Alert indicator on the chart

Fig.2. The ColorXdinMA_Alert indicator. Generating alert for breakout signal

Fig.2. The ColorXdinMA_Alert indicator. Generating alert for breakout signal

Fig.3. The ColorXdinMA_Alert indicator. Generating alert for trend signal

Fig.3. The ColorXdinMA_Alert indicator. Generating alert for trend signal

Related Posts

Comments (0)