RoundPriceAlertOnChart

Author: Copyright © 2011, Nikolay Kositsin
Miscellaneous
It plays sound alertsIt issuies visual alerts to the screenIt sends emails
0 Views
0 Downloads
0 Favorites
RoundPriceAlertOnChart
ÿþ//+------------------------------------------------------------------+ 

//|                                       RoundPriceAlertOnChart.mq5 | 

//|                               Copyright © 2018, Nikolay Kositsin | 

//|                              Khabarovsk,   farria@mail.redcom.ru | 

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

//---- 02B>@AB2> 8=48:0B>@0

#property copyright "Copyright © 2011, Nikolay Kositsin"

//---- AAK;:0 =0 A09B 02B>@0

#property link "farria@mail.redcom.ru"

//---- =><5@ 25@A88 8=48:0B>@0

#property version   "1.00"

#property description "2C:>20O A83=0;870F8O :@C3;>3> 7=0G5=8O F5=K"

//---- >B@8A>2:0 8=48:0B>@0 2 >A=>2=>< >:=5

#property indicator_chart_window

//--- :>;8G5AB2> 8=48:0B>@=KE 1CD5@>2

#property indicator_buffers 0

//--- 8A?>;L7>20=> 2A53> 3@0D8G5A:8E ?>AB@>5=89

#property indicator_plots   0

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

//| 5@5G8A;5=85 4;O B>;I8=K C@>2=O                |

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

enum ENUM_WIDTH //"8? :>=AB0=BK

  {

   w_1 = 1,   //1

   w_2,       //2

   w_3,       //3

   w_4,       //4

   w_5        //5

  };

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

//|  %+  " + "                   |

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

input bool On_Push = false;                               //@07@5H5=85 =0 ?5@540GC push-A>>1I5=89

input bool On_Email = false;                              //@07@5H5=85 =0 >B?@02:C ?>GBK

input bool On_Alert = true;                               //@07@5H5=85 =0 ?>40GC 0;5@B0

input bool On_Play_Sound = false;                         //@07@5H5=85 =0 ?>40GC 72C:>2>3> A83=0;0

input string NameFileSound = "expert.wav";                //8<O 4;O D09;0 72C:>2>3> A83=0;0

input string  CommentSirName="RoundPriceAlertOnChart";    //?5@20O G0ABL 0;5@B-:><<5=B0 8 =0720=8O 3@0D8G5A:8E >1J5:B>2

input uint RoundDigits=3;                                 //:>;8G5AB2> =C;59 2 @07@O40E 4;O >:@C3;5=8O

input uint SignalPause=5;                                 //8=B5@20; 2 <8=CB0E <564C A83=0;0<8

input color up_level_color=clrMediumSeaGreen;             //&25B 25@E=53> :@C3;>3> C@>2=O

input ENUM_LINE_STYLE up_level_style=STYLE_DASH;          //!B8;L 25@E=53> :@C3;>3> C@>2=O

input ENUM_WIDTH up_level_width=w_1;                      //">;I8=0 25@E=53> :@C3;>3> C@>2=O

input color dn_level_color=clrMagenta;                    //&25B =86=53> :@C3;>3> C@>2=O

input ENUM_LINE_STYLE dn_level_style=STYLE_DASH;          //!B8;L =86=53> :@C3;>3> C@>2=O

input ENUM_WIDTH dn_level_width=w_1;                      //">;I8=0 =86=53> :@C3;>3> C@>2=O

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

//---- >1JO2;5=85 F5;>G8A;5==KE ?5@5<5==KE =0G0;0 >BAG5B0 40==KE

int min_rates_total;

double ratio,power;

string up_level_name,dn_level_name;

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

//---- =8F80;870F8O ?5@5<5==KE =0G0;0 >BAGQB0 40==KE

   min_rates_total=2;

   power=MathPow(10,RoundDigits);

   ratio=_Point*power;

   up_level_name=CommentSirName+": Upper round price";

   dn_level_name=CommentSirName+": Lower round price";

   

   if(ObjectFind(0,up_level_name)==-1) CreateHline(0,up_level_name,0,0,up_level_color,up_level_style,up_level_width,false,"5@E=OO :@C3;0O F5=0");

   if(ObjectFind(0,dn_level_name)==-1) CreateHline(0,dn_level_name,0,0,dn_level_color,dn_level_style,dn_level_width,false,"86=OO :@C3;0O F5=0");

   

//--- A>740=85 8<5=8 4;O >B>1@065=8O 2 >B45;L=>< ?>4>:=5 8 2> 2A?;K20NI59 ?>4A:07:5

   string shortname="RoundPriceAlertOnChart";

   IndicatorSetString(INDICATOR_SHORTNAME,shortname);

//---- ?>AB028< :><<5=B >1 8=48:0B>@5 =0 3@0D8:

   Comment(shortname);

