RSI_on_MA_2X2_mtf

Download script
Author: Copyright � 2004, MetaQuotes Software Corp.
RSI_on_MA_2X2_mtf

This tool is a specialized technical analysis indicator designed for MetaTrader 4. Its primary purpose is to provide traders with a multi-layered view of market momentum by combining Relative Strength Index (RSI) calculations with Moving Averages across different timeframes.

Core Logic Overview

The script operates on a "nested" logic system. Instead of simply calculating the RSI based on raw price data (which can be very noisy), this indicator performs a two-step calculation process to smooth out market fluctuations and provide a more stable perspective on trend strength.

1. Data Smoothing via Moving Averages

First, the script calculates two distinct Moving Averages (MA). These act as a "filter" for the price data. By using Moving Averages as the foundation, the tool effectively removes minor price spikes and "noise," focusing instead on the underlying trend of the market.

2. Momentum Calculation (RSI)

Once the smoothed moving average data is established, the script applies the Relative Strength Index (RSI) to those averages. Because the RSI is calculated based on the Moving Average rather than the raw price, it provides a "momentum of the trend" reading. This helps traders identify overbought or oversold conditions that are more reliable than standard RSI readings.

3. Multi-Timeframe Integration

One of the most significant features of this logic is its ability to handle multiple timeframes simultaneously. The script can "look ahead" into higher timeframes (such as shifting from a 5-minute chart to a 1-hour or Daily view) while you are viewing your current chart.

This allows you to see what the momentum looks like on a larger scale without having to manually switch back and forth between different windows. It synchronizes this data so that the higher timeframe information is mapped correctly onto your current screen.

Summary of Visual Output

The indicator produces two main lines on a separate window below your price chart:

  • Primary Line: Represents the RSI of the first (shorter) Moving Average. This is typically used to identify immediate, short-term momentum.
  • Secondary Line: Represents the RSI of the second (longer) Moving Average. This helps in identifying the broader, long-term trend direction.

By comparing these two lines against established levels (such as 80 for overbought, 50 for neutral, and 20 for oversold), traders can better interpret whether the current market movement is a significant shift or just temporary volatility.

Indicators Used
Moving average indicatorRelative strength index
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
RSI_on_MA_2X2_mtf
//+------------------------------------------------------------------+
//| RSIonMA2x2mtf                             2RSI on 2MA    RSI.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|2007fxtsd keris  ki                    http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 Crimson

#property indicator_minimum -10
#property indicator_maximum 110

#property indicator_level1 80
#property indicator_level2 50
#property indicator_level3 20
#property indicator_levelstyle 2
#property indicator_levelcolor DarkSlateGray

//---- input parameters

extern int RSI1_Period =9;
extern int MA1_Period  =21;
extern int RSI2_Period =14;
extern int MA2_Period  =34;
extern int MA1_Mode  = MODE_EMA;
extern int MA2_Mode  = MODE_EMA;
extern int MA1_Price = PRICE_CLOSE;
extern int MA2_Price = PRICE_CLOSE;

extern int TimeFrame  = 0;
extern int MaxBarsToCount   = 1500;

extern string  TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
extern string  MA_Method_Price = "SMA0 EMA1 SMMA2 LWMA3||0O,1C 2H3L,4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";


//---- buffers
double RSI1_Buf[];
double RSI2_Buf[];
double MA1_Buf[];
double MA2_Buf[];
double MA1_Buf1[];
double MA2_Buf1[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator line
   IndicatorBuffers(6);

   SetIndexBuffer(0,RSI1_Buf); SetIndexStyle(0,DRAW_LINE); SetIndexLabel(0,"");
   SetIndexBuffer(1,RSI2_Buf); SetIndexStyle(1,DRAW_LINE); SetIndexLabel(1,"");
   SetIndexBuffer(2,MA1_Buf);  SetIndexStyle(2,DRAW_NONE); SetIndexLabel(2,"");
   SetIndexBuffer(3,MA2_Buf);  SetIndexStyle(3,DRAW_NONE); SetIndexLabel(3,"");
   SetIndexBuffer(4,MA1_Buf1); 
   SetIndexBuffer(5,MA2_Buf1); 

//----   

   SetIndexDrawBegin(0,RSI1_Period);
//----

IndicatorShortName("RSIonMA["+TimeFrame+"]: RSI1("+RSI1_Period+"|"+MA1_Period+") RSI2("+RSI2_Period+"|"+MA2_Period+")");
  if (TimeFrame<Period()) TimeFrame=Period();
 
 
   return(0);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
{
   datetime TimeArray[],TimeArray1[];

   int  counted_bars=IndicatorCounted();
   int  i,y=0,limit; 
   
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
     
      ArrayCopySeries(TimeArray, MODE_TIME,Symbol(),TimeFrame); 
      ArrayCopySeries(TimeArray1,MODE_TIME,Symbol(),TimeFrame); 
    
    limit = Bars - counted_bars;
    limit = MathMax(limit,TimeFrame/Period());
    limit= MathMin(limit,MaxBarsToCount);

   for(i=0,y=0;i<limit;i++)
   {
    if (Time[i]<TimeArray[y]) y++;
   
    MA1_Buf1[i]= iMA(NULL, TimeFrame, MA1_Period,0, MA1_Mode, MA1_Price, y);
    MA2_Buf1[i]= iMA(NULL, TimeFrame, MA2_Period,0, MA2_Mode, MA2_Price, y);
  
    MA1_Buf[y]=   MA1_Buf1[i];
    MA2_Buf[y]=   MA2_Buf1[i];

   }
 
   for(i=0,y=0;i<limit;i++)
   {
   if (Time[i]<TimeArray1[y]) y++;

   RSI1_Buf[i] = iRSIOnArray(MA1_Buf, 0, RSI1_Period, y);
	RSI2_Buf[i] = iRSIOnArray(MA2_Buf, 0, RSI2_Period, y);

   }
 
//----

	return(0);
}
//+------------------------------------------------------------------+

Comments