//+------------------------------------------------------------------+ //| LaguerreFilterLine.mq5 | //| Copyright 2011, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2011, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 1 //--- plot RSITrendScore #property indicator_label1 "LaguerreFilterLine" #property indicator_type1 DRAW_LINE #property indicator_color1 clrYellow #property indicator_style1 STYLE_SOLID #property indicator_width1 1 double FilterBuffer[]; double L0, L0Prev, L1, L1Prev, L2, L2Prev, L3, L3Prev; double iMABuffer[]; int iMAHandle; double Gamma = 0.7; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0, FilterBuffer, INDICATOR_DATA); PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 1); SetIndexBuffer(1, iMABuffer, INDICATOR_CALCULATIONS); ArraySetAsSeries(iMABuffer, true); iMAHandle = iMA(NULL, 0, 1, 0, MODE_SMA, PRICE_CLOSE); return(0); } void OnDeinit(const int reason) { IndicatorRelease(iMAHandle); } //+------------------------------------------------------------------+ //| 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[]) { L0 = L0Prev = L1 = L1Prev = L2 = L2Prev = L3 = L3Prev = 0; double cu, cd; int calculatedBars = (prev_calculated > 0) ? prev_calculated - 1 : 1; for (int i = rates_total - calculatedBars; i >= 0; i--) { CopyBuffer(iMAHandle, 0, i, 1, iMABuffer); L0 = (1.0 - Gamma)*iMABuffer[i] + Gamma*L0Prev; L1 = -Gamma*L0 + L0Prev + Gamma*L1Prev; L2 = -Gamma*L1 + L1Prev + Gamma*L2Prev; L3 = -Gamma*L2 + L2Prev + Gamma*L3Prev; cu = 0; cd = 0; if (L0 >= L1) cu = L0 - L1; else cd = L1 - L0; if (L1 >= L2) cu = cu + L1 - L2; else cd = cd + L2 - L1; if (L2 >= L3) cu = cu + L2 - L3; else cd = cd + L3 - L2; if (cu + cd != 0) FilterBuffer[i] = (L0 + 2 * L1 + 2 * L2 + L3) / 6.0; L0Prev = L0; L1Prev = L1; L2Prev = L2; L3Prev = L3; } return(rates_total); } //+------------------------------------------------------------------+