FractalChannel_Cloud

Author: Copyright © 2005, TrendLaboratory Ltd.
0 Views
0 Downloads
0 Favorites
FractalChannel_Cloud
ÿþ//+------------------------------------------------------------------+ 

//|                                         FractalChannel_Cloud.mq5 | 

//|                           Copyright © 2005, TrendLaboratory Ltd. |

//|                                       E-mail: igorad2004@list.ru | 

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

#property copyright "Copyright © 2005, TrendLaboratory Ltd."

#property link      "E-mail: igorad2004@list.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 

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

#property indicator_buffers 7 

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

#property indicator_plots   5

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

//| 0@0<5B@K >B@8A>2:8 25@E=53> >1;0:0     |

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

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

#property indicator_type1   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= F25B C'232,255,247'

#property indicator_color1 C'232,255,247'

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

#property indicator_label1  "Upper FractalChannel cloud"

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

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

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

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

#property indicator_type2   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= F25B C'255,240,255'

#property indicator_color2 C'255,240,255'

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

#property indicator_label2  "Lower FractalChannel cloud"

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

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

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

//---- >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= 75;Q=K9 F25B

#property indicator_color3 clrSeaGreen

//---- ;8=8O 8=48:0B>@0 - HB@8E-?C=:B8@

#property indicator_style3  STYLE_DASHDOTDOT

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

#property indicator_width3  1

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

#property indicator_label3  "Upper FractalChannel"

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

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

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

//---- >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= A5@K9 F25B

#property indicator_color4 clrGray

//---- ;8=8O 8=48:0B>@0  - HB@8E-?C=:B8@

#property indicator_style4  STYLE_DASHDOTDOT

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

#property indicator_width4  1

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

#property indicator_label4  "Middle FractalChannel"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 3       |

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

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

#property indicator_type5   DRAW_LINE

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

#property indicator_color5 clrRed

//---- ;8=8O 8=48:0B>@0  - HB@8E-?C=:B8@

#property indicator_style5  STYLE_DASHDOTDOT

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

#property indicator_width5  1

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

#property indicator_label5  "Lower FractalChannel"

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

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

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

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

  {

   Type_1 = 1,     //Type_1

   Type_2,         //Type_2

   Type_3         //Type_3

  };

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

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

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

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

  {

   OpenClose,//OpenClose

   LowHigh   //LowHigh

  };

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

//|  %+  " + "            |

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

input Type       ChannelType=Type_1;

input double     Margins=0;

input double     Advance=0;

input PriceType  Prices=OpenClose;

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

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

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

double UpUpBuffer[],UpDnBuffer[],DnUpBuffer[],DnDnBuffer[];

double UpperBuffer[],MiddleBuffer[],LowerBuffer[];

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

int min_rates_total=7;

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

//| FractalChannel initialization function                           | 

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

