BollingerBands_Box

Author: Copyright © 2018, Nikolay Kositsin
Price Data Components
Indicators Used
Bollinger bands indicator
0 Views
0 Downloads
0 Favorites
BollingerBands_Box
ÿþ//+------------------------------------------------------------------+ 

//|                                           BollingerBands_Box.mq5 | 

//|                               Copyright © 2018, Nikolay Kositsin | 

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

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

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

#property copyright "Copyright © 2018, 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"

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

#property indicator_chart_window 

//---- 4;O @0AGQB0 8 >B@8A>2:8 8=48:0B>@0 =5 8A?>;L7>20=> =8 >4=>3> 1CD5@0

#property indicator_buffers 0

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

#property indicator_plots   0

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

//|  >1JO2;5=85 :>=AB0=B                         |

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

#define RESET     0            // >=AB0=B0 4;O 2>72@0B0 B5@<8=0;C :><0=4K =0 ?5@5AG5B 8=48:0B>@0

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

//| E>4=K5 ?0@0<5B@K 8=48:0B>@0                 |

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

input string SirName="BollingerBands_Box";          //<O >1J5:B0 

input ENUM_TIMEFRAMES Timeframe=PERIOD_D1;          //"09<D@59< 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

input uint   NumberofBar=1;                         //><5@ 10@0 4;O @0AG5B0 8=48:0B>@0

input uint                BBPeriod=20;              //5@8>4 4;O @0AG5B0 A@54=59 ;8=88

input double              StdDeviation=2.0001;      //>;-2> >B:;>=5=89

input ENUM_APPLIED_PRICE  applied_price=PRICE_CLOSE;//"8? F5=K

input int                 Shift=0;                  //!4283 8=48:0B>@0 ?> 3>@87>=B0;8 2 10@0E

input bool ShowPrice=true;                          //?>:07K20BL F5=>2K5 <5B:8

input color Upper_color=clrLimeGreen;               //&25B 25@E=59 F5=>2>9 <5B:8

input color Middle_color=clrSlateGray;              //&25B A@54=59 F5=>2>9 <5B:8

input color Lower_color=clrRed;                     //&25B =86=59 F5=>2>9 <5B:8

input uint   BarsTotal=30;                          //:>;8G5AB2> 10@>2 ?@O<>C3>;L=8:>2

input uint   RightTail=5;                           //2KABC? ?@O<>C3>;L=8:>2 70 =C;52>9 10@ 2?@02> 2 10@0E B5:CI53> 3@0D8:0

input color  Color_Res=C'157,255,255';              //&25B 25@E=59 :>@>1:8

input color  Color_Sup=C'255,176,255';              //&25B =86=59 :>@>1:8

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

//--- >1JO2;5=85 F5;>G8A;5==KE ?5@5<5==KE 4;O E5=4;>2 8=48:0B>@>2

int Ind_Handle;

string UpBoxName,DnBoxName;

string upper_name,middle_name,lower_name;

uint SecondRightTail,SecondLeftTail;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- ?>;CG5=85 E5=4;0 8=48:0B>@0 BollingerBands

   Ind_Handle=iBands(Symbol(),Timeframe,BBPeriod,0,StdDeviation,applied_price);

   if(Ind_Handle==INVALID_HANDLE)

     {

      Print(" 5 C40;>AL ?>;CG8BL E5=4; 8=48:0B>@0 BollingerBands");

      return(INIT_FAILED);

     }

//----

   SecondRightTail=RightTail*PeriodSeconds(PERIOD_CURRENT);

//---- =8F80;870F8O AB@8=3>2

   upper_name=SirName+" upper text lable";

   middle_name=SirName+" middle text lable";

   lower_name=SirName+" lower text lable";

   UpBoxName=SirName+"_Up";

   DnBoxName=SirName+"_Dn";

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

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

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

   IndicatorSetString(INDICATOR_SHORTNAME,"BollingerBands_Box");

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

   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//----

   ObjectsDeleteAll(0,SirName,0,-1);

