AbsolutelyNoLagLwma_BBx7_Cloud_Digit

Author: Copyright © 2018, Nikolay Kositsin
2 Views
0 Downloads
0 Favorites
AbsolutelyNoLagLwma_BBx7_Cloud_Digit
ÿþ//+---------------------------------------------------------------------+

//|                            AbsolutelyNoLagLwma_BBx7_Cloud_Digit.mq5 | 

//|                                  Copyright © 2018, Nikolay Kositsin | 

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

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

//| ;O @01>BK  8=48:0B>@0  A;54C5B  ?>;>68BL D09; SmoothAlgorithms.mqh |

//| 2 ?0?:C (48@5:B>@8N): :0B0;>3_40==KE_B5@<8=0;0\\MQL5\Include        |

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

#property copyright "Copyright © 2018, Nikolay Kositsin"

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

#property description "AbsolutelyNoLagLwma Bollinger Bands"

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

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

#property indicator_buffers 11 

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

#property indicator_plots   6

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

//|  0@0<5B@K >B@8A>2:8 >1;0:0                  |

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

//---- >B@8A>2:0 8=48:0B>@0 2 2845 F25B=>3> >1;0:0

#property indicator_type1   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 >1;0:0 8A?>;L7>20=

#property indicator_color1  clrDeepSkyBlue

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label1  "Upper Sigma3 Cloud"

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

//|  0@0<5B@K >B@8A>2:8 >1;0:0                  |

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

//---- >B@8A>2:0 8=48:0B>@0 2 2845 F25B=>3> >1;0:0

#property indicator_type2   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 >1;0:0 8A?>;L7>20=

#property indicator_color2  clrLime

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label2  "Upper Sigma2 Cloud"

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

//|  0@0<5B@K >B@8A>2:8 >1;0:0                  |

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

//---- >B@8A>2:0 8=48:0B>@0 2 2845 F25B=>3> >1;0:0

#property indicator_type3   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 >1;0:0 8A?>;L7>20=

#property indicator_color3  clrLavender

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label3  "Sigma1 Cloud"

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

//|  0@0<5B@K >B@8A>2:8 <C28=30                 |

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

//---- >B@8A>2:0 8=48:0B>@0 2 2845 ;8=88

#property indicator_type4   DRAW_LINE

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= A8=5-D8>;5B>2K9 F25B

#property indicator_color4 clrBlueViolet

//---- ;8=8O 8=48:0B>@0 - A?;>H=0O

#property indicator_style4  STYLE_SOLID

//---- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 2

#property indicator_width4  2

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label4  "AbsolutelyNoLagLwma"

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

//|  0@0<5B@K >B@8A>2:8 >1;0:0                  |

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

//---- >B@8A>2:0 8=48:0B>@0 2 2845 F25B=>3> >1;0:0

#property indicator_type5   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 >1;0:0 8A?>;L7>20=

#property indicator_color5  clrMagenta

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label5  "Lower Sigma2 Cloud"

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

//|  0@0<5B@K >B@8A>2:8 >1;0:0                  |

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

//---- >B@8A>2:0 8=48:0B>@0 2 2845 F25B=>3> >1;0:0

#property indicator_type6   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 >1;0:0 8A?>;L7>20=

#property indicator_color6  clrMediumOrchid

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label6  "Lower Sigma3 Cloud"

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

//|  ?8A0=85 :;0AA>2 CA@54=5=89               |

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

#include <SmoothAlgorithms.mqh> 

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

//---- >1JO2;5=85 ?5@5<5==KE :;0AA0 CStdDeviation 87 D09;0 SmoothAlgorithms.mqh

CStdDeviation STD1,STD2,STD3;

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

//|  >1JO2;5=85 ?5@5G8A;5=89                   |

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

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

  {

   PRICE_CLOSE_ = 1,     //Close

   PRICE_OPEN_,          //Open

   PRICE_HIGH_,          //High

   PRICE_LOW_,           //Low

   PRICE_MEDIAN_,        //Median Price (HL/2)

   PRICE_TYPICAL_,       //Typical Price (HLC/3)

   PRICE_WEIGHTED_,      //Weighted Close (HLCC/4)

   PRICE_SIMPL_,         //Simpl Price (OC/2)

   PRICE_QUARTER_,       //Quarted Price (HLOC/4) 

   PRICE_TRENDFOLLOW0_,  //TrendFollow_1 Price 

   PRICE_TRENDFOLLOW1_,  //TrendFollow_2 Price

   PRICE_DEMARK_         //Demark Price 

  };

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

