EnvelopesATR_Cloud_v1

Author: Copyright © 2016, Tor
Indicators Used
Indicator of the average true range
0 Views
0 Downloads
0 Favorites
EnvelopesATR_Cloud_v1
ÿþ//+---------------------------------------------------------------------+

//|                                              EnvelopesATR_Cloud.mq5 | 

//|                                               Copyright © 2016, Tor | 

//|                                                http://einvestor.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, Tor"

#property link "http://einvestor.ru/"

#property description ">@01>B0==K9 AB0=40@B=K9 8=48:0B>@ >B:;>=5=8O F5=K Envelopes, ?>:07K20NI89 25@E=NN 8 =86=NN 3@0=8FC >B:;>=5=8O F5=K >B ,"

#property description "=> @0AAG8B0==K9 A CG5B>< A@54=59 2>;0B8;L=>AB8 A0<>3> 8=AB@C<5=B0 ?> 8=48:0B>@C ATR."

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

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

#property indicator_label1  "Upper EnvATR 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  "Env 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  clrHotPink

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

#property indicator_label4  "Lower EnvATR Cloud"

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

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

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

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

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

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

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

#include <SmoothAlgorithms.mqh> 

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

//---- >1JO2;5=85 ?5@5<5==KE :;0AA>2 CXMA 8 CStdDeviation 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 uint ATR_Period=14; //?5@8>4 ATR                   

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

input uint XLength=14; //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 Deviation1=0.1; //45280F8O

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 >;;8=465@0

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 EM=4;>2 8=48:0B>@>2

int ATR_Handle;

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

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

//| Custom indicator initialization function                         | 

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

int OnInit()

  {

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

   ATR_Handle=iATR(NULL,0,ATR_Period);

   if(ATR_Handle==INVALID_HANDLE)

     {

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

      return(INIT_FAILED);

     }

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



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

   upper_name1="EnvelopesATR_Cloud upper text lable 1";

   middle_name="EnvelopesATR_Cloud middle text lable";

   lower_name1="EnvelopesATR_Cloud lower text lable 1";

   upper_name2="EnvelopesATR_Cloud upper text lable 2";

   lower_name2="EnvelopesATR_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,"EnvelopesATR_Cloud(",Smooth,", ",XLength,", ",DoubleToString(Deviation1,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);

//----

  }

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

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

   if(BarsCalculated(ATR_Handle)<rates_total || rates_total<min_rates_total) return(RESET);



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

   double price,xma,ATR[1];

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

      if(CopyBuffer(ATR_Handle,0,rates_total-1-bar,1,ATR)<=0) return(RESET);

      //----

      ExtLineBuffer0[bar]=xma+dPriceShift;

      //----

      UpBuffer1[bar]=DnBuffer2[bar]=(1+Deviation1/100.0)*xma+dPriceShift;

      DnBuffer1[bar]=UpBuffer3[bar]=(1-Deviation1/100.0)*xma+dPriceShift;



      UpBuffer2[bar]=xma+ATR[0]+dPriceShift;

      DnBuffer3[bar]=xma-ATR[0]+dPriceShift;

     }     

     

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

//----

  }

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

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