AdaptiveRenko_Cld

Author: Copyright © 2010, Svinozavr
Indicators Used
Indicator of the average true rangeStandard Deviation indicator
0 Views
0 Downloads
0 Favorites
AdaptiveRenko_Cld
ÿþ//+------------------------------------------------------------------+

//|                                            AdaptiveRenko_Cld.mq5 |

//|                                    Copyright © 2010,   Svinozavr | 

//|                                                                  | 

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

#property copyright "Copyright © 2010,   Svinozavr"

#property link ""

#property description "40?B82=K9  5=:>"

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

#property version   "1.10"

//---- >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 8A?>;L7>20=> 8 1CD5@>2

#property indicator_buffers 8

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

#property indicator_plots   7

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

//|  0@0<5B@K >B@8A>2:8 >1;0:0 8=48:0B>@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 8=48:0B>@0 8A?>;L7>20= 240,240,251

#property indicator_color1  C'240,240,251'

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

#property indicator_label1  "AdaptiveRenko channel Cloud"

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

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

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

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

#property indicator_type2   DRAW_LINE

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

#property indicator_color2  clrDodgerBlue

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

#property indicator_style2 STYLE_DASHDOTDOT

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

#property indicator_width2  1

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

#property indicator_label2  "Lower AdaptiveRenko"

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

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

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

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

#property indicator_type3   DRAW_LINE

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

#property indicator_color3  clrMagenta

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

#property indicator_style3 STYLE_DASHDOTDOT

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

#property indicator_width3  1

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

#property indicator_label3 "Upper AdaptiveRenko"

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

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

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

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

#property indicator_type4   DRAW_LINE

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

#property indicator_color4  clrLime

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

#property indicator_style4 STYLE_SOLID

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

#property indicator_width4  2

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

#property indicator_label4  "AdaptiveRenko Support"

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

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

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

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

#property indicator_type5   DRAW_LINE

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

#property indicator_color5  clrRed

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

#property indicator_style5 STYLE_SOLID

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

#property indicator_width5  2

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

#property indicator_label5 "AdaptiveRenko Resistance"

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 6 2 2845 7=0G:0

#property indicator_type6   DRAW_ARROW

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

#property indicator_color6  clrLime

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

#property indicator_width6  2

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

#property indicator_label6  "AdaptiveRenko Support Arrow"

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 7 2 2845 7=0G:0

#property indicator_type7   DRAW_ARROW

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

#property indicator_color7  clrRed

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

#property indicator_width7  2

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

#property indicator_label7 "AdaptiveRenko Resistance Arrow"

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

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

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

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

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

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

  {

   ATR,     //ATR 8=48:0B>@

   StDev    //StDev 8=48:0B>@

  };

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

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

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

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

  {

   HighLow_, //High/Low

   Close_    //Close

  }; 

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

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

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

input double K=1.000001;                  //<=>68B5;L

input IndMode Indicator=ATR;              //8=48:0B>@ 4;O @0AGQB0

input uint VltPeriod=10;                  //?5@8>4 2>;0B8;L=>AB8

input PriceMode Price=Close_;             //A?>A>1 @0AGQB0 F5=K

input uint WideMin=2;                     //<8=8<0;L=0O B>;I8=0 :8@?8G0 2 ?C=:B0E

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

double sens;

//---- >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 DnBuffer[],UpBuffer[],DnClBuffer[],UpClBuffer[];

double UpTrendBuffer[],DnTrendBuffer[],UpTrendArBuffer[],DnTrendArBuffer[];

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

int  min_rates_total;

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

int Ind_Handle;

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

