Author: Copyright � 2008, masemus
+RSI_mtf

This script is a technical analysis tool designed for the MetaTrader platform to help traders identify momentum and trend direction using a specialized variation of the Relative Strength Index (RSI). Instead of looking at a single timeframe, this tool performs a "Multi-Timeframe" analysis, allowing it to compare data from different periods simultaneously to provide a clearer picture of market behavior.

Core Logic and Functionality

1. Multi-Timeframe Comparison The script calculates the RSI across two different settings: a primary period (user-defined) and a secondary reference point. By subtracting the value of one from the other, the tool creates a "Trend" value. This mathematical difference helps filter out standard market noise, focusing specifically on whether the momentum is strengthening or weakening relative to its historical averages.

2. Dynamic Dual-Timeframe Monitoring A key feature of this script is its ability to look at two different time horizons at once:

  • It tracks the current chart's timeframe to show immediate price action.
  • It simultaneously pulls data from a higher (or different) timeframe, which you can manually set. This allows a trader to see if the short-term movement aligns with the broader market trend, helping to avoid "counter-trend" trading errors.

3. Visual Signal Interpretation The script translates complex numerical data into easy-to-read visual cues on your chart:

  • Color-Coded Histograms: The tool uses a dual-color system (Green and Red). It identifies whether the trend is currently moving upward or downward based on the relationship between the current momentum and the previous bar's momentum.
  • Trend Identification: By comparing the "current" value to the "previous" value, the script determines the direction of the move. If the momentum is increasing, it highlights the upward movement; if it is decreasing, it signals a downward move.

4. Intelligent Labeling To keep the user informed without cluttering the screen, the script dynamically updates its label in the data window. It automatically identifies which timeframe it is currently analyzing (e.g., M15, H1, D1) and displays a text summary of the current trend status (Up, Down, or Sideways).

Summary for the User

In simple terms, this script acts as a "momentum filter." It takes standard RSI data, compares it across different timeframes, and simplifies the result into a visual color-coded signal. This helps you quickly see if the market is gaining strength or losing steam, ensuring that your short-term trades are supported by the larger timeframe's momentum.

Indicators Used
Relative strength index
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
+RSI_mtf
//+------------------------------------------------------------------+
//|                                                     +RSI_mtf.mq4 |
//|                                        Copyright © 2008, masemus |
//|                                                masemus@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, masemus"
#property link      "masemus@yahoo.com"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 SeaGreen
#property indicator_color2 FireBrick
#property indicator_color3 Red
#property indicator_color4 DarkKhaki

#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1

#property indicator_level1 0.0
#property indicator_levelcolor Silver
#property indicator_levelstyle STYLE_DOT

//---- input parameters
extern int TF=5;
extern int RSI_01=14;
extern int RSI_02=70;
extern int Price_Type=5;

// Price_Type ---------+
// 0 = PRICE_CLOSE     |
// 1 = PRICE_OPEN      |
// 2 = PRICE_HIGH      |
// 3 = PRICE_LOW       |
// 4 = PRICE_MEDIAN    |
// 5 = PRICE_TYPICAL   |
// 6 = PRICE_WEIGHTED  |
//+--------------------+

//---- indicator buffers
double ExtLimeBuffer[];
double ExtRedBuffer[];
double ExtTrend[];
double ExtTrend2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- additional buffers are used for counting
   IndicatorBuffers(4);
//---- drawing settings
   IndicatorDigits(4);
   SetIndexDrawBegin(0,34);
   SetIndexDrawBegin(1,34);
//---- indicator buffers mapping
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(0,ExtLimeBuffer);
   SetIndexBuffer(1,ExtRedBuffer);
   SetIndexBuffer(2,ExtTrend);
   SetIndexBuffer(3,ExtTrend2);
   SetIndexLabel(0,NULL);
   SetIndexLabel(1,NULL);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Trend                                                            |
//+------------------------------------------------------------------+
int start()
  {
   int i,limit,Bshift,counted_bars=IndicatorCounted();
   double prev,current;
   string Teks01 = "", Teks02 = "";
//+------------------------------------------------------------------+
   string MTF="";
   double cTF=Period();

               if (cTF==PERIOD_M1) { MTF="M1"; }
               if (cTF==PERIOD_M5) { MTF="M5"; }
               if (cTF==PERIOD_M15) { MTF="M15"; }
               if (cTF==PERIOD_M30) { MTF="M30"; }
               if (cTF==PERIOD_H1) { MTF="H1"; }
               if (cTF==PERIOD_H4) { MTF="H4"; }
               if (cTF==PERIOD_D1) { MTF="D1"; }
               if (cTF==PERIOD_W1) { MTF="W1"; }
               if (cTF==PERIOD_MN1) { MTF="MN1"; }

               else if (TF == 1) { MTF="M1"; }
               else if (TF == 5) { MTF="M5"; }
               else if (TF == 15) { MTF="M15"; }
               else if (TF == 30) { MTF="M30"; }
               else if (TF == 60) { MTF="H1"; }
               else if (TF == 240) { MTF="H4"; }
               else if (TF == 1440) { MTF="D1"; }
               else if (TF == 10080) { MTF="W1"; }
               else if (TF == 43200) { MTF="MN1"; }
//+------------------------------------------------------------------+

//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars+TF/Period(); 

   for(i=limit; i>=0; i--)
   {
     Bshift = iBarShift(Symbol(),TF,Time[i]); 
     ExtTrend[i]=iRSI(Symbol(),TF,RSI_01,Price_Type,Bshift)
                 -iRSI(Symbol(),TF,RSI_02,Price_Type,Bshift);

     ExtTrend2[i]=iRSI(Symbol(),0,RSI_01,Price_Type,i)
                  -iRSI(Symbol(),0,RSI_02,Price_Type,i);
//----
   bool up=true;
      current=iRSI(Symbol(),TF,RSI_01,Price_Type,Bshift)
              -iRSI(Symbol(),TF,RSI_02,Price_Type,Bshift);
      prev=iRSI(Symbol(),TF,RSI_01,Price_Type,Bshift+1)
           -iRSI(Symbol(),TF,RSI_02,Price_Type,Bshift+1);
      if(current>0) {Teks01="UP";}
      if(current<0) {Teks01="DN";}
      if(current==0) {Teks01="SW";}
      if(current>prev) up=true;
      if(current<prev) up=false;
      if(!up)
        {
         ExtRedBuffer[i]=current;
         ExtLimeBuffer[i]=0.0;
         Teks02="DN";
        }
      else
        {
         ExtLimeBuffer[i]=current;
         ExtRedBuffer[i]=0.0;
         Teks02="UP";
        }
     }
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("+RSI_["+RSI_01+","+RSI_02+"] "+MTF+" :: TREND_["+Teks01+"] SiGNAL_["+Teks02+"]");
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments