Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Views:
4709
Rating:
(16)
Published:
2016.09.19 12:39
Updated:
2023.03.29 13:47
\MQL5\Include\
PPO_SignAlert.mq5 (14.98 KB) view

Semaphore signal indicator based on the relative smoothed rate of price change , which features alerts, sending emails and push-notifications to mobile devices.

The following changes have been made to the indicator code in order to implement the alerts, email messages and push-notifications:

  1. Introduced new input parameters
    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
    
  2. Added three new functions to 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 &BuyArrow[],        // indicator buffer with buy signals
                   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
      {
    u//---
       static uint counter=0;
       if(Rates_total!=Prev_calculated) counter=0;
    
       bool BuySignal=false;
       bool SeriesTest=ArrayGetAsSeries(BuyArrow);
       int index;
       if(SeriesTest) index=int(NumberofBar);
       else index=Rates_total-int(NumberofBar)-1;
       if(NormalizeDouble(BuyArrow[index],_Digits) && BuyArrow[index]!=EMPTY_VALUE) 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);
         }
    
    u//---
      }
    //+------------------------------------------------------------------+
    //| Sell signal function                                             |
    //+------------------------------------------------------------------+
    void SellSignal(string SignalSirname,      // text of the indicator name for email and push messages
                    double &SellArrow[],       // indicator buffer with sell signals
                    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
      {
    u//---
       static uint counter=0;
       if(Rates_total!=Prev_calculated) counter=0;
    
       bool SellSignal=false;
       bool SeriesTest=ArrayGetAsSeries(SellArrow);
       int index;
       if(SeriesTest) index=int(NumberofBar);
       else index=Rates_total-int(NumberofBar)-1;
       if(NormalizeDouble(SellArrow[index],_Digits) && SellArrow[index]!=EMPTY_VALUE) 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);
         }
    u//---
      }
    //+------------------------------------------------------------------+
    //|  Getting the timeframe as a string                               |
    //+------------------------------------------------------------------+
    string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
      {
    //----
       return(StringSubstr(EnumToString(timeframe),7,-1));
    //----
      }
    
  3. Added a couple of calls to BuySignal() and SellSignal() functions after the indicator calculation cycles in the OnCalculate() block
    u//---     
       BuySignal("PPO_Sign",BuyBuffer,rates_total,prev_calculated,close,spread);
       SellSignal("PPO_Sign",SellBuffer,rates_total,prev_calculated,close,spread);
    u//---   
    

Where BuyBuffer and SellBuffer are the names of the indicator buffers for storing the buy and sell signals. As the empty values in the indicator buffers either zeros or EMPTY_VALUE must be set.

It is assumed that the only one call to the BuySignal() and SellSignal() functions will be used in the OnCalculate() block of the indicator code.

The indicator uses SmoothAlgorithms.mqh library classes (copy it to <terminal_data_folder>\MQL5\Include). The use of the classes was thoroughly described in the article "Averaging Price Series for Intermediate Calculations Without Using Additional Buffers".

Originally this indicator has been written in MQL4 and was first published in the Code Base on 08.03.2008.

Fig.1. The PPO_SignAlert indicator on the chart

Fig.1. The PPO_SignAlert indicator on the chart

Fig.2. The PPO_SignAlert indicator. Generating alerts.

Fig.2. The PPO_SignAlert indicator. Generating alerts.

Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/16108

BalanceOfPower_Histogram BalanceOfPower_Histogram

The Balance of Power (BOP) indicator as a color histogram of strength and direction of the current trend.

Exp_RAVI_Histogram Exp_RAVI_Histogram

The Exp_RAVI_Histogram breakout trading system based on the signals of the RAVI_Histogram oscillator.

Exp_i-SpectrAnalysis_RVI Exp_i-SpectrAnalysis_RVI

The Exp_i-SpectrAnalysis_RVI EA is based on the signals generated by the i-SpectrAnalysis_RVI oscillator.

CPrice CPrice

Instance of the class returns such values as Bid, Ask, High, Low, Close and Open prices of the current candle or any other specified in the parameters, as well as the candle opening time.