RSIonMA
Download scriptThis script functions as a custom technical analysis tool designed to help traders identify momentum and trend shifts in the financial markets. Rather than simply looking at raw price action, it applies a layered mathematical approach to smooth out market "noise" and provide clearer signals.
Core Logic and Methodology
The tool operates by performing a two-stage calculation involving Moving Averages and the Relative Strength Index (RSI). Here is how that logic flows:
1. Smoothing the Price Data The script first takes the standard closing prices of an asset and processes them through two different "Moving Averages."
- A short-term average (set to 10 periods) captures more immediate price movements.
- A long-term average (set to 20 periods) provides a broader view of the prevailing trend.
By calculating these averages first, the script ensures that the subsequent momentum analysis is based on stabilized price trends rather than erratic, minute-to-minute fluctuations.
2. Calculating Momentum (The RSI Layer) Once the two moving averages are established, the script applies the Relative Strength Index (RSI) to each of them individually. While a standard RSI measures the speed and change of price movements, this script measures the momentum of the moving averages.
This creates two distinct data lines:
- The Fast Momentum Line: Derived from the short-term average, it reacts more quickly to recent market changes.
- The Slow Momentum Line: Derived from the long-term average, it tracks the broader, more sustained momentum of the market.
Visual Output and Interpretation
The results are displayed in a separate window on your trading chart, scaled between 0 and 100.
- Dynamic Interaction: By plotting these two different RSI values simultaneously, the tool allows you to see how "fast" momentum compares to "slow" momentum.
- Trend Analysis: When the lines move in harmony, it suggests a strong underlying trend. Divergences—where one line moves significantly differently than the other—can highlight shifts in market sentiment or potential exhaustion in a current trend.
In summary, this script doesn't just tell you where the price is; it tells you how the average price trend is accelerating or decelerating, providing a filtered, two-layered perspective on market strength.
//+------------------------------------------------------------------+
//| RSI.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_color1 Crimson
#property indicator_color2 LimeGreen
//---- input parameters
extern int RSIPeriod=9;
extern int MA1=10;
extern int MA2=20;
extern int MAMode=MODE_SMA;
extern int MAPrice=PRICE_CLOSE;
//---- buffers
double RSI1Buf[];
double RSI2Buf[];
double MA1Buf[];
double MA2Buf[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
SetIndexBuffer(0,RSI1Buf); SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(1,RSI2Buf); SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(2,MA1Buf); SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(3,MA2Buf); SetIndexStyle(3,DRAW_NONE);
//----
SetIndexDrawBegin(0,RSIPeriod);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Relative Strength Index |
//+------------------------------------------------------------------+
int start()
{
int i;
for (i=Bars-1; i>=0; i--) MA1Buf[i]=iMA(NULL, 0, MA1, 0, MAMode, MAPrice, i);
for (i=Bars-1; i>=0; i--) RSI1Buf[i] = iRSIOnArray(MA1Buf, Bars-1, RSIPeriod, i);
for (i=Bars-1; i>=0; i--) MA2Buf[i]=iMA(NULL, 0, MA2, 0, MAMode, MAPrice, i);
for (i=Bars-1; i>=0; i--) RSI2Buf[i] = iRSIOnArray(MA2Buf, Bars-1, RSIPeriod, i);
//----
return(0);
}
//+------------------------------------------------------------------+
Comments