The ColorX2MA_Alert indicator is a game-changer for traders using MetaTrader 5. With its alert features, you can receive notifications via email and push alerts right to your mobile device, ensuring you never miss a trading opportunity.
To enhance its functionality, several updates have been made to the indicator's code to implement these alerts, email notifications, and mobile push notifications:
- New Input Parameters Introduced:
//---- Input variables for alerts input uint NumberofBar=1; // Bar number for the 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
- Added Functions: Three new functions have been added to the 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; bool BuySignal=false; bool SeriesTest=ArrayGetAsSeries(ColorArray); int index,index1; if(SeriesTest) { index=int(NumberofBar); index1=index+1; } else { index=Rates_total-int(NumberofBar)-1; index1=index-1; } if(ColorArray[index1]!=ColorIndex && ColorArray[index]==ColorIndex) BuySignal=true; if(BuySignal && counter<=NumberofAlerts) { counter++; MqlDateTime tm; TimeToStruct(TimeCurrent(),tm); string text=TimeToString(TimeCurrent(),TIME_DATE)+" "+string(tm.hour)+":"+string(tm.min); SeriesTest=ArrayGetAsSeries(Close); if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; double Ask=Close[index]; double Bid=Close[index]; SeriesTest=ArrayGetAsSeries(Spread); if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; Bid+=Spread[index]; string sAsk=DoubleToString(Ask,_Digits); string sBid=DoubleToString(Bid,_Digits); string sPeriod=GetStringTimeframe(ChartPeriod()); if(SoundON) Alert("BUY signal \n Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod); if(EMailON) SendMail(SignalSirname+": BUY signal alert","BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod); if(PushON) SendNotification(SignalSirname+": BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod); } //--- } //+------------------------------------------------------------------+ //| Sell signal function //+------------------------------------------------------------------+ void SellSignal(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; bool SellSignal=false; bool SeriesTest=ArrayGetAsSeries(ColorArray); int index,index1; if(SeriesTest) { index=int(NumberofBar); index1=index+1; } else { index=Rates_total-int(NumberofBar)-1; index1=index-1; } if(ColorArray[index1]!=ColorIndex && ColorArray[index]==ColorIndex) SellSignal=true; if(SellSignal && counter<=NumberofAlerts) { counter++; MqlDateTime tm; TimeToStruct(TimeCurrent(),tm); string text=TimeToString(TimeCurrent(),TIME_DATE)+" "+string(tm.hour)+":"+string(tm.min); SeriesTest=ArrayGetAsSeries(Close); if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; double Ask=Close[index]; double Bid=Close[index]; SeriesTest=ArrayGetAsSeries(Spread); if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; Bid+=Spread[index]; string sAsk=DoubleToString(Ask,_Digits); string sBid=DoubleToString(Bid,_Digits); string sPeriod=GetStringTimeframe(ChartPeriod()); if(SoundON) Alert("SELL signal \n Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod); if(EMailON) SendMail(SignalSirname+": SELL signal alert","SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod); if(PushON) SendNotification(SignalSirname+": SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod); } //--- } //+------------------------------------------------------------------+ //| Getting the timeframe as a string | //+------------------------------------------------------------------+ string GetStringTimeframe(ENUM_TIMEFRAMES timeframe) { //---- return(StringSubstr(EnumToString(timeframe),7,-1)); //---- }
- Function Calls Added: The indicator now includes calls to the BuySignal() and SellSignal() functions after the calculation cycles in the OnCalculate() block:
//--- BuySignal("X2MA_Alert",ColorX2MA,1,rates_total,prev_calculated,close,spread); SellSignal("X2MA_Alert",ColorX2MA,2,rates_total,prev_calculated,close,spread); //---
Here, ColorX2MA is the name of the color index buffer that stores line color as an index.
It's important to note that you'll typically call the BuySignal() and SellSignal() functions only once within the OnCalculate() block.
The ColorX2MA_Alert indicator utilizes the classes from the SmoothAlgorithms.mqh library, which you can find by copying it to your <terminal_data_folder>\MQL5\Include. For a detailed explanation on how to use these classes, check out the article "Averaging Price Series for Intermediate Calculations Without Using Additional Buffers".
Fig1. The ColorX2MA_Alert indicator on the chart
Fig.2. The ColorX2MA_Alert indicator. Generating alerts.
Related Posts
- Understanding the ColorX2MA_Osc Indicator for MetaTrader 5
- X2MA_HTF_Signal_BG: A Must-Have Indicator for Your MetaTrader 5 Trading Strategy
- Unlocking the Power of X2MA Transform Candles for MetaTrader 5
- Unlocking Trading Insights: The X2MA_HTF_Signal Indicator for MetaTrader 5
- Mastering the ColorX2MA Cloud Indicator for MetaTrader 5

