Author: Copyright © 2022, Vladimir Karputov
Miscellaneous
It plays sound alertsIt issuies visual alerts to the screenIt sends emails
2 Views
0 Downloads
0 Favorites
86DrzM
ÿþ//+------------------------------------------------------------------+

//|                                                       86DrzM.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.009"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot Down

#property indicator_label1  "Down"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrCoral

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Up

#property indicator_label2  "Up"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrDeepSkyBlue

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- input parameters

input group           "Arrows"

input uchar                InpUpArrowCode          = 242;         // Arrow Up: code (font Wingdings)

input int                  InpUpArrowShift         = 5;           // Arrow Up: vertical shift in pixel

input uchar                InpDownArrowCode        = 241;         // Arrow Down: code (font Wingdings)

input int                  InpDownArrowShift       = 5;           // Arrow Down: vertical shift in pixel

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

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

//--- indicator buffers

double   SignalDownBuffer[];

double   SignalUpBuffer[];

//---

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

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,SignalDownBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,SignalUpBuffer,INDICATOR_DATA);

//--- setting a code from the Wingdings charset as the property of PLOT_ARROW

   PlotIndexSetInteger(0,PLOT_ARROW,InpUpArrowCode);

   PlotIndexSetInteger(1,PLOT_ARROW,InpDownArrowCode);

//--- Set the vertical shift of arrows in pixels

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,-InpUpArrowShift);

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,InpDownArrowShift);

//--- Set as an empty value 0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,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<4)

      return(0);

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      limit=4;

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

        {

         SignalDownBuffer[i]=0.0;

         SignalUpBuffer[i]=0.0;

        }

     }

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

     {

      if(Inp_applied_volume==VOLUME_TICK)

        {

         //--- Indicator Buffer 1

         if(low[i-1] < low[i-2] //Candlestick Low < Candlestick Low

            && high[i] < high[i-2] //Candlestick High < Candlestick High

            && close[i] < low[i-1] //Candlestick Close < Candlestick Low

            && tick_volume[i-1] > tick_volume[i-2] //Volumes > Volumes

            && tick_volume[i] > tick_volume[i-1] //Volumes > Volumes

           )

            SignalDownBuffer[i]=high[i];

         else

            SignalDownBuffer[i]=0.0;

         //--- Indicator Buffer 2

         if(high[i-1] > high[i-2] //Candlestick High > Candlestick High

            && low[i] > low[i-2] //Candlestick Low > Candlestick Low

            && close[i] > high[i-1] //Candlestick Close > Candlestick High

            && tick_volume[i-1] < tick_volume[i-2] //Volumes < Volumes

            && tick_volume[i] < tick_volume[i-1] //Volumes < Volumes

           )

           {

            SignalUpBuffer[i]=low[i];

           }

         else

           {

            SignalUpBuffer[i]=0.0;

           }

        }

      else

        {

         //--- Indicator Buffer 1

         if(low[i-1] < low[i-2] //Candlestick Low < Candlestick Low

            && high[i] < high[i-2] //Candlestick High < Candlestick High

            && close[i] < low[i-1] //Candlestick Close < Candlestick Low

            && volume[i-1] > volume[i-2] //Volumes > Volumes

            && volume[i] > volume[i-1] //Volumes > Volumes

           )

            SignalDownBuffer[i]=high[i];

         else

            SignalDownBuffer[i]=0.0;

         //--- Indicator Buffer 2

         if(high[i-1] > high[i-2] //Candlestick High > Candlestick High

            && low[i] > low[i-2] //Candlestick Low > Candlestick Low

            && close[i] > high[i-1] //Candlestick Close > Candlestick High

            && volume[i-1] < volume[i-2] //Volumes < Volumes

            && volume[i] < volume[i-1] //Volumes < Volumes

           )

           {

            SignalUpBuffer[i]=low[i];

           }

         else

           {

            SignalUpBuffer[i]=0.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(SignalDownBuffer[i]!=0.0)

        {

         PlaySound(InpSoundName);

         m_text=Symbol()+","+StringSubstr(EnumToString(Period()),7,-1)+" Signal DOWN, "+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);

           }

        }

      else

        {

         if(SignalUpBuffer[i]!=0.0)

           {

            PlaySound(InpSoundName);

            m_text=Symbol()+","+StringSubstr(EnumToString(Period()),7,-1)+" Signal UP, "+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

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---