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:
- 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
}; - 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 - We've also added three new functions at the end of the indicator code:
BuySignal(),SellSignal(), andGetStringTimeframe().//+------------------------------------------------------------------+
//| 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;
... - Finally, we made calls to
BuySignal()andSellSignal()functions right after the indicator calculation cycles in theOnCalculate()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

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

Fig.3. The ColorXdinMA_Alert indicator. Generating alert for trend signal
Related Posts
- Unlocking the Power of the ColorXdinMA_StDev Indicator for MetaTrader 5
- Maximize Your Trading Potential with the ColorX2MA_Alert Indicator for MetaTrader 5
- Unlocking Trading Potential with XDPO_HTF_Signal for MetaTrader 5
- Visualize Current Trends Across All Time Frames with This MetaTrader 4 Indicator
- Mastering the MACD Candle Indicator for MetaTrader 4