1$

This technical script functions as a specialized market momentum indicator designed to track and smooth out price movements on a trading chart. Rather than simply plotting the raw price, it calculates a proprietary relative strength value by analyzing the relationship between multiple layers of smoothed data.

Core Logic Overview

The script operates through three primary stages: Smoothing, Layering, and Ratio Calculation.

1. Dynamic Smoothing (The Gamma Factor) The tool uses a specific multiplier (referred to as "Gamma") to blend current market prices with previous data points. This creates a "weighted" history where the influence of past prices is balanced against current fluctuations. This process prevents the indicator from reacting too violently to minor "noise" in the market, providing a cleaner visual representation of the trend.

2. Multi-Layered Momentum Tracking The script builds four distinct data layers (L0 through L3). Each layer is derived from the one before it using a recursive mathematical relationship. By stacking these layers:

  • L0 captures the most immediate price action.
  • L1, L2, and L3 capture progressively deeper levels of trend momentum.

By creating this hierarchy, the script can distinguish between a sudden, temporary price spike and a sustained shift in market direction.

3. Relative Strength Calculation Once these four layers are established, the script performs a "Comparison Analysis." It calculates the differences between each consecutive layer:

  • It identifies the "Upward Movement" (the sum of all positive differences where a higher layer exceeds a lower one).
  • It identifies the "Downward Movement" (the sum of all negative differences where a lower layer falls behind a higher one).

Finally, it produces a relative strength value by dividing the total Upward Movement by the combined total of all movements.

Practical Interpretation

The result is displayed as a line in a separate window below your main chart. Because it compares multiple smoothed layers against one another:

  • High Values: Suggest that the upward momentum across all price layers is dominant compared to the downward pressure.
  • Low Values: Suggest that downward pressure is prevailing across the different historical layers of the data.

In essence, this script acts as a sophisticated "momentum filter," helping traders see whether the current market trend has significant structural strength or if it is beginning to lose its underlying support.

11 Views
0 Downloads
0 Favorites
1$
//+------------------------------------------------------------------+
//|                                                            1.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+


#property indicator_separate_window
#property indicator_color1 MediumBlue

//---- input parameters
extern double gamma=0.9;
extern int CountBars=100000;

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