Same High Or Low Alert

Author: Copyright © 2022, Vladimir Karputov
Price Data Components
Miscellaneous
It plays sound alertsIt issuies visual alerts to the screenIt sends emails
0 Views
0 Downloads
0 Favorites
Same High Or Low Alert
ÿþ//+------------------------------------------------------------------+

//|                                       Same High Or Low Alert.mq5 |

//|                              Copyright © 2022, Vladimir Karputov |

//|                      https://www.mql5.com/en/users/barabashkakvn |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2022, Vladimir Karputov"

#property link      "https://www.mql5.com/en/users/barabashkakvn"

#property version   "1.000"

#property description "Search for two identical bars (which are next to each other) that have the same price 'High' or 'Low'"

#property description "Accuracy in Points (1.00055-1.00045=10 points)"

#property indicator_chart_window

#property indicator_buffers 0

#property indicator_plots   0

//--- input parameters

input group             "Main settings"

input uint                 InpAccuracy             = 3;           // Accuracy

input bool                 InpCurrent              = false;       // 'true' -> search on bar #0, 'false' -> on bar #1

input group             "Alerts"

input string               InpSoundName            = "alert.wav"; // Sound Name

input uchar                InpSoundRepetitions     = 3;           // Repetitions

input uchar                InpSoundPause           = 3;           // Pause, in seconds

input bool                 InpAlert                = true;        // Alert

input bool                 InpMail                 = true;        // Send mail

input bool                 InpNotification         = true;        // Send notification

//---

double   m_accuracy        = 0.0;

int      m_bar_current     = 0;

datetime m_last_sound      = 0;        // "0" -> D'1970.01.01 00:00';

uchar    m_repetitions     = 0;        //

string   m_text            = "";       //

datetime m_prev_bars       = 0;        // "0" -> D'1970.01.01 00:00';

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

   m_accuracy=InpAccuracy*Point();

   m_bar_current=(InpCurrent)?0:1;

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

   if(rates_total<2)

      return(0);

//--- alert

   if(time[rates_total-1]>m_prev_bars)

     {

      m_last_sound=0;

      m_prev_bars=time[rates_total-1];

      m_repetitions=0;

     }

   if(m_repetitions>=InpSoundRepetitions)

      return(rates_total);

   datetime time_current=TimeCurrent();

   if(time_current-m_last_sound>InpSoundPause)

     {

      int i=rates_total-1;

      if(MathAbs(high[i-m_bar_current]-high[i-1-m_bar_current])<=m_accuracy)

        {

         PlaySound(InpSoundName);

         m_text=Symbol()+","+StringSubstr(EnumToString(Period()),7,-1)+" Same High, "+TimeToString(time[i]);

         if(InpAlert)

            Alert(m_text);

         m_last_sound=time_current;

         m_repetitions++;

         //---

         if(InpMail)

           {

            SendMail(Symbol()+","+StringSubstr(EnumToString(Period()),7,-1),m_text);

           }

         if(InpNotification)

           {

            SendNotification(Symbol()+","+StringSubstr(EnumToString(Period()),7,-1)+" "+m_text);

           }

        }

      if(MathAbs(low[i-m_bar_current]-low[i-1-m_bar_current])<=m_accuracy)

        {

         PlaySound(InpSoundName);

         m_text=Symbol()+","+StringSubstr(EnumToString(Period()),7,-1)+" Same Low, "+TimeToString(time[i]);

         if(InpAlert)

            Alert(m_text);

         m_last_sound=time_current;

         m_repetitions++;

         //---

         if(InpMail)

           {

            SendMail(Symbol()+","+StringSubstr(EnumToString(Period()),7,-1),m_text);

           }

         if(InpNotification)

           {

            SendNotification(Symbol()+","+StringSubstr(EnumToString(Period()),7,-1)+" "+m_text);

           }

        }

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments