XMA_KLx5_Cloud

Author: Copyright © 2016, Nikolay Kositsin
1 Views
0 Downloads
0 Favorites
XMA_KLx5_Cloud
ÿþ//+---------------------------------------------------------------------+

//|                                                  XMA_KLx5_Cloud.mq5 | 

//|                                  Copyright © 2016, 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 © 2016, Nikolay Kositsin"

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

#property description "20 :0=0;0 5;B=5@0, ?>AB@>5==K5 =0 >4=>< A:>;L7OI5< A@54=5<, 2 F25B=>< >1;0G=>< 2845 A >B>1@065=85< ?>A;54=8E 7=0G5=89 2 2845 F5=>2KE <5B>:"

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

#property version   "1.01"

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

#property indicator_chart_window 

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

#property indicator_buffers 7 

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

#property indicator_plots   4

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

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

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

#property indicator_label1  "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_type2   DRAW_FILLING

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

#property indicator_color2  clrLavender

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

#property indicator_label2  "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_type3   DRAW_LINE

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

#property indicator_color3 clrBlueViolet

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

#property indicator_style3  STYLE_SOLID

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

#property indicator_width3  2

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

#property indicator_label3  "XMA"

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

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

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

#property indicator_color4  clrTomato

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

#property indicator_label4  "Lower Sigma2 Cloud"

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

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

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

#include <SmoothAlgorithms.mqh> 

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

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

CXMA XMA1;

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

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

  };

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

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

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

/*enum Smooth_Method - ?5@5G8A;5=85 >1JO2;5=> 2 D09;5 SmoothAlgorithms.mqh

  {

   MODE_SMA_,  //SMA

   MODE_EMA_,  //EMA

   MODE_SMMA_, //SMMA

   MODE_LWMA_, //LWMA

   MODE_JJMA,  //JJMA

   MODE_JurX,  //JurX

   MODE_ParMA, //ParMA

   MODE_T3,    //T3

   MODE_VIDYA, //VIDYA

   MODE_AMA,   //AMA

  }; */

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

//|  %+  " + "               |

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

input Smooth_Method XMA_Method=MODE_SMA_; //<5B>4 CA@54=5=8O

input uint XLength=100; //3;C18=0  CA@54=5=8O                    

input int XPhase=15; //?0@0<5B@ ?5@2>3> CA@54=5=8O,

//---- 4;O JJMA 87<5=ONI89AO 2 ?@545;0E -100 ... +100, 2;8O5B =0 :0G5AB2> ?5@5E>4=>3> ?@>F5AA0;

//---- ;O VIDIA MB> ?5@8>4 CMO, 4;O AMA MB> ?5@8>4 <54;5==>9 A:>;L7OI59

input double Ratio1 = 1.0; //:>MDD8F85=B ?5@2>3> C@>2=O

input double Ratio2 = 2.0; //:>MDD8F85=B 2B>@>3> C@>2=O

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

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

input color  Middle_color=clrBlue;

input color  Upper_color1=clrMediumSeaGreen;

input color  Lower_color1=clrRed;

input color  Upper_color2=clrDodgerBlue;

input color  Lower_color2=clrMagenta;

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

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

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

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

double dPriceShift;

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

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

//| X2MA KLx5 indicator initialization function                      | 

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

int OnInit()

  {

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

   min_rates_1=GetStartBars(XMA_Method,XLength,XPhase)+1;

   min_rates_total=min_rates_1+int(XLength);

//---- CAB0=>2:0 0;5@B>2 =0 =54>?CAB8<K5 7=0G5=8O 2=5H=8E ?5@5<5==KE

   XMA1.XMALengthCheck("XLength",XLength);

//---- CAB0=>2:0 0;5@B>2 =0 =54>?CAB8<K5 7=0G5=8O 2=5H=8E ?5@5<5==KE

   XMA1.XMAPhaseCheck("XPhase",XPhase,XMA_Method);

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

   dPriceShift=_Point*PriceShift;

   if(Ratio1>=Ratio2)

     {

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

      return(INIT_FAILED);

     }



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

   upper_name1="XMA_KLx5_Cloud upper text lable 1";

   middle_name="XMA_KLx5_Cloud middle text lable";

   lower_name1="XMA_KLx5_Cloud lower text lable 1";

   upper_name2="XMA_KLx5_Cloud upper text lable 2";

   lower_name2="XMA_KLx5_Cloud lower text lable 2";



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

   SetIndexBuffer(0,UpBuffer2,INDICATOR_DATA);

   SetIndexBuffer(1,DnBuffer2,INDICATOR_DATA);

   SetIndexBuffer(2,UpBuffer1,INDICATOR_DATA);

   SetIndexBuffer(3,DnBuffer1,INDICATOR_DATA);

   SetIndexBuffer(4,ExtLineBuffer0,INDICATOR_DATA);

   SetIndexBuffer(5,UpBuffer3,INDICATOR_DATA);

   SetIndexBuffer(6,DnBuffer3,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);

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



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

   string shortname;

   string Smooth=XMA1.GetString_MA_Method(XMA_Method);

   StringConcatenate(shortname,"XMA_Bollinger Bands(",Smooth,", ",XLength,", ",DoubleToString(Ratio1,2),", ",DoubleToString(Ratio2,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);

//----

  }

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

//| X2MA KLx5 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 price,xma,line,Keltner,Keltner1,Keltner2;

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

   int first,bar;



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

   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=PriceSeries(IPC,bar,open,low,high,close);

      xma=XMA1.XMASeries(0,prev_calculated,rates_total,XMA_Method,XPhase,XLength,price,bar,false);

      line=xma+dPriceShift;

      ExtLineBuffer0[bar]=xma+dPriceShift;

      Keltner=GetKeltner(XLength,bar,high,low);

      Keltner1=Ratio1*Keltner;

      UpBuffer1[bar]=DnBuffer2[bar]=line+Keltner1;

      DnBuffer1[bar]=UpBuffer3[bar]=line-Keltner1;

      Keltner2=Ratio2*Keltner;

      UpBuffer2[bar]=line+Keltner2;

      DnBuffer3[bar]=line-Keltner2;

     }

   int bar0=rates_total-1;

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

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

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

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

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

//----     

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

//----

  }

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

// 2KG8A;5=85 ?>;>28=K H8@8=K :0=0;0 5;B=5@0                        |

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

double GetKeltner(int period,int bar,const double &High[],const double &Low[])

  {

//----

   double Resalt,sum=0;

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

     {

      int index=MathMax(0,bar-iii);

      sum+=High[index]-Low[index];

     }

   Resalt=sum/period;

   return(Resalt);

//----

  }

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

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