//---- =8F80;870F8O ?5@5<5==KE    

   min_rates_total=int(VltPeriod);

   sens=WideMin*_Point;



   if(Indicator==ATR) Ind_Handle=iATR(NULL,0,VltPeriod);

   else  Ind_Handle=iStdDev(NULL,0,VltPeriod,0,MODE_SMA,PRICE_CLOSE);

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

   

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

   SetIndexBuffer(0,UpClBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

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

   ArraySetAsSeries(UpClBuffer,true);

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



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

   SetIndexBuffer(1,DnClBuffer,INDICATOR_DATA);

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

   ArraySetAsSeries(DnClBuffer,true);



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

   SetIndexBuffer(2,UpBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

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

   ArraySetAsSeries(UpBuffer,true);

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



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

   SetIndexBuffer(3,DnBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);

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

   ArraySetAsSeries(DnBuffer,true);

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



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

   SetIndexBuffer(4,UpTrendBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);

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

   ArraySetAsSeries(UpTrendBuffer,true);

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



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

   SetIndexBuffer(5,DnTrendBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,min_rates_total);

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

   ArraySetAsSeries(DnTrendBuffer,true);

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

   

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

   SetIndexBuffer(6,UpTrendArBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(5,PLOT_DRAW_BEGIN,min_rates_total);

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

   ArraySetAsSeries(UpTrendArBuffer,true);

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

   PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,NULL);



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

   SetIndexBuffer(7,DnTrendArBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(6,PLOT_DRAW_BEGIN,min_rates_total);

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

   ArraySetAsSeries(DnTrendArBuffer,true);

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

   PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,NULL);



//---- CAB0=>2:0 D>@<0B0 B>G=>AB8 >B>1@065=8O 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//---- 8<O 4;O >:>= 40==KE 8 ;M910 4;O AC1J>:>= 

   string short_name="AdaptiveRenko_Cld("+DoubleToString(K,3)+","+EnumToString(Indicator)+","

                                    +string(VltPeriod)+","+EnumToString(Price)+","+string(WideMin)+")";

   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

//----   

  }

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

//| Custom indicator iteration function                              |

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

int OnCalculate

(const int rates_total,

const int prev_calculated,

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(BarsCalculated(Ind_Handle)<rates_total || rates_total<min_rates_total) return(RESET);



//---- >1JO2;5=8O ;>:0;L=KE ?5@5<5==KE 

   int to_copy,limit,bar,trend;

   double Hi,Lo,vlt,Brick,Up,Dn;

   double IndArray[];

   static double Brick_,Up_,Dn_;

   static int trend_;



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

   ArraySetAsSeries(High,true);

   ArraySetAsSeries(Low,true);

   ArraySetAsSeries(Close,true);

   ArraySetAsSeries(IndArray,true);



//---- @0AGQBK =5>1E>48<>3> :>;8G5AB20 :>?8@C5<KE 40==KE 8

//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-1; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2

      if(Price==Close_) {Hi=Close[limit]; Lo=Hi;}

      else {Hi=High[limit]; Lo=Low[limit];}

      Brick_=MathMax(K*(Hi-Lo),sens);

      Up_=Hi;

      Dn_=Lo;

      trend_=0;

     }

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

//----   

   to_copy=limit+1;



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

   if(CopyBuffer(Ind_Handle,0,0,to_copy,IndArray)<=0) return(RESET);

   

//---- 2>AB0=>2;5=85 7=0G5=89 ?5@5<5==KE

   Up=Up_;

   Dn=Dn_;

   Brick=Brick_;

   trend=trend_;



//---- ?5@2K9 F8:; @0AGQB0 8=48:0B>@0

   for(bar=limit; bar>=0 && !IsStopped(); bar--)

     {

      if(Price==Close_) {Hi=Close[bar]; Lo=Hi;}

      else {Hi=High[bar]; Lo=Low[bar];}



      vlt=MathMax(K*IndArray[bar],sens);



      if(Hi>Up+Brick)

        {

         if(Brick) Up+=MathFloor((Hi-Up)/Brick)*Brick;

         Brick=vlt;

         Dn=Up-Brick;

        }



      if(Lo<Dn-Brick)

        {

         if(Brick) Dn-=MathFloor((Dn-Lo)/Brick)*Brick;

         Brick=vlt;

         Up=Dn+Brick;

        }



      UpBuffer[bar]=UpClBuffer[bar]=Up;

      DnBuffer[bar]=DnClBuffer[bar]=Dn;

      UpTrendBuffer[bar]=DnTrendBuffer[bar]=UpTrendArBuffer[bar]=DnTrendArBuffer[bar]=NULL;



      if(UpBuffer[bar+1]<Up) trend=+1;

      if(DnBuffer[bar+1]>Dn) trend=-1;



      if(trend>0) UpTrendArBuffer[bar]=UpTrendBuffer[bar]=Dn-Brick;

      if(trend<0) DnTrendArBuffer[bar]=DnTrendBuffer[bar]=Up+Brick;



      //---- A>E@0=5=85 7=0G5=89 ?5@5<5==KE ?5@54 <=>3>:@0B=K< ?@>3>=>< =0 B5:CI5< 10@5

      if(bar)

        {

         Up_=Up;

         Dn_=Dn;

         Brick_=Brick;

         trend_=trend;

        }

     }

//----     

   return(rates_total);

  }

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



    

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