//----

   ChartRedraw(0);

  }

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

//| 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 @0AG5B0

   if(BarsCalculated(Ind_Handle)<Bars(Symbol(),Timeframe)) return(prev_calculated);

//----

   double Up[1],Md[1],Dn[1];

   int to_copy;



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

   ArraySetAsSeries(time,true);

//----

   to_copy=1;

//--- :>?8@C5< 2=>2L ?>O282H85AO 40==K5 2 <0AA82K

   if(CopyBuffer(Ind_Handle,UPPER_BAND,NumberofBar,1,Up)<=0) return(RESET);

   if(CopyBuffer(Ind_Handle,BASE_LINE,NumberofBar,1,Md)<=0) return(RESET);

   if(CopyBuffer(Ind_Handle,LOWER_BAND,NumberofBar,1,Dn)<=0) return(RESET);

//----

   datetime time0=time[0]+SecondRightTail;

   SetRectangle(0,UpBoxName,0,time[BarsTotal-1],Md[0],time0,Up[0],Color_Res,true,UpBoxName);

   SetRectangle(0,DnBoxName,0,time[BarsTotal-1],Md[0],time0,Dn[0],Color_Sup,true,DnBoxName);

//----

   if(ShowPrice)

     {

      SetRightPrice(0,upper_name,0,time0,Up[0],Upper_color);

      SetRightPrice(0,middle_name,0,time0,Md[0],Middle_color);

      SetRightPrice(0,lower_name,0,time0,Dn[0],Lower_color);

     }

//----

   ChartRedraw(0);

   return(rates_total);

  }

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

//|  !>740=85 ?@O<>C3>;L=>3> >1J5:B0                                 |

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

void CreateRectangle

(

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

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

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

 datetime time1,         // 2@5<O 1

 double   price1,        // F5=0 1

 datetime time2,         // 2@5<O 2

 double   price2,        // F5=0 2

 color    Color,         // F25B ;8=88

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

 string   text           // B5:AB

 )

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_RECTANGLE,nwin,time1,price1,time2,price2);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetInteger(chart_id,name,OBJPROP_FILL,true);

   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,background);

   ObjectSetString(chart_id,name,OBJPROP_TOOLTIP,"\n"); //70?@5B 2A?;K20NI59 ?>4A:07:8

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true); //>1J5:B =0 704=5< ?;0=5

//----

  }

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

//|  5@5CAB0=>2:0 ?@O<>C3>;L=>3> >1J5:B0                            |

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

void SetRectangle

(

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

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

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

 datetime time1,         // 2@5<O 1

 double   price1,        // F5=0 1

 datetime time2,         // 2@5<O 2

 double   price2,        // F5=0 2

 color    Color,         // F25B ;8=88

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

 string   text           // B5:AB

 )

//---- 

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateRectangle(chart_id,name,nwin,time1,price1,time2,price2,Color,background,text);

   else

     {

      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

      ObjectMove(chart_id,name,0,time1,price1);

      ObjectMove(chart_id,name,1,time2,price2);

     }

//----

  }

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

//|  RightPrice creation                                             |

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

void CreateRightPrice(long chart_id,// chart ID

                      string   name,              // object name

                      int      nwin,              // window index

                      datetime time,              // price level time

                      double   price,             // price level

                      color    Color              // Text color

                      )

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_ARROW_RIGHT_PRICE,nwin,time,price);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);

   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,2);

//----

  }

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

//|  RightPrice reinstallation                                       |

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

void SetRightPrice(long chart_id,// chart ID

                   string   name,              // object name

                   int      nwin,              // window index

                   datetime time,              // price level time

                   double   price,             // price level

                   color    Color              // Text color

                   )

//---- 

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateRightPrice(chart_id,name,nwin,time,price,Color);

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

//----

  }

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

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