/* * Place the SmoothAlgorithms.mqh file * to the terminal_data_folder\MQL5\Include */ //+------------------------------------------------------------------+ //| X2MA_KLx9.mq5 | //| Copyright 2011, Nikolay Kositsin | //| Khabarovsk, farria@mail.redcom.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, Nikolay Kositsin" #property link "farria@mail.redcom.ru" #property description "X2MA Keltner Channel" //---- indicator version #property version "1.00" //---- drawing the indicator in the main window #property indicator_chart_window //---- number of indicator buffers 9 #property indicator_buffers 9 //---- 9 graphical plots are used in total #property indicator_plots 9 //+-----------------------------------+ //| Indicator drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a line #property indicator_type1 DRAW_LINE //---- use blue violet color for the indicator line #property indicator_color1 BlueViolet //---- the indicator line is a dash-dotted curve #property indicator_style1 STYLE_DASHDOTDOT //---- indicator line width is equal to 1 #property indicator_width1 1 //---- displaying a label of the indicator #property indicator_label1 "X2MA" //+--------------------------------------------+ //| Levels indicator drawing parameters | //+--------------------------------------------+ //---- drawing Keltner Channels as lines #property indicator_type2 DRAW_LINE #property indicator_type3 DRAW_LINE #property indicator_type4 DRAW_LINE #property indicator_type5 DRAW_LINE #property indicator_type6 DRAW_LINE #property indicator_type7 DRAW_LINE #property indicator_type8 DRAW_LINE #property indicator_type9 DRAW_LINE //---- selection of Keltner Channels colors #property indicator_color2 DarkSlateGray #property indicator_color3 Purple #property indicator_color4 Red #property indicator_color5 Blue #property indicator_color6 Blue #property indicator_color7 Red #property indicator_color8 Purple #property indicator_color9 DarkSlateGray //---- Keltner Channels are dott-dash curves #property indicator_style2 STYLE_DASHDOTDOT #property indicator_style3 STYLE_DASHDOTDOT #property indicator_style4 STYLE_DASHDOTDOT #property indicator_style5 STYLE_DASHDOTDOT #property indicator_style6 STYLE_DASHDOTDOT #property indicator_style7 STYLE_DASHDOTDOT #property indicator_style8 STYLE_DASHDOTDOT #property indicator_style9 STYLE_DASHDOTDOT //---- Keltner Channels width is equal to 1 #property indicator_width2 1 #property indicator_width3 1 #property indicator_width4 1 #property indicator_width5 1 #property indicator_width6 1 #property indicator_width7 1 #property indicator_width8 1 #property indicator_width9 1 //---- display of Keltner Channels labels #property indicator_label2 "+4Sigma" #property indicator_label3 "+3Sigma" #property indicator_label4 "+2Sigma" #property indicator_label5 "+1Sigma" #property indicator_label6 "-1Sigma" #property indicator_label7 "-2Sigma" #property indicator_label8 "-3Sigma" #property indicator_label9 "-4Sigma" //+-----------------------------------+ //| Smoothings classes description | //+-----------------------------------+ #include //+-----------------------------------+ //---- declaration of variables of the CXMA and CStdDeviation classes //---- from the SmoothAlgorithms.mqh file CXMA XMA1,XMA2; CStdDeviation STD; //+-----------------------------------+ //| enumerations declaration | //+-----------------------------------+ enum Applied_price_ // Type of constant { 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_SIMPLE, // Simple Price (OC/2) PRICE_QUARTER_, // Quarted Price (HLOC/4) PRICE_TRENDFOLLOW0_, // TrendFollow_1 Price PRICE_TRENDFOLLOW1_ // TrendFollow_2 Price }; /*enum Smooth_Method - enumeration is declared in the SmoothAlgorithms.mqh file { 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 }; */ //+-----------------------------------+ //| Indicator input parameters | //+-----------------------------------+ input Smooth_Method MA_Method1=MODE_SMA; // First smoothing method input int Length1=40; // First smoothing depth input int Phase1=15; // First smoothing parameter // for JJMA that can change withing the range -100 ... +100. It impacts the quality of the intermediate process of smoothing; // for VIDIA it is a CMO period, for AMA it is a slow average period input Smooth_Method MA_Method2=MODE_JJMA; // Second smoothing method input int Length2=20; // Second smoothing depth input int Phase2=100; // Second smoothing parameter // for JJMA that can change withing the range -100 ... +100. It impacts the quality of the intermediate process of smoothing; // for VIDIA it is a CMO period, for AMA it is a slow average period input int KeltnerPeriod=20; // Keltner smoothing period input double Ratio1 = 1.0; // First level ratio input double Ratio2 = 2.0; // Second level ratio input double Ratio3 = 3.0; // Third level ratio input double Ratio4 = 4.0; // Fourth level ratio input Applied_price_ IPC=PRICE_CLOSE; // Price constant /* , used for the indicator calculation (1-CLOSE, 2-OPEN, 3-HIGH, 4-LOW, 5-MEDIAN, 6-TYPICAL, 7-WEIGHTED, 8-SIMPLE, 9-QUARTER, 10-TRENDFOLLOW, 11-0.5 * TRENDFOLLOW.) */ input int Shift=0; // Horizontal shift of the indicator in bars input int PriceShift=0; // Vertical shift of the indicator in points //+-----------------------------------+ //---- declaration of a dynamic array that //---- will be used as an indicator buffer double X2MA[]; //---- declaration of dynamic arrays that // will be used as Keltner Channels indicator buffers double ExtLineBuffer1[],ExtLineBuffer2[],ExtLineBuffer3[],ExtLineBuffer4[]; double ExtLineBuffer5[],ExtLineBuffer6[],ExtLineBuffer7[],ExtLineBuffer8[]; //---- declaration of the average vertical shift value variable double dPriceShift; //---- declaration of the integer variables for the start of data calculation int StartBars,StartBars1,StartBars2; //+------------------------------------------------------------------+ //| calculation of the half of the Keltner Channel width | //+------------------------------------------------------------------+ double GetKeltner(int period,int bar,const double &High[],const double &Low[]) { //---- double Resalt,sum=0; for(int iii=0; iiirates_total || prev_calculated<=0) // checking for the first start of the indicator calculation { first1=0; // starting index for calculation of all bars for the average first2=StartBars; // starting index for calculation of all bars for the average } else { first1=prev_calculated-1; // starting index for calculation of the new bars for the average first2=first1; // starting index for calculation of the new bars for the channel } //---- main indicator calculation loop for(bar=first1; bar