Aroon_Oscillator_with_Alerts

Author: Copyright 2018, MetaQuotes Software Corp.
Price Data Components
Miscellaneous
It issuies visual alerts to the screenIt sends emails
0 Views
0 Downloads
0 Favorites
Aroon_Oscillator_with_Alerts
ÿþ//+------------------------------------------------------------------+

//|                                 Aroon_Oscillator_with_Alerts.mq5 |

//|                        Copyright 2018, MetaQuotes Software Corp. |

//|                                                 https://mql5.com |

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

#property copyright "Copyright 2018, MetaQuotes Software Corp."

#property link      "https://mql5.com"

#property version   "1.00"

#property description "Aroon oscillator with alerts"

#property description "Aroon Horn: https://www.mql5.com/ru/code/22182"

#property description "Aroon Filter: https://www.mql5.com/ru/code/22183"

#property indicator_separate_window

#property indicator_buffers 3

#property indicator_plots   2

//--- plot Aaron

#property indicator_label1  "Aroon"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrSeaGreen

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Hist

#property indicator_label2  "Hist"

#property indicator_type2   DRAW_COLOR_HISTOGRAM

#property indicator_color2  clrDodgerBlue,clrOrangeRed,clrDarkGray

#property indicator_style2  STYLE_SOLID

#property indicator_width2  8

//--- enums

enum ENUM_INPUT_YES_NO

  {

   INPUT_YES   =  1,    // Yes

   INPUT_NO    =  0     // No

  };

//--- input parameters

input uint              InpPeriod   =  10;         // Period

input double            InpFilter   =  50.0;       // Filter

input ENUM_INPUT_YES_NO InpUseAlert =  INPUT_YES;  // Show alerts

input ENUM_INPUT_YES_NO InpSendMail =  INPUT_NO;   // Send mail

input ENUM_INPUT_YES_NO InpSendPush =  INPUT_YES;  // Send push-notifications

//--- indicator buffers

double         BufferAroon[];

double         BufferHist[];

double         BufferColors[];

//--- global variables

double         filter;

int            period;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- set global variables

   period=int(InpPeriod<1 ? 1 : InpPeriod);

   filter=(InpFilter<0 ? 0 : InpFilter);

//--- indicator buffers mapping

   SetIndexBuffer(0,BufferAroon,INDICATOR_DATA);

   SetIndexBuffer(1,BufferHist,INDICATOR_DATA);

   SetIndexBuffer(2,BufferColors,INDICATOR_COLOR_INDEX);

//--- setting plot buffer parameters

   PlotIndexSetInteger(1,PLOT_SHOW_DATA,false);

//--- setting buffer arrays as timeseries

   ArraySetAsSeries(BufferAroon,true);

   ArraySetAsSeries(BufferHist,true);

   ArraySetAsSeries(BufferColors,true);

//--- setting indicator parameters

   IndicatorSetString(INDICATOR_SHORTNAME,"Aroon Osc Alerts ("+(string)period+")");

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

   if(filter>0)

     {

      IndicatorSetInteger(INDICATOR_LEVELS,2);

      IndicatorSetDouble(INDICATOR_LEVELVALUE,0,filter);

      IndicatorSetDouble(INDICATOR_LEVELVALUE,1,-filter);

     }

   else

      IndicatorSetInteger(INDICATOR_LEVELS,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[])

  {

//--- #AB0=>2:0 <0AA82>2 1CD5@>2 :0: B09<A5@89

   ArraySetAsSeries(time,true);

//--- @>25@:0 :>;8G5AB20 4>ABC?=KE 10@>2

   if(rates_total<fmax(period,4)) return 0;

//--- @>25@:0 8 @0AGQB :>;8G5AB20 ?@>AG8BK205<KE 10@>2

   int limit=rates_total-prev_calculated;

   if(limit>1)

     {

      limit=rates_total-2;

      ArrayInitialize(BufferAroon,EMPTY_VALUE);

      ArrayInitialize(BufferHist,EMPTY_VALUE);

      ArrayInitialize(BufferColors,2);

     }

   

//---  0AGQB 8=48:0B>@0

   static datetime last_time;

   for(int i=limit; i>=0 && !IsStopped(); i--)

     {

      int bh=iHighest(NULL,PERIOD_CURRENT,MODE_HIGH,period,i);

      int bl=iLowest(NULL,PERIOD_CURRENT,MODE_LOW,period,i);

      if(bh==WRONG_VALUE || bl==WRONG_VALUE)

         continue;

      

      BufferHist[i]=BufferAroon[i]=100.0*(bl-bh)/period;



      if(BufferAroon[i]>filter)

        {

         BufferColors[i]=0;

         if(i==0 && BufferAroon[i+1]<filter && time[0]>last_time)

           {

            Notifications("Aaron Up Signal",InpUseAlert,InpSendPush,InpSendMail);

            last_time=time[0];

           }

        }

      else if(BufferAroon[i]<-filter)

        {

         BufferColors[i]=1;

         if(i==0 && BufferAroon[i+1]>-filter && time[0]>last_time)

           {

            Notifications("Aaron Down Signal",InpUseAlert,InpSendPush,InpSendMail);

            last_time=time[0];

           }

        }

      else

         BufferColors[i]=2;

     }

   

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

   return(rates_total);

  }

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

//| B?@02;O5B A>>1I5=8O                                             |

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

void Notifications(const string mess,bool use_alert=true,bool send_push=true,bool send_mail=false)

  {

   string message=Symbol()+", "+TimeframeToString(Period())+": "+mess;

   if(use_alert) Alert(message);

   if(send_mail  && TerminalInfoInteger(TERMINAL_EMAIL_ENABLED)) SendMail(MQLInfoString(MQL_PROGRAM_NAME)+" "+ProgramType()+" Signal",message);

   if(send_push && TerminalInfoInteger(TERMINAL_NOTIFICATIONS_ENABLED)) SendNotification(MQLInfoString(MQL_PROGRAM_NAME)+" "+ProgramType()+" Signal: "+message);

  }

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

//| >72@0I05B =08<5=>20=85 B8?0 ?@>3@0<<K                           |

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

string ProgramType(void)

  {

   ENUM_PROGRAM_TYPE type=(ENUM_PROGRAM_TYPE)MQLInfoInteger(MQL_PROGRAM_TYPE);

   return(type==PROGRAM_INDICATOR ? "indicator" : type==PROGRAM_EXPERT ? "expert" : "script");

  }

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

//| Timeframe to string                                              |

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

string TimeframeToString(const ENUM_TIMEFRAMES timeframe)

  {

   return StringSubstr(EnumToString(timeframe),7);

  }

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

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