//+------------------------------------------------------------------+ //| Hodrick-Prescott Filter.mq5 | //| Copyright 2010, gpwr | //| vlad1004@yahoo.com | //+------------------------------------------------------------------+ #property copyright "gpwr" #property version "1.00" #property description "Hodrick-Prescott Filter" #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_label1 "filter" #property indicator_type1 DRAW_LINE #property indicator_color1 Red #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //===================================== INPUTS =========================================== input int Per =50; // HP filter period input int N =500; // # of prices to smooth //--- global variables int PrevBars; double Lambda; //--- indicator buffers double hpf[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- initialize global variables PrevBars=Bars(_Symbol,_Period)-1; Lambda=0.0625/MathPow(MathSin(M_PI/Per),4); //--- map indicator buffers ArraySetAsSeries(hpf,true); SetIndexBuffer(0,hpf,INDICATOR_DATA); IndicatorSetInteger(INDICATOR_DIGITS,_Digits); IndicatorSetString(INDICATOR_SHORTNAME,"HPF("+string(Per)+")"); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int bars, 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[]) { //--- check for insufficient data and new bar if(bars=0;i--) { x[i]=a[i]-b[i]*h1-c[i]*h2; h2=h1; h1=x[i]; } } //+------------------------------------------------------------------+