//+------------------------------------------------------------------+ //| KGHP.mq5 | //| Copyright 2006, Newdigital | //| http://www.forex-tsd.com/ | //+------------------------------------------------------------------+ //+------------------------------------------------------------------------+ //| I wanted to create the KGHP digital filter and was failed. | //| But when I attached this indicator to the indicator window together | //| with other filters (in one indicator window) I recognized that | //| it is great indicator. It follows the price and seems it is like | //| the price curve in the indicator window. Just attach an other filter to| //| the same window and this KGHP indicator will be as price curve. | //| It is very easy to analyze everything.*/ | //| --- Parameters: P1=30, D1=29, A1=40 | //| --- P2=52, D2=31, A2=40, Ripple=0.08, Delay=0 | //| --- Order [Auto]=858, Calculate method=2 | //+------------------------------------------------------------------------+ //--- Copyright #property copyright "Copyright 2006, Newdigital" //--- link to the website of the author #property link "http://www.finware.ru/" #property description "Digital High Pass (KGHP) Filter" #property description "Using the Generator of Digital Filters" //--- Indicator version #property version "1.00" //--- drawing the indicator in a separate window #property indicator_separate_window //--- one buffer is used for calculation and drawing of the indicator #property indicator_buffers 1 //--- one plot is used #property indicator_plots 1 //--- drawing the indicator as a line #property indicator_type1 DRAW_LINE //---- blue color is used for the indicator line #property indicator_color1 clrRed //---- the indicator line is a continuous curve #property indicator_style1 STYLE_SOLID //--- indicator line width is 2 #property indicator_width1 2 //--- displaying the indicator label #property indicator_label1 "KGHP" //--- indicator input parameters input int KGHPShift=0; // Horizontal shift of the average in bars //--- declaration of the integer variables for the start of data calculation int min_rates_total; //---- declaration of a dynamic array that //---- will be used as an indicator buffer double ExtLineBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- initialization of global variables min_rates_total=858; //--- set ExtLineBuffer dynamic array as indicator buffer SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA); //--- shift the indicator horizontally by KGHPSift PlotIndexSetInteger(0,PLOT_SHIFT,KGHPShift); //--- set the position, from which the indicator drawing starts PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //--- restriction to draw empty values for the indicator PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); //--- initializations of a variable for the indicator short name string shortname; StringConcatenate(shortname,"KGHP(",KGHPShift,")"); //--- Creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,shortname); //--- Determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //--- } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // number of bars in history at the current tick const int prev_calculated, // number of bars calculated at previous call const int begin, // index of the beginning of reliable bars counting const double &price[]) // price array for calculation of the indicator { //--- checking if the number of bars is enough for the calculation if(rates_totalrates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator { first=min_rates_total-1+begin; // starting index for calculation of all bars //--- increase the position of the data start by 'begin' bars as a result of the calculation using data of another indicator if(begin>0) PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,begin+min_rates_total); } else first=prev_calculated-1; // starting number for calculation of new bars //--- main indicator calculation loop for(bar=first; bar