Laguerre_v4
Download scriptThis tool is designed to provide a visual representation of market momentum by analyzing price movements through a specialized mathematical filter. Instead of looking at raw price fluctuations, it processes data in a way that helps smooth out "market noise" to reveal the underlying trend.
Core Logic and Mechanics
The script operates based on three primary stages:
1. Data Smoothing (The Laguerre Calculation) The tool begins by taking the current closing prices and applying a specific weighted calculation. It uses a user-adjustable sensitivity factor (Gamma) to balance how much weight is given to new price data versus historical data. This creates a series of four distinct "lagged" values. By calculating these values in sequence, the tool creates a stabilized foundation that reacts to significant moves while ignoring minor, insignificant price flickers.
2. Momentum Measurement Once the smoothed values are established, the logic compares them against one another to determine the direction and strength of the current move. It calculates the difference between these four values:
- If the value is moving upward compared to its predecessor, it is categorized as Positive Momentum.
- If the value is moving downward, it is categorized as Negative Momentum.
The script then aggregates all these differences into two total sums: one representing the cumulative "upward" strength and one representing the cumulative "downward" strength.
3. Final Output (The Ratio) To produce the final visual result shown on your chart, the tool calculates a ratio between the positive and negative momentum. This results in a percentage-like value that oscillates within a specific range.
How to Interpret the Results
The final output tells you the relative strength of the current trend:
- When the indicator leans toward the upper boundary, it suggests that upward momentum is currently dominant.
- When it leans toward the lower boundary, it suggests that downward momentum is taking hold.
- The horizontal levels provided in the settings act as visual anchors to help you identify when momentum is reaching extremes or potentially losing steam.
Essentially, this script acts as a "momentum gauge," translating complex price history into a simplified visual indicator that helps traders see whether the current trend has enough power to sustain its direction.
//+------------------------------------------------------------------+
//| Laguerre.mq4 |
//| Emerald King |
//| mailto:info@emerald-king.com |
//+------------------------------------------------------------------+
#property copyright "Emerald King"
#property link "mailto:info@emerald-king.com"
#property indicator_separate_window
#property indicator_color1 Magenta
#property indicator_level2 0.75
#property indicator_level3 0.45
#property indicator_level4 0.15
//---- input parameters
extern double gamma = 0.7;
extern int CountBars = 950;
//----
double L0 = 0;
double L1 = 0;
double L2 = 0;
double L3 = 0;
double L0A = 0;
double L1A = 0;
double L2A = 0;
double L3A = 0;
double LRSI = 0;
double CU = 0;
double CD = 0;
//---- buffers
double val1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0, val1);
//----
if (CountBars > Bars)
CountBars = Bars;
SetIndexDrawBegin(0, Bars - CountBars);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i;
int counted_bars = IndicatorCounted();
i = CountBars - 1;
//----
while(i >= 0)
{
L0A = L0;
L1A = L1;
L2A = L2;
L3A = L3;
L0 = (1 - gamma)*Close[i] + gamma*L0A;
L1 = - gamma *L0 + L0A + gamma *L1A;
L2 = - gamma *L1 + L1A + gamma *L2A;
L3 = - gamma *L2 + L2A + gamma *L3A;
//----
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)
LRSI = CU / (CU + CD);
val1[i] = LRSI;
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments