Author: Emerald King
Laguerre

This tool is designed to provide traders with a specialized visual representation of market momentum, specifically utilizing a mathematical framework known as the Laguerre calculation. Unlike standard indicators that might simply track price, this script focuses on capturing the "velocity" and "smoothness" of price movements to help identify underlying trends.

How it Works

The logic functions by processing historical price data through a multi-layered calculation. It looks at recent closing prices and applies a smoothing factor (determined by the "gamma" setting) to create a series of rolling values.

Rather than looking at just one point in time, the script creates four distinct internal components ($L0$ through $L3$). These components interact with each other in a chain:

  • The first value is heavily influenced by the current price and the previous state.
  • Each subsequent value ($L1, L2, L3$) reacts to the one before it, creating a "memory" effect of recent market activity.

Momentum Calculation

Once these four values are established, the script evaluates the relationship between them. It calculates the difference (the "gap") between each consecutive level:

  1. It measures how much $L0$ deviates from $L1$, $L1$ from $L2$, and $L2$ from $L3$.
  2. It separates these differences into positive movements (upward momentum) and negative movements (downward momentum).
  3. Finally, it calculates a ratio of upward movement versus total movement.

Visual Output

The final result displayed on your chart is a smoothed oscillator value. Because it uses the Laguerre logic, the resulting line is designed to be less "jittery" than many other indicators. It aims to show you the relative strength of the current trend—providing a clearer picture of whether the market is aggressively pushing in one direction or if the momentum is beginning to exhaust.

Key Parameters

  • Gamma: This acts as the sensitivity dial. Adjusting this changes how quickly the indicator reacts to new price information versus how much it "smooths" out the noise.
  • CountBars: This defines the history window, telling the script how many previous candles to analyze to build its calculation.
15 Views
0 Downloads
0 Favorites
Laguerre
//+------------------------------------------------------------------+
//|                                                     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 Blue
//---- input parameters
extern double gamma=0.5;
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