Volume Change Histogram Alert 2

Author: Copyright © 2020, Vladimir Karputov
Miscellaneous
It plays sound alertsIt issuies visual alerts to the screenIt sends emails
0 Views
0 Downloads
0 Favorites
Volume Change Histogram Alert 2
ÿþ//+------------------------------------------------------------------+

//|                              Volume Change Histogram Alert 2.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43516 |

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

#property copyright "Copyright © 2020, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43516"

#property description "New in 2.0: Send an email to an address specified in the Email tab of the options window"

#property description "New in 2.0: Send push notifications to mobile terminals whose MetaQuotes IDs are specified in the Notifications tab"

#property version   "2.000"

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_plots   1

//--- plot VolumeChange

#property indicator_label1  "VolumeChange"

#property indicator_type1   DRAW_HISTOGRAM

#property indicator_color1  clrMediumSeaGreen

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- input parameters

input double                  InpCoefficient          = 1.99;           // Volume Change Coefficient

input ENUM_APPLIED_VOLUME     InpAppliedVolume        = VOLUME_TICK;    // Volume type for calculation

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

input uchar                   InpSoundRepetitions     = 3;              // Repeats on the same bar

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

input bool                    InpMailNotificationOne  = true;           // Email and notifications only once per bar

input bool                    InpSendMail             = true;           // Send an email

input bool                    InpSendNotification     = true;           // Send push notifications

//--- indicator buffers

double   VolumeChangeBuffer[];

//---

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

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

int      m_repeats         = 0;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,VolumeChangeBuffer,INDICATOR_DATA);

//--- an empty value for plotting, for which there is no drawing

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

//---

   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<1)

      return(0);

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      VolumeChangeBuffer[0]=0.0;

      limit=1;

     }

//--- main loop

   if(time[rates_total-1]>m_prev_bars)

     {

      m_last_signal=0;

      m_prev_bars=time[rates_total-1];

      m_repeats=0;

     }

   for(int i=limit; i<rates_total; i++)

     {

      //---

      datetime time_current=TimeCurrent();

      //--- calculate with appropriate volumes

      if(InpAppliedVolume==VOLUME_TICK)

        {

         if(tick_volume[i]>tick_volume[i-1]*InpCoefficient)

           {

            VolumeChangeBuffer[i]=(double)tick_volume[i];

            if(prev_calculated>0)

               if(m_repeats<InpSoundRepetitions)

                  if(time_current>=m_last_signal)

                    {

                     PlaySound(InpSoundName);

                     Alert("Volume Change Histogram ("+DoubleToString(VolumeChangeBuffer[i],0)+")");

                     if(InpSendMail || InpSendNotification)

                       {

                        if(InpMailNotificationOne)

                          {

                           if(m_repeats==0)

                             {

                              Sends(VolumeChangeBuffer[i]);

                             }

                          }

                        else

                          {

                           Sends(VolumeChangeBuffer[i]);

                          }

                       }

                     m_last_signal=time_current+InpSoundPause;

                     m_repeats++;

                    }

           }

         else

           {

            VolumeChangeBuffer[i]=0.0;

            //--- pause

            m_last_signal=time_current;

           }

        }

      else

        {

         if(volume[i]>volume[i-1]*InpCoefficient)

           {

            VolumeChangeBuffer[i]=(double)volume[i];

            if(prev_calculated>0)

               if(m_repeats<InpSoundRepetitions)

                  if(time_current>=m_last_signal)

                    {

                     PlaySound(InpSoundName);

                     Alert("Volume Change Histogram ("+DoubleToString(VolumeChangeBuffer[i],0)+")");

                     if(InpSendMail || InpSendNotification)

                       {

                        if(InpMailNotificationOne)

                          {

                           if(m_repeats==0)

                             {

                              Sends(VolumeChangeBuffer[i]);

                             }

                          }

                        else

                          {

                           Sends(VolumeChangeBuffer[i]);

                          }

                       }

                     m_last_signal=time_current+InpSoundPause;

                     m_repeats++;

                    }

           }

         else

           {

            VolumeChangeBuffer[i]=0.0;

            //--- pause

            m_last_signal=time_current;

           }

        }

     }

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

   return(rates_total);

  }

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

//| Send Mail and Notification                                       |

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

void Sends(const double volume)

  {

   if(InpSendMail)

     {

      ResetLastError();

      if(!SendMail(Symbol()+","+StringSubstr(EnumToString(Period()),7,-1),"Volume Change Histogram ("+DoubleToString(volume,0)+")"))

        {

         Print(__FILE__," ",__FUNCTION__,", ERROR Send Mail: ",GetLastError());

        }

     }

   if(InpSendNotification)

     {

      ResetLastError();

      if(!SendNotification(Symbol()+","+StringSubstr(EnumToString(Period()),7,-1)+", "+"Volume Change Histogram ("+DoubleToString(volume,0)+")"))

        {

         Print(__FILE__," ",__FUNCTION__,", ERROR Send Notification: ",GetLastError());

        }

     }

  }

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

Comments