Laguerre_005
Download scriptThis custom trading indicator is designed to provide visual momentum analysis by calculating a specialized variation of a moving average, tailored for use in the Metatrader platform. Its primary goal is to smooth out price fluctuations to reveal the underlying trend and strength of market movements.
Core Logic Overview
The script operates by analyzing historical price data (specifically closing prices) over a user-defined period. Instead of simply averaging the past few candles, it employs a recursive mathematical approach. This means that every new calculation takes into account both the current price and the results of the previous calculation, creating a fluid, continuous line that reacts to market changes without being overly sensitive to "noise" or minor price spikes.
How it Works Step-by-Step
- Smoothing Phase: The tool processes the price using a specific weight (defined by a sensitivity parameter). It creates four distinct layers of data (L0 through L3) that interact with one another. By weaving these layers together, the script identifies the "velocity" of the price action.
- Momentum Detection: Once the smoothed layers are established, the logic compares them against each other. It calculates the distance between these layers to determine if the market is moving upward or downward.
- Relative Strength Calculation: The tool then aggregates these differences into two categories: "Upward Momentum" and "Downward Momentum." It takes the ratio of these two forces to produce a final value.
- Visual Output: This final value is plotted on a separate window below your main chart.
Key Features for Traders
- Trend Clarity: By smoothing out the erratic jumps in price, the indicator helps traders see if the market is truly gaining strength or just experiencing temporary volatility.
- Balance Measurement: The resulting line provides a relative measure of momentum. When the value shifts significantly toward one end of the scale, it indicates a dominant trend; when it stays centered, it suggests a period of equilibrium or consolidation.
- Customizable Lookback: You can adjust how many bars of historical data the script considers, allowing you to tailor the indicator to different timeframes—from fast-paced scalping to long-term swing trading.
In essence, this tool acts as a "momentum filter," translating raw price data into a smoothed representation of market energy, helping traders identify the prevailing direction with greater clarity.
//+------------------------------------------------------------------+
//| 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.6;
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;
double val1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
SetIndexBuffer(0,val1);
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if (CountBars>Bars) CountBars=Bars;
SetIndexDrawBegin(0,Bars-CountBars);
int i;
int counted_bars=IndicatorCounted();
//if(CountBars<=Lookback) return(0);
//---- initial zero
//if(counted_bars<1)
//{
// for(i=1;i<=Lookback;i++) val1[CountBars-i]=0.0;
//}
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