LaguerreFilter
Download scriptThe Laguerre Filter is a specialized technical analysis tool designed to smooth out market noise and identify the underlying price trends more clearly. For traders who find standard moving averages too lagging or too "choppy," this script provides a more refined way to visualize price action by balancing responsiveness with stability.
Core Operational Logic
The script functions by processing historical price data through a multi-layered mathematical framework. Instead of simply averaging the last few prices, it utilizes a series of recursive calculations (referred to as L0 through L3). Think of these as four different "layers" of information that work together to capture the momentum of the market.
1. Data Input and Smoothing The script begins by identifying a base price point. It then applies a specific weighting factor, known as Gamma, to these prices. This Gamma value is the primary lever for the user; it determines how much weight the filter gives to new incoming data versus historical data. A higher sensitivity allows the filter to react faster to sudden moves, while a lower setting provides a smoother, more "damped" line that ignores minor fluctuations.
2. The Recursive Calculation The script calculates four distinct variables sequentially. Each variable takes the current price and blends it with the previous values of the preceding layers. This creates a cascading effect:
- Each layer acts as a stabilizer for the one before it.
- This ensures that the resulting filter doesn't "jump" erratically when a single price tick occurs, but rather flows in a way that mimics the organic movement of a trend.
3. Trend Detection and Filtering After generating these four layers, the script performs a comparison between them to measure the "force" of the current move. It evaluates the gaps between the layers to determine the strength of the upward or downward momentum.
Finally, the tool combines these layers into a single output line. This final line is the Laguerre Filter. Because it is derived from this multi-layered recursive process, the resulting line provides a visual representation of the trend that is often cleaner and more "fluid" than standard indicators.
Practical Application
For a user watching a chart, the Laguerre Filter acts as a guide. When the filter line moves steadily in one direction, it indicates a sustained trend. Because it is designed to filter out "noise"—those tiny, insignificant price wiggles that often trigger false signals—it helps traders stay focused on the primary direction of the market without being distracted by temporary volatility.
//+------------------------------------------------------------------+
//| LaguerreFilter.mq4 |
//| Copyright © 2006, Forex-TSD.com |
//| Written by IgorAD,igorad2003@yahoo.co.uk |
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link "http://www.forex-tsd.com/"
#property indicator_chart_window
#property indicator_color1 Yellow
//---- input parameters
extern double gamma = 0.7;
extern int Price_Type = 0;
//---- buffers
double Filter[];
double L0[];
double L1[];
double L2[];
double L3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(5);
//---- indicators
SetIndexStyle(0, DRAW_LINE);
SetIndexDrawBegin(0, 1);
SetIndexLabel(0, "LaguerreFilter");
SetIndexBuffer(0, Filter);
SetIndexBuffer(1, L0);
SetIndexBuffer(2, L1);
SetIndexBuffer(3, L2);
SetIndexBuffer(4, L3);
//----
string short_name="LaguerreFilter(" + DoubleToStr(gamma, 2) + ")";
IndicatorShortName(short_name);
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
double CU, CD;
//---- last counted bar will be recounted
if (counted_bars>0)
counted_bars--;
else
counted_bars = 1;
limit = Bars - counted_bars;
//---- computations for RSI
for (int i=limit; i>=0; i--)
{
double Price=iMA(NULL,0,1,0,0,Price_Type,i);
L0[i] = (1.0 - gamma)*Price + gamma*L0[i+1];
L1[i] = -gamma*L0[i] + L0[i+1] + gamma*L1[i+1];
L2[i] = -gamma*L1[i] + L1[i+1] + gamma*L2[i+1];
L3[i] = -gamma*L2[i] + L2[i+1] + gamma*L3[i+1];
CU = 0;
CD = 0;
if (L0[i] >= L1[i])
CU = L0[i] - L1[i];
else
CD = L1[i] - L0[i];
if (L1[i] >= L2[i])
CU = CU + L1[i] - L2[i];
else
CD = CD + L2[i] - L1[i];
if (L2[i] >= L3[i])
CU = CU + L2[i] - L3[i];
else
CD = CD + L3[i] - L2[i];
if (CU + CD != 0)
Filter[i] = (L0[i] + 2 * L1[i] + 2 * L2[i] + L3[i]) / 6.0;
}
return(0);
}
//+------------------------------------------------------------------+
Comments