void OnInit()

  {

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

   SetIndexBuffer(0,UpUpBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   //PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,NULL);

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

   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);

//---- 70?@5B =0 >B>1@065=85 7=0G5=89 8=48:0B>@0 2 ;52>< 25@E=5< C3;C >:=0 8=48:0B>@0

   PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(UpUpBuffer,true);

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

   SetIndexBuffer(1,UpDnBuffer,INDICATOR_DATA);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(UpDnBuffer,true);



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

   SetIndexBuffer(2,DnUpBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   //PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,NULL);

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

   PlotIndexSetInteger(1,PLOT_SHIFT,Shift);

//---- 70?@5B =0 >B>1@065=85 7=0G5=89 8=48:0B>@0 2 ;52>< 25@E=5< C3;C >:=0 8=48:0B>@0

   PlotIndexSetInteger(1,PLOT_SHOW_DATA,false);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(DnUpBuffer,true);

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

   SetIndexBuffer(3,DnDnBuffer,INDICATOR_DATA);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(DnDnBuffer,true);

   

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

   SetIndexBuffer(4,UpperBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(2,PLOT_SHIFT,Shift);

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

   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(UpperBuffer,true);



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

   SetIndexBuffer(5,MiddleBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(3,PLOT_SHIFT,Shift);

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

   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(MiddleBuffer,true);



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

   SetIndexBuffer(6,LowerBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(4,PLOT_SHIFT,Shift);

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

   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(LowerBuffer,true);



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

   string shortname;

   StringConcatenate(shortname,"FractalChannel_Cloud( ChannelType=",ChannelType,",Prices=",Prices,")");

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

  }

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

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



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

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);



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

   double smax,smin,Low0,Low1,Low2,Low3,Low4,Low5,Low6;

   double High0,High1,High2,High3,High4,High5,High6,v1,v2;

//---- 1JO2;5=85 F5;KE ?5@5<5==KE

   int limit,bar;

//---- 1JO2;5=85 AB0B8G5A:8E ?5@5<5==KE  

   static double smax_,smin_;



//---- @0AGQBK AB0@B>2>3> =><5@0 limit 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

     {

      limit=rates_total-min_rates_total; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2

      smax_ = 0;

      smin_ = 1000000000000;

     }

   else

     {

      limit=rates_total-prev_calculated; // AB0@B>2K9 =><5@ 4;O @0AGQB0 =>2KE 10@>2

     }

     

//---- 2>AAB0=02;8205< 7=0G5=8O ?5@5<5==KE

   smax = smax_;

   smin = smin_;



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

   for(bar=limit; bar>=0; bar--)

     {

      //---- 70?><8=05< 7=0G5=8O ?5@5<5==KE ?5@54 ?@>3>=0<8 =0 B5:CI5< 10@5

      if(rates_total!=prev_calculated && bar==rates_total-1)

        {

         smax_ = smax;

         smin_ = smin;

        }

      

      v1=-1;

      v2=-1;



      switch(Prices)

        {

         case  OpenClose:

            High0=high[bar+0];

            High1=high[bar+1];

            High2=high[bar+2];

            High3=high[bar+3];

            High4=high[bar+4];

            High5=high[bar+5];

            High6=high[bar+6];



            Low0=low[bar+0];

            Low1=low[bar+1];

            Low2=low[bar+2];

            Low3=low[bar+3];

            Low4=low[bar+4];

            Low5=low[bar+5];

            Low6=low[bar+6];

            break;



         case  LowHigh:

            High0=MathMax(close[bar+0],open[bar+1]);

            High1=MathMax(close[bar+1],open[bar+1]);

            High2=MathMax(close[bar+2],open[bar+2]);

            High3=MathMax(close[bar+3],open[bar+3]);

            High4=MathMax(close[bar+4],open[bar+4]);

            High5=MathMax(close[bar+5],open[bar+5]);

            High6=MathMax(close[bar+6],open[bar+6]);



            Low0=MathMin(close[bar+0],open[bar+1]);

            Low1=MathMin(close[bar+1],open[bar+1]);

            Low2=MathMin(close[bar+2],open[bar+2]);

            Low3=MathMin(close[bar+3],open[bar+3]);

            Low4=MathMin(close[bar+4],open[bar+4]);

            Low5=MathMin(close[bar+5],open[bar+5]);

            Low6=MathMin(close[bar+6],open[bar+6]);

            break;

            

          default:

            High0=high[bar+0];

            High1=high[bar+1];

            High2=high[bar+2];

            High3=high[bar+3];

            High4=high[bar+4];

            High5=high[bar+5];

            High6=high[bar+6];



            Low0=low[bar+0];

            Low1=low[bar+1];

            Low2=low[bar+2];

            Low3=low[bar+3];

            Low4=low[bar+4];

            Low5=low[bar+5];

            Low6=low[bar+6];

        }



      switch(ChannelType)

        {

         case  Type_1:

           {

            if(High2<=High1 && High0<High1) v1=High1;

            if(Low2 >= Low1 && Low0 > Low1) v2=Low1;

           }

         break;



         case  Type_2:

           {

            if(High4<=High2 && High3<=High2 && High0<High2 && High1<High2) v1=High2;

            if(Low4 >= Low2 && Low3 >= Low2 && Low0 > Low2 && Low1 > Low2) v2=Low2;

           }

         break;



         case  Type_3:

           {

            if(High6<=High3 && High5<=High3 && High4<=High3 && High0<High3 && High1<High3 && High2<High3) v1=High3;

            if(Low6 >= Low3 && Low5 >= Low3 && Low4 >= Low3 && Low0 > Low3 && Low1 > Low3 && Low2 > Low3) v2=Low3;

           }

         break;

         

         default:

           {

            if(High2<=High1 && High0<High1) v1=High1;

            if(Low2 >= Low1 && Low0 > Low1) v2=Low1;

           }

        }



      if(v1>0) smax=v1;

      if(High0>smax) smax=High0;



      if(v2>0) smin=v2;

      if(Low0<smin) smin=Low0;



      UpperBuffer[bar]=UpUpBuffer[bar]=smax-(smax-smin)*Margins;

      LowerBuffer[bar]=DnDnBuffer[bar]=smin+(smax-smin)*Margins;

      MiddleBuffer[bar]=UpDnBuffer[bar]=DnUpBuffer[bar]=(UpperBuffer[bar]+LowerBuffer[bar])/2;

     }

//----     

   return(rates_total);

  }

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

Comments