Relative Strength Index RSI
Relative Strength Index, Wilder's — the average gain over the average loss across N bars, mapped onto 0 to 100, both averages Wilder-smoothed.
It measures how one-sided recent change has been, not how large the move was. Conventional readings: above 70 called overbought and below 30 oversold, the 50 line as a momentum divide, and divergence against price. MT5 and TA-Lib compute it identically.
01The study, live
Computed by Bentrix’s own code over the same synthetic bars on every page — an illustration of how the study behaves, not a market.
What this figure shows
The figure is computed over 300 sample bars. RSI has no value on the first 14 — the bars it needs before it can answer — and its first value stands on bar 15. Its line runs between 14.67 and 88.64 on these bars, and the last value is 57.38. The pane's scale is fixed at 0 to 100, the range the study can take. Counting the conditions the study declares on these bars: crosses above 30 7 times; crosses below 30 7 times; crosses above 70 7 times; crosses below 70 8 times. Press a condition under the figure to see each place marked. As states rather than moments: is above 30 on 216 bars; is below 30 on 70 bars; is above 70 on 66 bars; is below 70 on 220 bars.
02Its parts, named
03What you see
A line in its own pane between 0 and 100, with reference lines at 30 and 70. It rises when recent bars have mostly closed up and falls when they have mostly closed down.
04Where it comes from
J. Welles Wilder introduced the RSI in his 1978 book New Concepts in Technical Trading Systems, alongside the ATR, the ADX and the Parabolic SAR. It became one of the most widely used oscillators in the world. Despite its name it has nothing to do with comparing two markets; it compares a market's recent gains with its recent losses.
05The formula
Split each bar's change into a gain or a loss:
Uₜ = max (Pₜ − P_(t−1), 0), Dₜ = max (P_(t−1) − Pₜ, 0)
Smooth each with Wilder's average over bars (14 by default), then:
RS = Ū/D̄, RSI = 100 − 100/(1 + RS)
If the average gain equals the average loss, and the RSI is 50. If there were only gains, it approaches 100.
06A worked example
Take the closes 20, 21, 23, 22, 24, 25, 24, 26 and a period of 3. The changes from bar to bar are +1, +2, −1, +2, +1, −1, +2.
The first value uses the first three changes. The gains average (1 + 2 + 0) / 3 = 1.00 and the losses (0 + 0 + 1) / 3 = 0.333. RS = 1.00 / 0.333 = 3.00, and
RSI = 100 − 100 / (1 + 3.00) = 75.00
The next change is +2. Wilder's smoothing keeps two thirds of each average and adds a third of the new figure: the gains become (2 × 1.00 + 2) / 3 = 1.33, the losses (2 × 0.333 + 0) / 3 = 0.222. RS = 6.00 and RSI = 85.71.
Five of these seven changes are rises, so the index sits high. It never says how large the move was in price terms: the same pattern of changes a tenth the size gives exactly the same RSI.
07Built in Assay
The same study written in Assay, Bentrix’s script language, and drawn by Bentrix itself as the script’s graph: each block is one step of the formula. On the ladder the steps stand in the script’s order, one a row; on the board each wire carries a value from the block that gives it to the block that reads it, left to right. The script computes exactly what the study computes — Bentrix checks the two against each other, candle by candle.
//@version=6 indicator("Relative Strength Index") length = input.int(14, "Length") change = ta.change(close) // The rises and the falls, each averaged Wilder's way. gain = ta.rma(math.max(change, 0), length) loss = ta.rma(math.max(-change, 0), length) rsi = loss == 0 ? 100 : 100 - 100 / (1 + gain / loss) plot(rsi, "RSI") hline(70) hline(30)
Paste it into the Assay IDE to put it on a chart, or to change it. Looking at the graph is free in every package; editing it as blocks is Plus.
08Readings — what traders look for
Above 70, below 30. Wilder called these regions overbought and oversold. Traders read an RSI above 70 as recent gains having been much larger than recent losses; below 30, the reverse.
The 50 line. An RSI above 50 is read as average gains exceeding average losses over the window — many traders use it as a momentum divide.
Leaving an extreme. A cross back below 70 (or above 30) is read as the one-sided stretch having eased.
Divergence. Price making a new high while the RSI makes a lower high is read as the move continuing with less one-sidedness. See divergenceDivergencePrice makes a new high (or low) while an oscillator does not — the move is reaching further on less momentum..
Ranges shifting. Some traders read an RSI that keeps between 40 and 80 as typical of an up-trend, and one between 20 and 60 as typical of a down-trend.
How the 70 and 30 readings fail. In a strong trend the line stays at one end of its scale for a long time; a high reading there describes the trend and does not mark its end. Wilder's levels were described on daily commodity charts; on other markets and periods traders move them (80 and 20, or 60 and 40 inside a trend).
How divergence fails. A divergence can form two, three or four times in a row while price keeps going; it describes a slowing pace, and a move can keep slowing for a long while.
09In different markets and timeframes
The RSI is most informative in markets that swing inside a range: its turns from the ends of the scale line up with the swings. In a trend it shifts its whole range — Andrew Cardwell and Constance Brown describe it living between 40 and 80 in advances and 20 and 60 in declines — so the fixed 70 and 30 stop marking anything. On one-minute charts a 14-bar RSI covers a quarter of an hour and reaches its extremes many times a day; on weekly bars the same reading takes months to form. On Renko bricks every change is one box, so the RSI becomes a count of up-bricks against down-bricks.
10With other studies
Read beside a trend measure (a long moving average or the ADX) that says which of the two regimes holds, since the levels mean different things in each; beside the Stochastic RSI, which shows where the RSI stands in its own recent range; and beside price itself for divergences. ConnorsRSI averages a short RSI with two other quick measures.
11What it does not tell you
The RSI measures how one-sided recent changes have been — not how large the move was, and not what comes next. In a strong trend the RSI can stay above 70 for weeks while price keeps rising; overbought is a name for a reading, not a statement about what comes next. A divergence can be followed by another divergence.
12Inputs and defaults
- 1Period — 14The N of Wilder's smoothing. 14 is his own choice. A short RSI (2 to 5) swings between the ends of the scale almost every few bars; a long one (21 and more) seldom leaves the middle, and the usual 70 and 30 are then rarely reached.
- 2Applied price — CloseAny of the seven prices, and several at once, each its own line with its own look.
- 3Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
- 4Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.
What each input changes
- Applied priceWhich price of the bar the changes are taken from — the close by default.
- In use14 is Wilder's own. 2 to 5 for very short-term work (with levels at 90 and 10), 9 for a quicker line, 21 to 25 for a calmer one whose 70 and 30 are seldom reached.
13Limits and common misreadings
The period changes everything. A 2-period RSI swings from extreme to extreme; a 50-period RSI barely leaves the middle. Levels that suit one do not suit the other.
Wilder's smoothing makes the RSI depend slightly on how far back the calculation started; the warm-up matters for the first few dozen bars.
14Conditions an alert or a strategy can watch
an event happens on one bar a state holds on every bar while it lasts
These are the conditions the study itself declares — the same rules the alert editor and the strategy engine read, and the ones the figure's chips show.
15Practise it in the laboratory
On an H1 replay, turn on is above 70 in the figure's toggles above, then on your own chart, and step through each stretch: note what price did in the ten bars after the RSI left the zone. Then do the same during a strong trend and compare.
Open the laboratory17In Bentrix
- From the menu: a chart's Indicators button › Oscillators › RSI, or type RSI in its search.
- Its settings: the settings card opens when it is added; its legend's name opens it again.
18From an agent or a program
Two tools reach it. study_values computes it over a workbench’s candles up to the clock — no chart needed — and study_attach puts it on a chart, where it is drawn and saved with the chart ({"chart": "<chart uri>", "kind": "rsi"}).
The study, as a chart files it
This is a new RSI’s entry — its kind, its calculation, the price it reads and its settings. Change a setting here to read it with other inputs.
{
"applied": "close",
"convention": "mt5",
"kind": "rsi",
"settings": {
"period": 14,
"shape": "period"
}
}An agent
An agent calls the MCP tool with it:
{
"name": "study_values",
"arguments": {
"bench": "bentrix://lab/\u2026/bench/\u2026",
"symbol": "EURUSD",
"timeframe": "H1",
"limit": 5,
"study": {
"applied": "close",
"convention": "mt5",
"kind": "rsi",
"settings": {
"period": 14,
"shape": "period"
}
}
}
}A program
A program does the same in its language — bench and market as in the built-in indicators guide:
Python
values = client.study.values(bench, market, "H1", {"applied": "close", "convention": "mt5", "kind": "rsi", "settings": {"period": 14, "shape": "period"}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
print("line:", line["line"])
print(" newest values:", line["values"])JavaScript
const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "mt5", "kind": "rsi", "settings": { "period": 14, "shape": "period" } }, limit: 5 });
console.log("times:", values.times);
for (const line of values.lines) {
console.log("line:", line.line);
console.log(" newest values:", line.values);
}C#
var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "mt5", ["kind"] = "rsi", ["settings"] = new Dictionary<string, object?> { ["period"] = 14, ["shape"] = "period" } }, limit: 5);
Console.WriteLine($"times: {values!["times"]!}");
foreach (var line in values!["lines"]!.AsArray())
{
Console.WriteLine($"line: {line!["line"]!}");
Console.WriteLine($" newest values: {line!["values"]!}");
}Go
values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "mt5", "kind": "rsi", "settings": map[string]any{"period": 14, "shape": "period"}}, Limit: mcp.Ptr[int64](5)}))
fmt.Println("times:", at(values, "times"))
for _, line := range at(values, "lines").([]any) {
fmt.Println("line:", at(line, "line"))
fmt.Println(" newest values:", at(line, "values"))
}Java
Object values = client.study.values(new Bentrix.StudyApi.ValuesArgs(bench, market, "H1", obj("applied", "close", "convention", "mt5", "kind", "rsi", "settings", obj("period", 14, "shape", "period"))).limit(5L));
System.out.println("times:" + " " + at(values, "times"));
for (Object line : (List<Object>) at(values, "lines")) {
System.out.println("line:" + " " + at(line, "line"));
System.out.println(" newest values:" + " " + at(line, "values"));
}C++
auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "mt5"}, {"kind", "rsi"}, {"settings", Json::Object{{"period", 14}, {"shape", "period"}}}}).limit(5));
std::cout << "times:" << " " << values["times"].dump() << std::endl;
for (const Json &line : values["lines"].arr()) {
std::cout << "line:" << " " << line["line"].dump() << std::endl;
std::cout << " newest values:" << " " << line["values"].dump() << std::endl;
}Julia
values = client.study.values(bench, market, "H1", Dict{String,Any}("applied" => "close", "convention" => "mt5", "kind" => "rsi", "settings" => Dict{String,Any}("period" => 14, "shape" => "period")); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
println("line:", " ", line["line"])
println(" newest values:", " ", line["values"])
endR
values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "mt5", kind = "rsi", settings = list(period = 14, shape = "period")), limit = 5)
cat("times:", format(values$times), "\n")
for (line in values$lines) {
cat("line:", format(line$line), "\n")
cat(" newest values:", format(line$values), "\n")
}Rust
let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "mt5", "kind": "rsi", "settings": {"period": 14, "shape": "period"}})).limit(5))?;
println!("times: {}", values["times"]);
for line in values["lines"].as_array().into_iter().flatten() {
println!("line: {}", line["line"]);
println!(" newest values: {}", line["values"]);
}Reading the answer
times— the candles’ open times, in milliseconds since 1970 (UTC), oldest first.lines— one entry per line, in this order, each with itslinename and itsvalues;values[i]belongs to the candle attimes[i].- The last value is the candle at the clock’s, which may still be forming: it changes until that candle closes, as on the chart. Nothing after the clock is ever computed.
nullis a candle with no value yet — the warm-up, about 1 × the period at the start of the history.- Its fixed levels, drawn on the chart:
[30.0, 70.0].
line | What it is |
|---|---|
Main | the indicator's own value |
In a strategy
Filed under a key of your choice in a strategy document’s studies — here rsi: {"rsi": {"applied": "close", "convention": "mt5", "kind": "rsi", "settings": {"period": 14, "shape": "period"}}} — its rules can name:
| Write | What it is |
|---|---|
rsi | its main line, as a value in a compare |
{"cond": "rsi:level.cross_up:30"} | a condition it declares itself |
{"cond": "rsi:level.cross_down:30"} | a condition it declares itself |
{"cond": "rsi:level.above:30"} | a condition it declares itself |
{"cond": "rsi:level.below:30"} | a condition it declares itself |
{"cond": "rsi:level.cross_up:70"} | a condition it declares itself |
{"cond": "rsi:level.cross_down:70"} | a condition it declares itself |
{"cond": "rsi:level.above:70"} | a condition it declares itself |
{"cond": "rsi:level.below:70"} | a condition it declares itself |
19Sources
- Wilder, J. Welles Jr. New Concepts in Technical Trading Systems. Trend Research, 1978.
- Murphy, John J. Technical Analysis of the Financial Markets. New York Institute of Finance, 1999, ch. 10.
Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed