LaguerreFilterCloud
Download scriptThis technical tool is designed to help traders identify price momentum and market direction by filtering out "noise"—the minor, erratic price fluctuations that can often mislead short-term analysis. Based on the principles of cybernetics as applied to financial markets, the script provides a smoothed visual representation of price movement.
Core Logic Overview
The indicator operates by processing historical price data (specifically the high and low prices of each candle) to create a distinct mathematical "filter." Here is a breakdown of how it works in plain terms:
1. Data Smoothing (The Laguerre Component) Instead of looking at a single price point, the script utilizes a series of interconnected calculations known as Laguerre filters. These act like a sophisticated weighted average. By combining current prices with previous calculations, the tool creates a "fluid" movement that prioritizes the most relevant data while diminishing the impact of insignificant spikes or dips.
2. Reference Baseline (The FIR Component) To determine where the price is headed, the script also calculates a secondary reference point known as a Finite Impulse Response (FIR) buffer. This looks back at a specific window of recent candles to establish a "baseline" average of the price action over a short period.
3. Determining Market Movement (The Difference Calculation) The true value shown on your chart is the result of comparing these two components:
- It takes the smoothed baseline (FIR).
- It subtracts the Laguerre filtered price from it.
- The difference between these two figures is what is plotted on your screen.
How to Interpret the Results
Because the script calculates the difference between a moving average and a filtered price, the resulting histogram tells you about the relationship between current momentum and historical trends:
- Trend Identification: When the indicator moves significantly in one direction, it suggests that the current price movement is pulling away from its recent average, indicating a strengthening trend.
- Noise Reduction: Because of the Laguerre math involved, the histogram will appear smoother than many standard moving averages. It aims to show you the "true" path of the market by ignoring the jitter of individual price ticks.
- Customization: The tool includes a "Gamma" coefficient. This allows you to adjust the sensitivity of the filter—higher values typically make the indicator more responsive to recent changes, while lower values make it smoother and slower to react.
In summary, this script acts as a sophisticated lens that strips away market distractions, leaving you with a clear visual signal of the underlying price momentum.
//+------------------------------------------------------------------+
//| LaguerreFilterCloud.mq5 |
//| Laguerre Filter |
//| |
//| Algorithm taken from book |
//| "Cybernetics Analysis for Stock and Futures" |
//| by John F. Ehlers |
//| |
//| contact@mqlsoft.com |
//| http://www.mqlsoft.com/ |
//| modify to MQL4 by Mikhail Kozhemyako > LaguerreFilterCloud.mq4 |
//+------------------------------------------------------------------+
#property copyright "Coded by Witold Wozniak"
#property link "www.mqlsoft.com"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 clrGreen
#property indicator_width1 3
#property indicator_label1 "Laguerre Filter"
//+----------------------------------------------+
//| Âõîäíûå ïàðàìåòðû èíäèêàòîðà |
//+----------------------------------------------+
input double Gamma=0.68;// êîýôôèöèåíò èíäèêàòîðà
int oldbar;
double L0,L1,L2,L3,L0A,L1A,L2A,L3A;
int min_rates_total;
double LaguerreBuffer,FirBuffer,DifBuffer[];
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- Èíèöèàëèçàöèÿ ïåðåìåííûõ íà÷àëà îòñ÷¸òà äàííûõ
min_rates_total=4;
oldbar=Bars-1;
//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â èíäèêàòîðíûé áóôåð
SetIndexBuffer(0,DifBuffer);
SetIndexShift(0,min_rates_total+1);
//---- èíèöèàëèçàöèè ïåðåìåííîé äëÿ êîðîòêîãî èìåíè èíäèêàòîðà
string shortname=StringConcatenate("Laguerre Filter(",DoubleToString(Gamma,3),")");
IndicatorShortName(shortname);
}
//+------------------------------------------------------------------+
//| 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[]
)
{
//---- ïðîâåðêà êîëè÷åñòâà áàðîâ íà äîñòàòî÷íîñòü äëÿ ðàñ÷¸òà
if(rates_total<min_rates_total) return(0);
int first,bar;
//---- ðàñ÷¸ò ñòàðòîâîãî íîìåðà first äëÿ öèêëà ïåðåñ÷¸òà áàðîâ
if(prev_calculated>rates_total || prev_calculated<=0) // ïðîâåðêà íà ïåðâûé ñòàðò ðàñ÷¸òà èíäèêàòîðà
{
first=rates_total-1; // ñòàðòîâûé íîìåð äëÿ ðàñ÷¸òà âñåõ áàðîâ
bar=first;
}
else first=rates_total-prev_calculated+1+min_rates_total; // ñòàðòîâûé íîìåð äëÿ ðàñ÷¸òà íîâûõ áàðîâ
//---- îñíîâíîé öèêë ðàñ÷¸òà èíäèêàòîðà
for(bar=first;bar>=0 && !IsStopped(); bar--)
{
if(oldbar<Bars || prev_calculated==0)
{
oldbar=Bars;
L0A = L0;
L1A = L1;
L2A = L2;
L3A = L3;
}
L0 = (1 - Gamma) * (high[bar]+low[bar])/2 + Gamma * L0A;
L1 = - Gamma * L0 + L0A + Gamma * L1A;
L2 = - Gamma * L1 + L1A + Gamma * L2A;
L3 = - Gamma * L2 + L2A + Gamma * L3A;
if(bar>min_rates_total)
{
LaguerreBuffer=(L0+2.0*L1+2.0*L2+L3)/6.0;
FirBuffer=(1.0*(high[bar]+low[bar])/2+2.0*(high[bar-1]+low[bar-1])/2+2.0*(high[bar-2]+low[bar-2])/2+1.0*(high[bar-3]+low[bar-3])/2)/6.0;
DifBuffer[bar]=FirBuffer-LaguerreBuffer;
}
else
{
DifBuffer[bar]=0;
}
}
//----
return(rates_total);
}
Comments