Laguerre_ROC

Download script
Laguerre_ROC

This tool is designed to analyze and visualize market momentum by calculating the Rate of Change (ROC) through the lens of a specialized mathematical smoothing technique. Instead of showing raw, jagged price movements that can be distracting, this indicator filters the data to provide a clearer picture of how quickly an asset's price is moving in a specific direction.

Core Logic Overview

The script operates by looking back at a set number of historical candles (defined by the period) and measuring the percentage change between the current price and the price from that past point. This gives us the basic "speed" of the market.

To make this speed data more useful for trading, the script applies a sophisticated weighting system:

  • Dynamic Smoothing: It uses a series of interconnected calculations (Laguerre-style filters) to balance new information with historical trends. By using a specific "gamma" value, the tool decides how much importance to give to the most recent price action versus older data.
  • Multi-Layered Analysis: The logic processes the data through four distinct layers. Each layer influences the next, creating a refined average that reduces "market noise." This helps in identifying the underlying trend without getting distracted by minor, insignificant fluctuations.
  • Momentum Ratio: Finally, the script calculates a ratio based on the differences between these four layers. It determines whether the momentum is pushing forward or pulling back.

Visual Representation

The result is displayed as a single line in a separate window below your main chart. Because it uses a weighted ratio:

  • The values are normalized to help you see the strength of the trend clearly.
  • It highlights where the market is accelerating, decelerating, or moving sideways.
  • By smoothing out the erratic "zig-zags" of standard price action, it allows traders to see the actual flow of the market momentum more intuitively.
15 Views
0 Downloads
0 Favorites
Laguerre_ROC
//+------------------------------------------------------------------+
//|                                                 Laguerre_ROC.mq4 |
//|                                             Emerald King , MTE&I |
//+------------------------------------------------------------------+

#property indicator_separate_window

#property indicator_color1 Red

#property indicator_level2 1.00
#property indicator_level3 0.75
#property indicator_level4 0.50
#property indicator_level5 0.25
#property indicator_level6 0.00

#property indicator_maximum  1.10
#property indicator_minimum -0.10

//---- input parameters
extern int    vPeriod   =     5;
extern double gamma     = 0.500;
extern int    CountBars =  3000;

double ROC = 0;
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 LROC = 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();

   i = CountBars-1;
   while(i>=0)
   {
      L0A = L0;
      L1A = L1;
      L2A = L2;
      L3A = L3;
      
      ROC = (((Close[i] - Close[i + vPeriod]) / Close[i + vPeriod]) + Point);
      L0 = ((1 - gamma)*(ROC)) + (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) LROC = CU / (CU + CD);
      val1[i] = LROC;
	  i--;
	}
   return(0);
 }
//+------------------------------------------------------------------+

Comments