RSI_mtf
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), a popular momentum oscillator used by traders to determine whether an asset is being overbought or oversold.
Core Functionality
The tool visualizes price momentum by tracking the speed and change of price movements over a specific period. By analyzing these fluctuations, it provides a numerical value that helps users identify potential trend reversals or market exhaustion. The indicator is displayed in a separate window below the main price chart, ranging from 0 to 100, with clear visual markers at the 30 and 70 levels to highlight significant trading zones.
Key Logic & Features
- Multi-Timeframe Analysis: A standout feature of this script is its ability to look beyond the current chart's timeframe. While most indicators only show data for the period you are currently viewing (e.g., 15 minutes), this script can be configured to pull RSI data from different timeframes (such as Hourly, Daily, or Weekly) simultaneously. This allows traders to see "the big picture" without constantly switching between different charts.
- Customizable Parameters: Users have the flexibility to fine-tune the tool based on their specific trading style through several adjustable settings:
- RSI Period: Determines the length of time the indicator looks back to calculate momentum (the default is 14 periods).
- Applied Price: Defines which price point is used for the calculation (e.g., the closing price, opening price, etc.).
- Timeframe Selection: Allows the user to manually select which specific timeframe they wish to monitor.
- Smart Data Processing: To ensure the platform remains responsive and smooth, the script includes a "Max Bars" limit. This prevents the software from trying to calculate data for thousands of historical bars at once, focusing instead on the most relevant recent data to keep the chart moving efficiently.
- Dynamic Labeling: The script automatically generates a clear name in the data window that combines the period and the timeframe being used. This makes it easy for traders managing multiple windows to identify exactly what each indicator is reporting at a glance.
Summary of Use
Essentially, this tool acts as a high-level "momentum scanner." It takes complex price history, processes it through a specific mathematical formula (the RSI), and presents it as a clean, readable line. By offering multi-timeframe capabilities, it gives traders a sophisticated way to verify market trends across different time horizons in one unified view.
//+------------------------------------------------------------------+
//| 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_minimum 0
#property indicator_maximum 100
#property indicator_level1 30
#property indicator_level2 70
#property indicator_levelcolor DarkSlateGray
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int TimeFrame=0;
extern int RSIperiod=14;
extern int applied_price=0;
extern int MaxBarsToCount = 2500;
//---- 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(TimeFrame)
{
case 1: string TimeFrameStr="M1"; break;
case 5 : TimeFrameStr="M5"; break;
case 15 : TimeFrameStr="M15"; break;
case 30 : TimeFrameStr="M30"; break;
case 60 : TimeFrameStr="H1"; break;
case 240 : TimeFrameStr="H4"; break;
case 1440 : TimeFrameStr="D1"; break;
case 10080 : TimeFrameStr="W1"; break;
case 43200 : TimeFrameStr="MN1"; break;
default : TimeFrameStr ="TF0";
}
short_name="RSI ("+RSIperiod+") ["+TimeFrameStr+"] ";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
if (TimeFrame<Period()) TimeFrame=Period();
//----
SetIndexDrawBegin(0,RSIperiod);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Relative Strength Index |
//+------------------------------------------------------------------+
int start()
{
datetime TimeArray[];
int i,shift,limit,y=0,counted_bars=IndicatorCounted();
ArrayCopySeries(TimeArray,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++;
RSIBuffer[i]=iRSI(NULL,TimeFrame,RSIperiod,applied_price,y) ;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments