ytg_Def_RSI

Download script
Author: Yuriy Tokman
ytg_Def_RSI

This custom indicator is designed to help traders identify momentum trends by analyzing the relationship between two different Relative Strength Index (RSI) periods. Instead of looking at a single RSI line, this tool measures the "gap" or the difference in strength between a short-term trend and a long-term trend, then smooths that data to provide a cleaner visual signal.

How the Logic Works

1. Dual RSI Analysis The script begins by calculating two separate Relative Strength Indices simultaneously:

  • Short-Term RSI: This tracks rapid price fluctuations over a smaller window of time (defaulting to 14 periods). It reacts quickly to recent market movements.
  • Long-Term RSI: This tracks the broader market trend over a larger window of time (defaulting to 28 periods). It represents the overall momentum.

2. Calculating the Difference Rather than displaying these two lines individually, the script subtracts the Long-Term RSI value from the Short-Term RSI value. This calculation determines how much the immediate price action is pulling away from or pushing back against the broader trend.

  • A positive result suggests the short-term momentum is stronger than the long-term average.
  • A negative result suggests the short-term momentum is weaker than the long-term average.

3. Smoothing the Data Because raw differences between two indicators can sometimes be "noisy" or jagged, the script applies a Moving Average to this difference. This final step filters out minor price flickers and creates a smoother line on your chart.

Summary for the User

The final output you see is a smoothed representation of momentum acceleration. By observing how this line moves above or below the zero level, you can better visualize whether the current market speed is gaining strength relative to the historical average or beginning to lose steam. This helps in identifying potential trend shifts before they become obvious on a standard price chart.

Indicators Used
Relative strength indexMoving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
ytg_Def_RSI
//+------------------------------------------------------------------+
//|                                                  ytg_Def_RSI.mq4 |
//|                                                     Yuriy Tokman |
//|                                            yuriytokman@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link      "yuriytokman@gmail.com"

#property indicator_separate_window

#property  indicator_buffers 2
#property  indicator_color1  Green
#property indicator_level1 0

extern int RSI_1_Period  = 14;//ïåðèîä ïåðâîãî èíäèêàòîðà ÐÑÈ
extern int RSI_2_Period  = 28;//ïåðèîä âòîðîãî èíäèêàòîðà ÐÑÈ
extern int applied_price = 0;//èñïîëüçóåìàÿ öåíà  0-6
extern int ma_period     = 14;//ïåðèîä ñãëàæèâàíèÿ
extern int ma_method     = 0;//ìåòîä ñãëàæèâàíèÿ  0-3

double   buf[];
double   MA_buf[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(0, buf);
   
   SetIndexStyle(1,DRAW_NONE);
   SetIndexBuffer(1,MA_buf);   
   
   IndicatorShortName("ytg_Def_RSI");
   Comment("yuriytokman@gmail.com");   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   Comment("");  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   double RSI_1,RSI_2;
   
   int limit;
   int counted_bars=IndicatorCounted();
   
   if(counted_bars<0) return(-1);

   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(int i=limit; i>=0; i--)
   {
     RSI_1 = iRSI(NULL,0,RSI_1_Period,applied_price,i);
     RSI_2 = iRSI(NULL,0,RSI_2_Period,applied_price,i);

     MA_buf[i] = (RSI_1-RSI_2);
   }
   for(i=limit; i>=0; i--)
   {
     buf[i] = iMAOnArray(MA_buf,0,ma_period,0,ma_method,i);
   }   
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments