Home Technical Indicator Post

Mastering the Waddah Attar Trend Alert Indicator for MetaTrader 5

Attachments
16832.zip (22.5 KB, Download 0 times)

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(), and GetStringTimeframe().
    //+------------------------------------------------------------------+
    //| 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() and SellSignal() functions have been added after the indicator calculations in the OnCalculate() 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, ColorIndBuffer is 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() and SellSignal() functions is planned for use within the OnCalculate() block of the indicator code.

    The indicator relies on the SmoothAlgorithms.mqh library 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".

Waddah_Attar_Trend_Alert indicator on the chart

Fig.1. Waddah_Attar_Trend_Alert indicator on the chart

Waddah_Attar_Trend_Alert indicator. Generating alerts

Fig.2. Waddah_Attar_Trend_Alert indicator. Generating alerts

Related Posts

Comments (0)