LOD_HOD_Price_Break

Author: Copyright 2018, MetaQuotes Software Corp.
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains open time of each bar
Miscellaneous
It issuies visual alerts to the screenIt sends emails
2 Views
0 Downloads
0 Favorites
LOD_HOD_Price_Break
ÿþ//+------------------------------------------------------------------+

//|                                          LOD_HOD_Price_Break.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 "Price break Low of Day/High of Day Alert indicator"

#property description "This indicator will alert the trader when price breaks either the high or low of the previous day."

#property description "It will also display the high and low that price needed to break each day."

#property indicator_chart_window

#property indicator_buffers 0

#property indicator_plots   0

//--- enums

enum ENUM_INPUT_YES_NO

  {

   INPUT_YES   =  1,       // Yes

   INPUT_NO    =  0        // No

  };

//--- input parameters

input uchar             InpLineWidth   =  2;             // Day line width

input ENUM_LINE_STYLE   InpStyle       =  STYLE_SOLID;   // Day line style

input color             InpLineColorUP =  clrRed;        // Upper price day line color

input color             InpLineColorDN =  clrBlue;       // Lower price day line color

input ENUM_INPUT_YES_NO InpUseAlerts   =  INPUT_YES;     // Use alerts

input ENUM_INPUT_YES_NO InpSendMail    =  INPUT_NO;      // Send mail

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

//--- global variables

string         prefix;

MqlRates       data[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- timer

   EventSetTimer(90);

//--- set global variables

   prefix=MQLInfoString(MQL_PROGRAM_NAME)+"_";

//--- setting indicator parameters

   IndicatorSetString(INDICATOR_SHORTNAME,"Price break PrLOD/HOD Alert");

//---

   ArrayResize(data,3);

   ArraySetAsSeries(data,true);

//---

   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//--- timer

   EventKillTimer();

   ObjectsDeleteAll(0,prefix,0);

   ChartRedraw();

//---

  }

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

//| 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(open,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);

   ArraySetAsSeries(time,true);

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

   if(rates_total<4) return 0;

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

   int limit=rates_total-prev_calculated;

   if(limit>1)

     {

      limit=rates_total-1;

     }



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

   static datetime last_time=0;

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

     {

      //--- Drawing the Lines

      double H=iHigh(NULL,PERIOD_D1,i+1);

      double L=iLow(NULL,PERIOD_D1,i+1);

      datetime line_start=iTime(NULL,PERIOD_D1,i);

      datetime line_end=(i>0 ? iTime(NULL,PERIOD_D1,(i-1)) : iTime(NULL,PERIOD_D1,i)+(1*86400));

      if(H==0 || L==0 || line_start==0 || line_end==0)

         continue;

      string pf=TimeToString(time[i]);

      DrawLine(prefix+"HIGH_"+pf,H,H,line_start,line_end,InpLineColorUP,InpLineWidth,InpStyle,"","High the day at "+TimeToString(line_start-PeriodSeconds(PERIOD_D1)));

      DrawLine(prefix+"LOW_"+pf,L,L,line_start,line_end,InpLineColorDN,InpLineWidth,InpStyle,"","Low the day at "+TimeToString(line_start-PeriodSeconds(PERIOD_D1)));

     }

     

//--- ;5@BK

   if(last_time!=time[0])

     {

      if(close[0]>iHigh(NULL,PERIOD_D1,1))

        {

         string message="Price is Higher than Yesterday's High";

         Notifications(message,InpUseAlerts,InpSendPush,InpSendMail);

         last_time=time[0];

        }

      if(close[0]<iLow(NULL,PERIOD_D1,1))

        {

         string message="Price is Lower than Yesterday's High";

         Notifications(message,InpUseAlerts,InpSendPush,InpSendMail);

         last_time=time[0];

        }

     }



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

   return(rates_total);

  }

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

//| Timer function                                                   |

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

void OnTimer()

  {

   Time(NULL,PERIOD_D1,1);

  }

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

//| >72@0I05B 2@5<O 10@0                                            |

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

datetime Time(const string symbol_name,const ENUM_TIMEFRAMES timeframe,const int index)

  {

   datetime array[];

   return(CopyTime(symbol_name,timeframe,index,1,array)==1 ? array[0] : 0);

  }

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

//| 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);

  }

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

//| K2>48B B@5=4>2CN ;8=8N                                          |

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

void DrawLine(const string name,const double price1,const double price2,const datetime time1,const datetime time2,const color line_color,const int line_width,const ENUM_LINE_STYLE line_style,const string text="\n",const string tooltip="\n")

  {

   if(ObjectFind(0,name)<0)

     {

      ObjectCreate(0,name,OBJ_TREND,0,time1,price1,time2,price2);

      ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);

      ObjectSetInteger(0,name,OBJPROP_SELECTED,false);

      ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);

      ObjectSetInteger(0,name,OBJPROP_RAY_LEFT,false);

      ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);

     }

   ObjectSetInteger(0,name,OBJPROP_TIME,0,time1);

   ObjectSetInteger(0,name,OBJPROP_TIME,1,time2);

   ObjectSetDouble(0,name,OBJPROP_PRICE,0,price1);

   ObjectSetDouble(0,name,OBJPROP_PRICE,1,price2);

//---

   ObjectSetInteger(0,name,OBJPROP_WIDTH,line_width);

   ObjectSetInteger(0,name,OBJPROP_COLOR,line_color);

   ObjectSetInteger(0,name,OBJPROP_STYLE,line_style);

   ObjectSetString(0,name,OBJPROP_TEXT,text);

   ObjectSetString(0,name,OBJPROP_TOOLTIP,tooltip);

  }

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

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