RSI measures the speed and magnitude of recent price changes on a 0–100 scale. Readings above 70 signal overbought conditions and below 30 oversold; many traders also use the 50 line as a simple trend bias. Copy the version for your platform below.
MetaTrader 4 (MQL4)
#property indicator_separate_window
#property indicator_buffers 1
extern int RSI_Period = 14;
double RsiBuffer[];
int OnInit() {
SetIndexBuffer(0, RsiBuffer);
IndicatorShortName("RSI(" + RSI_Period + ")");
return 0;
}
int OnCalculate(const int rates_total, const int prev_calculated, const double &close[]) {
for (int i = prev_calculated; i < rates_total; i++)
RsiBuffer[i] = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
return rates_total;
}MetaTrader 5 (MQL5)
#property indicator_separate_window
#property indicator_buffers 1
input int RSI_Period = 14;
double RsiBuffer[];
int OnInit() {
SetIndexBuffer(0, RsiBuffer);
IndicatorSetString(INDICATOR_SHORTNAME, "RSI(" + IntegerToString(RSI_Period) + ")");
return INIT_SUCCEEDED;
}
int OnCalculate(const int rates_total, const int prev_calculated,
const datetime &time[], const double &open[], const double &high[],
const double &low[], const double &close[], const long &tick_volume[],
const long &volume[], const int &spread[]) {
for (int i = prev_calculated; i < rates_total; i++)
RsiBuffer[i] = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
return rates_total;
}TradeStation (EasyLanguage)
inputs: Length(14);
variables: MyRSI(0);
MyRSI = RSI(Close, Length);
Plot1(MyRSI, "RSI");TradingView (Pine Script)
//@version=5
indicator("RSI", overlay=false)
length = input.int(14, "RSI Length")
overbought = input.float(70.0, "Overbought")
oversold = input.float(30.0, "Oversold")
rsiValue = ta.rsi(close, length)
plot(rsiValue, title="RSI", color=color.purple, linewidth=2)
hline(overbought)
hline(oversold)
hline(50)Want it inside dtcharts? Open the Script Converter, paste any version above, and it converts to a native indicator you can drop on the chart. Every snippet here is tested to convert cleanly.