//|  %+  " + "               |

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

input uint LLength=7; //3;C18=0  CA@54=5=8O                    

input double BandsDeviation1=2.0; //45280F8O 1

input double BandsDeviation2=3.0; //45280F8O 2

input double BandsDeviation3=4.0; //45280F8O 3

input uint Digit=2; //:>;8G5AB2> @07@O4>2 >:@C3;5=8O

input Applied_price_ IPC=PRICE_CLOSE_;//F5=>20O :>=AB0=B0

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

input int PriceShift=0; // c4283 8=48:0B>@0 ?> 25@B8:0;8 2 ?C=:B0E

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

//---- F25B0 F5=>2KE <5B>:

input color  Upper_color3=clrBlue;

input color  Upper_color2=clrDodgerBlue;

input color  Upper_color1=clrMediumSeaGreen;

input color  Middle_color=clrDarkGray;

input color  Lower_color1=clrRed;

input color  Lower_color2=clrMagenta;

input color  Lower_color3=clrOrange;

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

//---- >1JO2;5=85 48=0<8G5A:>3> <0AA820, :>B>@K9 1C45B 2 

// 40;L=59H5< 8A?>;L7>20= 2 :0G5AB25 8=48:0B>@=>3> 1CD5@0

double ExtLineBuffer0[];

//---- >1JO2;5=85 48=0<8G5A:8E <0AA82>2, :>B>@K5 1C4CB 2 

// 40;L=59H5< 8A?>;L7>20=K 2 :0G5AB25 8=48:0B>@=KE 1CD5@>2 C@>2=59 >;;8=465@0

double UpBuffer1[],DnBuffer1[],UpBuffer2[],DnBuffer2[],UpBuffer3[],DnBuffer3[];

double UpBuffer4[],DnBuffer4[],UpBuffer5[],DnBuffer5[];

//---- 1JO2;5=85 ?5@5<5==>9 7=0G5=8O 25@B8:0;L=>3> A42830 <C28=30

double dPriceShift,PointPow10;

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

int min_rates_total,min_rates_1;

//---- 1JO2;5=85 AB@8=3>2 4;O B5:AB>2KE <5B>:

string upper_name1,middle_name,lower_name1,upper_name2,lower_name2,upper_name3,lower_name3;

//---- >1JO2;5=85 3;>10;L=KE ?5@5<5==KE

int Count[];

double Price[],Lwma[];

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

//|  5@5AG5B ?>78F88 A0<>3> =>2>3> M;5<5=B0 2 <0AA825               |

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

void Recount_ArrayZeroPos(int &CoArr[],// >72@0B ?> AAK;:5 =><5@0 B5:CI53> 7=0G5=8O F5=>2>3> @O40

                          int Size)

  {

//----

   int numb,Max1,Max2;

   static int count=1;



   Max2=Size;

   Max1=Max2-1;



   count--;

   if(count<0) count=Max1;



   for(int iii=0; iii<Max2; iii++)

     {

      numb=iii+count;

      if(numb>Max1) numb-=Max2;

      CoArr[iii]=numb;

     }

//----

  }

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

//| Custom indicator initialization function                         | 

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

int OnInit()

  {

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

   min_rates_1=int(LLength*2.0);

   min_rates_total=min_rates_1+int(LLength);

   PointPow10=_Point*MathPow(10,Digit);

//---- =8F80;870F8O A42830 ?> 25@B8:0;8

   dPriceShift=_Point*PriceShift;

   if(BandsDeviation1>=BandsDeviation2)

     {

      Print("E>4=>9 ?0@0<5B@ 5280F8O 2 2A5340 4>;65= 1KBL 1>;LH5 2E>4=>3> ?0@0<5B@0 5280F8O 1! A?@02LB5 7=0G5=8O MB8E 2E>4=KE ?0@0<5B@>2 8=48:0B>@0!");

      return(INIT_FAILED);

     }

   if(BandsDeviation2>=BandsDeviation3)

     {

      Print("E>4=>9 ?0@0<5B@ 5280F8O 3 2A5340 4>;65= 1KBL 1>;LH5 2E>4=>3> ?0@0<5B@0 5280F8O 2! A?@02LB5 7=0G5=8O MB8E 2E>4=KE ?0@0<5B@>2 8=48:0B>@0!");

      return(INIT_FAILED);

     }

//---- @0A?@545;5=85 ?0<OB8 ?>4 <0AA82K ?5@5<5==KE  

   ArrayResize(Count,LLength);

   ArrayResize(Price,LLength);

   ArrayResize(Lwma,LLength);



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

   upper_name1="AbsolutelyNoLagLwma_BBx7_Cloud_Digit upper text lable 1";

   middle_name="AbsolutelyNoLagLwma_BBx7_Cloud_Digit middle text lable";

   lower_name1="AbsolutelyNoLagLwma_BBx7_Cloud_Digit lower text lable 1";

   upper_name2="AbsolutelyNoLagLwma_BBx7_Cloud_Digit upper text lable 2";

   lower_name2="AbsolutelyNoLagLwma_BBx7_Cloud_Digit lower text lable 2";

   upper_name3="AbsolutelyNoLagLwma_BBx7_Cloud_Digit upper text lable 3";

   lower_name3="AbsolutelyNoLagLwma_BBx7_Cloud_Digit lower text lable 3";



//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(0,UpBuffer4,INDICATOR_DATA);

   SetIndexBuffer(1,DnBuffer4,INDICATOR_DATA);

   SetIndexBuffer(2,UpBuffer2,INDICATOR_DATA);

   SetIndexBuffer(3,DnBuffer2,INDICATOR_DATA);

   SetIndexBuffer(4,UpBuffer1,INDICATOR_DATA);

   SetIndexBuffer(5,DnBuffer1,INDICATOR_DATA);

   SetIndexBuffer(6,ExtLineBuffer0,INDICATOR_DATA);

   SetIndexBuffer(7,UpBuffer3,INDICATOR_DATA);

   SetIndexBuffer(8,DnBuffer3,INDICATOR_DATA);

   SetIndexBuffer(9,UpBuffer5,INDICATOR_DATA);

   SetIndexBuffer(10,DnBuffer5,INDICATOR_DATA);

//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 ?> 3>@87>=B0;8

   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);

   PlotIndexSetInteger(1,PLOT_SHIFT,Shift);

   PlotIndexSetInteger(2,PLOT_SHIFT,Shift);

   PlotIndexSetInteger(3,PLOT_SHIFT,Shift);

   PlotIndexSetInteger(4,PLOT_SHIFT,Shift);

   PlotIndexSetInteger(5,PLOT_SHIFT,Shift);

//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAGQB0 >B@8A>2:8 8=48:0B>@0

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,min_rates_total);



//---- 8=8F80;870F88 ?5@5<5==>9 4;O :>@>B:>3> 8<5=8 8=48:0B>@0

   string shortname;

   StringConcatenate(shortname,"AbsolutelyNoLagLwma_BBx7_Cloud_Digit(",LLength,", ",

                     DoubleToString(BandsDeviation1,2),", ",DoubleToString(BandsDeviation2,2),", ",DoubleToString(BandsDeviation3,2),")");

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

   IndicatorSetString(INDICATOR_SHORTNAME,shortname);



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

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);

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

   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//----

   ObjectDelete(0,upper_name1);

   ObjectDelete(0,middle_name);

   ObjectDelete(0,lower_name1);

   ObjectDelete(0,upper_name2);

   ObjectDelete(0,lower_name2);

   ObjectDelete(0,upper_name3);

   ObjectDelete(0,lower_name3);

//----

   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[],

                const double &low[],

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



//---- 1JO2;5=85 ?5@5<5==KE A ?;020NI59 B>G:>9  

   double line,stdev;

      double sum,sumw,lwma2;



//---- 1JO2;5=85 F5;KE ?5@5<5==KE 8 ?>;CG5=85 C65 ?>AG8B0==KE 10@>2

   int first,bar,weight;



//---- @0AGQB AB0@B>2>3> =><5@0 first 4;O F8:;0 ?5@5AGQB0 10@>2

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

     {

      first=0; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2

      ArrayInitialize(Count,0);

      ArrayInitialize(Price,0.0);

      ArrayInitialize(Lwma,0.0);

     }

   else first=prev_calculated-1; // AB0@B>2K9 =><5@ 4;O @0AGQB0 =>2KE 10@>2



//---- A=>2=>9 F8:; @0AGQB0 8=48:0B>@0

   for(bar=first; bar<rates_total && !IsStopped(); bar++)

     {

      Price[Count[0]]=PriceSeries(IPC,bar,open,low,high,close);

      //----

      sum=0;

      sumw=0;

      for(int kkk=0; kkk<int(LLength); kkk++) { weight=int(LLength)-kkk; sumw+=weight; sum+=weight*Price[Count[kkk]]; }

      if(sumw) Lwma[Count[0]]=sum/sumw;

      else  Lwma[Count[0]]=NULL;

      //----

      sum=0;

      sumw=0;

      for(int kkk=0; kkk<int(LLength); kkk++) { weight=int(LLength)-kkk; sumw+=weight; sum+=weight*Lwma[Count[kkk]]; }

      if(sumw) lwma2=sum/sumw;

      else  lwma2=NULL;

      //----

      line=lwma2+dPriceShift;

      ExtLineBuffer0[bar]=PointPow10*MathRound(line/PointPow10);

      //---- @0AGQB 8 >:@C3;5=85 >;;8=465@0 1

      stdev=STD1.StdDevSeries(min_rates_1,prev_calculated,rates_total,LLength,BandsDeviation1,Price[Count[0]],lwma2,bar,false);

      UpBuffer1[bar]=DnBuffer2[bar]=PointPow10*MathCeil((line+stdev)/PointPow10);

      DnBuffer1[bar]=UpBuffer3[bar]=PointPow10*MathFloor((line-stdev)/PointPow10);

      //---- 8A?@02;5=85 >;;8=465@0 1

      if(ExtLineBuffer0[bar]>=UpBuffer1[bar]) UpBuffer1[bar]=DnBuffer2[bar]=ExtLineBuffer0[bar]+PointPow10;

      if(ExtLineBuffer0[bar]<=DnBuffer1[bar]) DnBuffer1[bar]=UpBuffer3[bar]=ExtLineBuffer0[bar]-PointPow10;

      //---- @0AGQB 8 >:@C3;5=85 >;;8=465@0 2

      stdev=STD2.StdDevSeries(min_rates_1,prev_calculated,rates_total,LLength,BandsDeviation2,Price[Count[0]],lwma2,bar,false);

      UpBuffer2[bar]=DnBuffer4[bar]=PointPow10*MathCeil((line+stdev)/PointPow10);

      DnBuffer3[bar]=UpBuffer5[bar]=PointPow10*MathFloor((line-stdev)/PointPow10);

      //---- 8A?@02;5=85 >;;8=465@0 2

      if(UpBuffer1[bar]>=UpBuffer2[bar]) UpBuffer2[bar]=DnBuffer4[bar]=UpBuffer1[bar]+PointPow10;

      if(DnBuffer1[bar]<=DnBuffer3[bar]) DnBuffer3[bar]=UpBuffer5[bar]=DnBuffer1[bar]-PointPow10;

      //---- @0AGQB 8 >:@C3;5=85 >;;8=465@0 3        

      stdev=STD3.StdDevSeries(min_rates_1,prev_calculated,rates_total,LLength,BandsDeviation3,Price[Count[0]],lwma2,bar,false);

      UpBuffer4[bar]=PointPow10*MathCeil((line+stdev)/PointPow10);

      DnBuffer5[bar]=PointPow10*MathFloor((line-stdev)/PointPow10);

      //---- 8A?@02;5=85 >;;8=465@0 3

      if(UpBuffer2[bar]>=UpBuffer4[bar]) UpBuffer4[bar]=UpBuffer2[bar]+PointPow10;

      if(DnBuffer3[bar]<=DnBuffer5[bar]) DnBuffer5[bar]=DnBuffer3[bar]-PointPow10;

      if(bar<rates_total-1) Recount_ArrayZeroPos(Count,LLength);

     }

   if(ShowPrice)

     {

      int bar0=rates_total-1;

      datetime time0=time[bar0]+Shift*PeriodSeconds();

      SetRightPrice(0,middle_name,0,time0,ExtLineBuffer0[bar0],Middle_color,"Georgia");

      SetRightPrice(0,upper_name1,0,time0,UpBuffer1[bar0],Upper_color1,"Georgia");

      SetRightPrice(0,lower_name1,0,time0,DnBuffer1[bar0],Lower_color1,"Georgia");

      SetRightPrice(0,upper_name2,0,time0,UpBuffer2[bar0],Upper_color2,"Georgia");

      SetRightPrice(0,lower_name2,0,time0,DnBuffer3[bar0],Lower_color2,"Georgia");

      SetRightPrice(0,upper_name3,0,time0,UpBuffer4[bar0],Upper_color3,"Georgia");

      SetRightPrice(0,lower_name3,0,time0,DnBuffer5[bar0],Lower_color3,"Georgia");

     }

//----     

   ChartRedraw(0);

   return(rates_total);

  }

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

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

                      string   Font               // Text font

                      )

//---- 

  {

//----

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

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetString(chart_id,name,OBJPROP_FONT,Font);

   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

                   string   Font               // Text font

                   )

//---- 

  {

//----

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

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