RSI_MTF1
Download scriptThis script is designed to function as a specialized technical analysis tool for the MetaTrader platform. Its primary purpose is to calculate and display the Relative Strength Index (RSI), which is a popular momentum indicator used by traders to determine whether an asset is overbought or oversold.
Core Functionality
The unique characteristic of this specific script is its Multi-Timeframe (MTF) capability. While standard indicators typically only show data for the specific chart you are currently viewing (e.g., a 15-minute chart), this tool allows you to view RSI data from a different timeframe simultaneously. For example, you could stay on a small, fast-moving chart while viewing the RSI trends of a much larger daily or weekly timeframe.
How the Logic Works
The script operates using three primary components:
1. User Configuration The tool allows you to customize three key variables:
- RSI Period: Determines the number of previous price candles used to calculate the momentum (set to 3 by default in this version).
- Timeframe Selection: Allows you to choose which specific timeframe's data should be pulled into your current view (ranging from minutes to months).
- Price Type: Defines which part of the candle (like the close price or the open price) the indicator should use for its calculations.
2. Data Synchronization Because the script is pulling data from a different timeframe than the one you are looking at, it performs a series of "behind-the-scenes" calculations. It checks your current chart settings and identifies exactly where the data from the larger timeframe aligns with your current view. This ensures that the line drawn on your screen accurately reflects the historical data of the chosen period without getting out of sync.
3. Visual Output Once the data is gathered and synchronized, the script draws a continuous line in a "separate window" at the bottom of your chart.
- The indicator scales from 0 to 100.
- It automatically adjusts its label based on your settings (e.g., it will clearly display which timeframe it is currently tracking).
- It ensures that there is enough historical data available before attempting to draw the line, preventing errors or "broken" lines at the beginning of the chart history.
Summary for the Trader
Essentially, this script acts as a "window" into higher-level market trends. It simplifies your analysis by allowing you to monitor large-scale momentum (like daily trends) while executing trades on smaller, more immediate charts, helping you stay aligned with the bigger picture of the market.
//+------------------------------------------------------------------+
//| RSI.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//| by Hartono Setiono |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int RSIPeriod=3;
extern int RSITimeFrame=1440;
extern int applied_price=0;
//---- buffers
double RSIBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
IndicatorBuffers(1);
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,RSIBuffer);
//---- name for DataWindow and indicator subwindow label
switch(RSITimeFrame)
{
case 1 : short_name="Period_M1"; break;
case 5 : short_name="Period_M5"; break;
case 15 : short_name="Period_M15"; break;
case 30 : short_name="Period_M30"; break;
case 60 : short_name="Period_H1"; break;
case 240 : short_name="Period_H4"; break;
case 1440 : short_name="Period_D1"; break;
case 10080 : short_name="Period_W1"; break;
case 43200 : short_name="Period_MN1"; break;
default : {short_name="Current Timeframe"; RSITimeFrame=0;}
}
short_name="RSI_MTF("+short_name+", "+RSIPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,RSIPeriod);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Relative Strength Index |
//+------------------------------------------------------------------+
int start()
{
int i,x,counted_bars=IndicatorCounted();
double rel,negative,positive;
//----
if(RSITimeFrame==0) RSITimeFrame = Period();
if(RSITimeFrame==Period()) x=0; else x=1;
if(Bars<=RSIPeriod) return(0);
if(Period()<RSIPeriod) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=RSIPeriod;i++) RSIBuffer[Bars-i]=0.0;
//----
i=Bars-RSIPeriod-1;
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
RSIBuffer[i]=iRSI(NULL,RSITimeFrame,RSIPeriod,applied_price,MathFloor(i*Period()/RSITimeFrame)+x);
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments