Relative Strength Index (rsi)
[[rsi]] is a momentum oscillator bounded between 0 and 100. It compares the average strength of upward moves with the average strength of downward moves over a given period to show whether price movement is strengthening, slowing down, or losing momentum.
The RSI is used to identify excess phases, filter entries, or build reversal conditions. The higher its value, the more recent gains dominate. The lower it moves, the more recent losses take over.
Block declaration
A strategy can contain multiple [[rsi]] blocks. Each block outputs one numeric series representing the RSI value.
Examples
Minimal setup
This block computes an RSI on the close series. Since length is omitted, the block uses the default length 14.
[[rsi]]
id = "rsi"Custom fixed setup
This block uses a custom value for length.
[[rsi]]
id = "rsi"
length = 21Finding the optimal length
This block explores a range of values for length on the hlc3 source to identify the best-performing length.
[[rsi]]
id = "rsi"
source = "hlc3"
length.start = 8
length.stop = 30
length.step = 2Finding overbought and oversold zones
This example combines one [[rsi]] block with two [[constant]] blocks to explore different overbought and oversold zones. It helps test which thresholds best fit the symbol, the timeframe, and the overall strategy logic.
[[constant]]
id = "overbought"
start = 65
stop = 80
[[constant]]
id = "oversold"
start = 20
stop = 35
[[rsi]]
id = "rsi"
length = 14
[[condition]]
id = "rsi_buy_signal"
condition = "rsi < oversold"
next_block_id = "..."
[[condition]]
id = "rsi_sell_signal"
condition = "rsi > overbought"
next_block_id = "..."Parameters
| Parameter | Description |
|---|---|
idString Required | Unique name for the RSI series. |
sourceString or Array Optional | Input series used for the calculation. Accepted forms: source = "hl2" or source = ["close", "hl2"].Each value can be either a standard price source ( open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume) or the id of another indicator.Default value: "close" |
lengthInteger Optional | Observation window for the RSI; must be ≥ 2 when provided. If length is omitted, the default value is 14.Usage: • Fixed: length = value• Grid search: – length.start = min_value– length.stop = max_value– length.step = value (optional, default 1) |
symbolString or Array Optional | Market symbol(s) used when source only consists of standard prices (open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume).If source mixes standard prices and indicator ids, symbol is applied only to combinations based on standard prices.If source contains only indicator ids, symbol is ignored.When omitted, the block inherits the [backtest] symbol.For symbol format, arrays, and alignment rules, see Exchanges, Symbols and Timeframes. |
timeframeString or Array Optional | Timeframe on which this indicator is computed. If timeframe is omitted, the computation uses the grid’s main timeframe defined in [backtest].For accepted formats and timeframe alignment rules, see Exchanges, Symbols and Timeframes. |
Available variables
Use the identifiers below directly in your expressions. The RSI block exposes one numeric series and its parameters (length, source, symbol, timeframe).
Assume the block is configured as:
[[rsi]]
id = "rsi"Then:
| Variable | Description |
|---|---|
rsi orrsi[0]Decimal | Current RSI value. |
rsi[n]Decimal | RSI value from n candles ago. |
rsi.lengthDecimal | RSI length currently in use (works with fixed or grid‑searched values). |
rsi.sourceString | Name of the input series (e.g., close, hlc3, or another indicator id). |
rsi.symbolString | Symbol used (display format). |
rsi.timeframeString | Timeframe used for this RSI. |
Notes
- Numeric variables can be combined freely in formulas (arithmetic, comparisons, logical operators).
- Text variables are strings and are intended for equality/inequality checks only (e.g.,
rsi_std.timeframe == "60").