Created by: Eng. Waddah Attar
The Waddah Attar Trend Alert indicator for MetaTrader 5 is a game changer for traders, featuring alerts, email notifications, and push alerts right on your mobile device.
Let’s dive into the recent updates that have been made to the indicator’s code to enhance its functionality:
- New Input Parameters:
//---- Inputs 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
- New Functions Added: Three new functions have been added to the end of the indicator code:
BuySignal(),SellSignal(), andGetStringTimeframe().//+------------------------------------------------------------------+ //| Buy signal function | //+------------------------------------------------------------------+ void BuySignal(string SignalSirname, // indicator name for alerts double &ColorArray[], // color index buffer int ColorIndex, // color index for generating a signal const int Rates_total, // current number of bars const int Prev_calculated, // bars from 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+=_Point*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, // indicator name for alerts double &ColorArray[], // color index buffer int ColorIndex, // color index for generating a signal const int Rates_total, // current number of bars const int Prev_calculated, // bars from 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+=_Point*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 a timeframe as a string | //+------------------------------------------------------------------+ string GetStringTimeframe(ENUM_TIMEFRAMES timeframe) { //---- return(StringSubstr(EnumToString(timeframe),7,-1)); //---- }
- Function Calls: Calls to the
BuySignal()andSellSignal()functions have been added after the indicator calculations in theOnCalculate()block.//--- BuySignal("Waddah_Attar_Trend_Alert",ColorIndBuffer,0,rates_total,prev_calculated,close,spread); SellSignal("Waddah_Attar_Trend_Alert",ColorIndBuffer,1,rates_total,prev_calculated,close,spread); //---
In this case,
ColorIndBufferis the name of a color index buffer that stores a line color as an index, where 0 and 1 represent the colors in the buffer.It's important to note that only one call to
BuySignal()andSellSignal()functions is planned for use within theOnCalculate()block of the indicator code.The indicator relies on the
SmoothAlgorithms.mqhlibrary classes (make sure to copy it to<terminal_data_folder>\MQL5\Include). The usage of these classes is thoroughly explained in the article "Averaging Price Series for Intermediate Calculations Without Using Additional Buffers".
Fig.1. Waddah_Attar_Trend_Alert indicator on the chart
Fig.2. Waddah_Attar_Trend_Alert indicator. Generating alerts
Related Posts
- Unlock Trading Insights with Volume Profile + Range v6.0 for MetaTrader 5
- Hourly Buffers for Data Collection in MetaTrader 5: A Simple Guide
- Maximize Your Trading Potential with the ColorX2MA_Alert Indicator for MetaTrader 5
- Unlocking the Power of ColorJFatl_Digit_Alert: Your Go-To MT5 Indicator
- Unlocking BykovTrendAlert: Your Go-To Indicator for MT5 Alerts

