Author: Emerald King
StocRSI 2

This technical indicator is designed to provide a specialized visualization of market momentum by combining three distinct mathematical concepts: relative strength, historical price range scanning, and a weighted moving average.

Instead of relying on standard price action alone, the script processes historical data through a multi-layered calculation sequence to determine where the current market position sits within a specific timeframe. Here is how the logic functions step-by-step:

1. Dynamic Momentum Calculation

The script begins by analyzing price changes over a defined period. It identifies every instance where the price moved up and every instance where it moved down, calculating the total "gain" and total "loss" separately. By dividing these totals, it creates a raw momentum value. This value is then smoothed out using an averaging technique to ensure that minor, insignificant price flickers do not create "noise" in the final reading.

2. Relative Strength Analysis

Once the basic momentum is established, the script converts this into a relative strength ratio. It determines how much of the total market movement (the sum of gains and losses) was attributed to upward movement. This allows the indicator to see not just if the price is moving, but the proportion of power behind that move compared to the opposing force.

3. Range Scanning (Highs and Lows)

To give the data context, the script looks back over a specific window of time to identify the highest and lowest points reached by the relative strength values. By establishing these boundaries, it can determine exactly where the current market strength stands on a scale from bottom to top. It essentially asks: "Compared to the highest and lowest momentum we've seen recently, where are we right now?"

4. Weighted Smoothing

Finally, the script applies a weighted average to the resulting data. Unlike a standard average where every data point carries equal weight, this logic places more significance on the most recent price actions. This helps the indicator react more fluidly to current market shifts while maintaining a smooth line that is easy for a trader to follow visually.

Summary of Behavior

The final output is a smoothed line that represents a sophisticated "momentum-within-a-range" metric. It filters out extreme volatility, identifies the relative strength of the current trend against historical highs and lows, and provides a visual representation of whether the market is leaning toward an aggressive push or a period of exhaustion.

15 Views
0 Downloads
0 Favorites
StocRSI 2
//+------------------------------------------------------------------+
//|                                                    StocRSI 2.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 Red
//---- input parameters
extern int Len1=8;
extern int Len2=8;
extern int Len3=5;
extern int CountBars=950;

double CU = 0;
double CD = 0;
double CUAve = 0;
double CDAve = 0;
double CUAveB = 0;
double CDAveB = 0;
double Count = 0;
double RSI0[1000];
double HiR = 0;
double LoR = 0;
double StocR = 0;
double StocRSI = 0;
double Price = 0;
int x = 0;
double TempA = 0;
double TempB = 0;
double TempC = 0;
int Lookback = 0;

double val1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   Lookback = MathMax(Len1, Len2);
   Lookback = MathMax(Lookback, Len3);   
   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+Lookback);
   
   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-Lookback-1;
   while(i>=0)
   {
      CU = 0;
      CD = 0;
      CUAveB = CUAve;
      CDAveB = CDAve;
      
      for (x=i; x<i+Len1-1;x++)
      {
         if (Close[x] > Close[x + 1]) CU = CU + (Close[x] - Close[x + 1]);
         if (Close[x] < Close[x + 1]) CD = CD + (Close[x + 1] - Close[x]);
      }
      
      
      CU = CU / Len1;
      CD = CD / Len1;
      CUAve = CU;
      CDAve = CD;
      
      if ((CUAve + CDAve) != 0) RSI0[i] = CUAve / (CUAve+ CDAve);
      if (i > Lookback)
      {
         CUAve = (CUAveB *(Len1 - 1) + CU) / Len1;
         CDAve = (CDAveB *(Len1 - 1) + CD) / Len1;
      }
      
      if ((CUAve + CDAve) != 0) RSI0[i] = CUAve / (CUAve+ CDAve);
      
      for (x=i; x<i+Len2-1; x++) 
      {
         if ( x==i )
         {
            TempA = RSI0[x];
            TempB = RSI0[x];
         }
         
         if ( RSI0[x] > TempA )
            TempA = RSI0[x];
         if ( RSI0[x] < TempB )
            TempB = RSI0[x];
      }
            
      HiR = TempA;
      LoR = TempB;
      
      if (HiR != LoR) StocR = (RSI0[i] - LoR)/ (HiR - LoR);

      StocRSI = 0;
      TempC = 0;
      
      for (x=i; x<i+Len3-1;x++)
      {
         StocRSI = StocRSI + (Len3 - x) * StocR;
         TempC = TempC + (x+1);
      }
      
      if ( TempC != 0 ) StocRSI = StocRSI / TempC;

      if ( StocRSI > 0 )
         val1[i] = val1[i+1];
      else
         val1[i] = StocRSI;   
	  i--;
	}
   return(0);
 }
//+------------------------------------------------------------------+

Comments