//--- >?@545;5=85 B>G=>AB8 >B>1@065=8O 7=0G5=89 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//---- 7025@H5=85 8=8F80;870F88

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//---- C40;8< :><<5=B >1 8=48:0B>@5 A 3@0D8:0

   Comment("");

   ObjectDelete(0,up_level_name);

   ObjectDelete(0,dn_level_name);

//----

  }

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

//| Custom indicator iteration function                              | 

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

int OnCalculate(const int rates_total,    // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5

                const int prev_calculated,// :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5

                const datetime &time[],

                const double &open[],

                const double& high[],     // F5=>2>9 <0AA82 <0:A8<C<>2 F5=K 4;O @0AGQB0 8=48:0B>@0

                const double& low[],      // F5=>2>9 <0AA82 <8=8<C<>2 F5=K  4;O @0AGQB0 8=48:0B>@0

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AGQB0

   if(rates_total<min_rates_total) return(0);



//----

   static double LastRes;

   static datetime LastSignalTime;

//--- 8=45:A0F8O M;5<5=B>2 2 <0AA820E =5 :0: 2 B09<A5@8OE  

   ArraySetAsSeries(close,false);

//---- 

   datetime SignalTime=TimeCurrent();

   double Price=close[rates_total-1];

   double Res=MathFloor(Price/ratio);

   double RoundPrice=Res*ratio;

   double UpRoundPrice,DnRoundPrice;

   if(RoundPrice<Price)

     {

      UpRoundPrice=RoundPrice+ratio;

      DnRoundPrice=RoundPrice;     

     }

   else

     {

      UpRoundPrice=RoundPrice;

      DnRoundPrice=RoundPrice-ratio;     

     }

     

   SetHline(0,up_level_name,0,UpRoundPrice,up_level_color,up_level_style,up_level_width,false,"5@E=OO :@C3;0O F5=0");

   SetHline(0,dn_level_name,0,DnRoundPrice,dn_level_color,dn_level_style,dn_level_width,false,"86=OO :@C3;0O F5=0");



   if(prev_calculated>rates_total || prev_calculated<=0) // ?@>25@:0 =0 ?5@2K9 AB0@B @0AGQB0 8=48:0B>@0

     {

      LastRes=Res;

      LastSignalTime=SignalTime;

     }

     

   int dTime=int((SignalTime-LastSignalTime)/60);



   if(LastRes!=Res && dTime>int(SignalPause))

     {

      if(On_Play_Sound) PlaySound(NameFileSound);     

      string comment,sTime=" CurrTime="+TimeToString(SignalTime,TIME_MINUTES);

      StringConcatenate(comment,CommentSirName,Symbol(),sTime," &5=0 ?@>18;0 C@>25=L ",DoubleToString(Res*ratio,_Digits),"!");   

      if(On_Alert) Alert(comment);

      if(On_Push) SendNotification(comment);

      if(On_Email) SendMail(CommentSirName+Symbol(),comment);     

      LastSignalTime=SignalTime;

      LastRes=Res;

     }

//----    

   return(rates_total);

  }

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

//|  !>740=85 3>@87>=B0;L=>9 ;8=88                                   |

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

void CreateHline(long     chart_id,      // 845=B8D8:0B>@ 3@0D8:0

                 string   name,          // 8<O >1J5:B0

                 int      nwin,          // 8=45:A >:=0

                 double   price,         // F5=0 3>@87>=B0;L=>3> C@>2=O

                 color    Color,         // F25B ;8=88

                 int      style,         // AB8;L ;8=88

                 int      width,         // B>;I8=0 ;8=88

                 bool     background,    // D>=>2>5 >B>1@065=85 ;8=88

                 string   text)          // B5:AB

  {

//----

   ObjectCreate(chart_id,name,OBJ_HLINE,nwin,0,price);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style);

   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width);

   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,background);

   ObjectSetInteger(chart_id,name,OBJPROP_RAY,true);

   ObjectSetInteger(chart_id,name,OBJPROP_SELECTED,false);

   ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,false);

   ObjectSetInteger(chart_id,name,OBJPROP_ZORDER,true);

//----

  }

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

//|  5@5CAB0=>2:0 3>@87>=B0;L=>9 ;8=88                              |

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

void SetHline(long     chart_id,      // 845=B8D8:0B>@ 3@0D8:0

              string   name,          // 8<O >1J5:B0

              int      nwin,          // 8=45:A >:=0

              double   price,         // F5=0 3>@87>=B0;L=>3> C@>2=O

              color    Color,         // F25B ;8=88

              int      style,         // AB8;L ;8=88

              int      width,         // B>;I8=0 ;8=88

              bool     background,    // D>=>2>5 >B>1@065=85 ;8=88

              string   text)          // B5:AB

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateHline(chart_id,name,nwin,price,Color,style,width,background,text);

   else

     {

      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

      ObjectMove(chart_id,name,0,0,price);

      ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

     }

//----

  }

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

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