ColorKeltnerCandles

Author: Copyright © 2017, Nikolay Kositsin
0 Views
0 Downloads
0 Favorites
ColorKeltnerCandles
ÿþ//+---------------------------------------------------------------------+

//|                                             ColorKeltnerCandles.mq5 |

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

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

#property description "ColorKeltnerCandles"

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

#property version   "1.00"

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

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

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

//---- >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=> ?OBL 1CD5@>2

#property indicator_buffers 5

//---- 8A?>;L7>20=> 2A53> >4=> 3@0D8G5A:>5 ?>AB@>5=85

#property indicator_plots   1

//---- 2 :0G5AB25 8=48:0B>@0 8A?>;L7>20=K F25B=K5 A25G8

#property indicator_type1   DRAW_COLOR_CANDLES

//---- 2 :0G5AB25 F25B>2 A25G59 8A?>;L7>20=K

#property indicator_color1 clrMagenta,clrRed,clrOrangeRed,clrCrimson,clrBrown,CLR_NONE,clrSeaGreen,clrMediumSeaGreen,clrYellowGreen,clrLime,clrAqua

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

#property indicator_label1  "ColorKeltnerCandles 5AOBL F25B>2"



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

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

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

#include <SmoothAlgorithms.mqh> 

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



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

CMoving_Average MA;

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

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

  };

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

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

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

input int BandsPeriod=100; //?5@8>4 CA@54=5=8O



input double BandsDeviation1 = 1.0; //45280F8O ?5@2>3> C@>2=O

input double BandsDeviation2 = 1.5; //45280F8O 2B>@>3> C@>2=O

input double BandsDeviation3 = 2.0; //45280F8O B@5BL53> C@>2=O

input double BandsDeviation4 = 2.5; //45280F8O G5B2Q@B>3> C@>2=O

input double BandsDeviation5 = 3.0; //45280F8O ?OB>3> C@>2=O



input ENUM_MA_METHOD MA_Method_=MODE_EMA; //<5B>4 CA@54=5=8O 8=48:0B>@0

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

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



//---- >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 ExtOpenBuffer[];

double ExtHighBuffer[];

double ExtLowBuffer[];

double ExtCloseBuffer[];

double ExtColorsBuffer[];



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

int StartBars;

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

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

   StartBars=BandsPeriod+1;



//---- ?@52@0I5=85 48=0<8G5A:8E <0AA82>2 2 8=48:0B>@=K5 1CD5@K

   SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);

   SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);

//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 F25B>2>9, 8=45:A=K9 1CD5@   

   SetIndexBuffer(4,ExtColorsBuffer,INDICATOR_COLOR_INDEX);

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

   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,StartBars);

//--- CAB0=>2:0 :>;8G5AB20 F25B>2 11 4;O F25B>2>3> 1CD5@0

  // PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,11);

//---- #AB0=>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="ColorKeltnerCandles";

   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

//----   

  }

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

//| 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<StartBars) return(0);



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

   double price_,Keltner,ma;

   double UpKeltner1,UpKeltner2,UpKeltner3,UpKeltner4,UpKeltner5;

   double DnKeltner1,DnKeltner2,DnKeltner3,DnKeltner4,DnKeltner5;

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

   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 ?>;>A 5;B=5@0

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

     {

      //---- K7>2 DC=:F88 PriceSeries 4;O ?>;CG5=8O 2E>4=>9 F5=K price_

      price_=PriceSeries(IPC,bar,open,low,high,close);



      //---- K7>2 DC=:F88 MASeries 4;O ?>;CG5=8O 7=0G5=8O <C2<=30

      ma=MA.MASeries(0,prev_calculated,rates_total,BandsPeriod,MA_Method_,price_,bar,false);

      

      //---- K7>2 DC=:F88 GetKeltner 4;O ?>;CG5=8O 7=0G5=8O ?>;>28=K H8@8=K :0=0;0 5;B=5@0 A Deviation = 1.0 

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



      //---- >;CG5=85 7=0G5=89 C@>2=59

      UpKeltner1=ma+Keltner*BandsDeviation1;

      UpKeltner2=ma+Keltner*BandsDeviation2;

      UpKeltner3=ma+Keltner*BandsDeviation3;

      UpKeltner4=ma+Keltner*BandsDeviation4;

      UpKeltner5=ma+Keltner*BandsDeviation5;

      DnKeltner1=ma-Keltner*BandsDeviation1;

      DnKeltner2=ma-Keltner*BandsDeviation2;

      DnKeltner3=ma-Keltner*BandsDeviation3;

      DnKeltner4=ma-Keltner*BandsDeviation4;

      DnKeltner5=ma-Keltner*BandsDeviation5;



      if((price_>UpKeltner1||price_<DnKeltner1)&&bar>StartBars) //5ABL A83=0;K 4;O >:@0A:8 A25G59

        {

              if(price_>UpKeltner5) ExtColorsBuffer[bar]=10;

         else if(price_>UpKeltner4) ExtColorsBuffer[bar]=9;

         else if(price_>UpKeltner3) ExtColorsBuffer[bar]=8;

         else if(price_>UpKeltner2) ExtColorsBuffer[bar]=7;

         else if(price_>UpKeltner1) ExtColorsBuffer[bar]=6;



         else if(price_<DnKeltner5) ExtColorsBuffer[bar]=0;

         else if(price_<DnKeltner4) ExtColorsBuffer[bar]=1;

         else if(price_<DnKeltner3) ExtColorsBuffer[bar]=2;

         else if(price_<DnKeltner2) ExtColorsBuffer[bar]=3;

         else if(price_<DnKeltner1) ExtColorsBuffer[bar]=4;

         

         ExtOpenBuffer[bar]=open[bar];

         ExtHighBuffer[bar]=high[bar];

         ExtLowBuffer[bar]=low[bar];

         ExtCloseBuffer[bar]=close[bar];

        }

      else // A83=0;K 4;O >:@0A:8 A25G59 >BACBAB2CNB

        {

         ExtOpenBuffer[bar]=0.0;

         ExtHighBuffer[bar]=0.0;

         ExtLowBuffer[bar]=0.0;

         ExtCloseBuffer[bar]=0.0;

         ExtColorsBuffer[bar]=5;

        }

     }

//----     

   return(rates_total);

  }

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

// 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 keltner,sum=0;

   for(int iii=0; iii<period; iii++) sum +=High[MathMax(0,bar-iii)]-Low[MathMax(0,bar-iii)];

   keltner=sum/period;

//----

   return(keltner);

  }

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



   

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