Indicators · condition block
RSI (Relative Strength Index)
The RSI block compares the Relative Strength Index with a level, typically 30 for oversold and 70 for overbought. RSI measures how strong recent gains are relative to recent losses on a 0 to 100 scale.
How the engine evaluates it
RSI uses Wilder's smoothing. The first average gain and average loss are the simple averages of the first N close-to-close changes; after that each average is updated as (previous × (N − 1) + latest) / N.
RSI = 100 − 100 / (1 + average gain / average loss). If there were no losses at all, RSI is 100.
< fires while RSI is strictly below the level and > while it is strictly above. It is a state, not a crossing, so it can be true for many candles in a row. Before your start date the engine loads extra history (at least 50 candles, up to 5,000, scaled to the longest indicator in the bot) so the indicator has settled by the first candle of the run. For RSI, about five times its length.
change[t] = close[t] − close[t−1]
avgGain = (avgGain × (N − 1) + max(change, 0)) / N
avgLoss = (avgLoss × (N − 1) + max(−change, 0)) / N
RSI = 100 − 100 / (1 + avgGain / avgLoss)
Botscript syntax
In the Lab you pick this block from the Indicators group and fill in its fields. In the code view the same condition is written like this:
rsi(14) < 30
rsi(14) > 70
Settings
| Setting | Values | Default | Notes |
|---|---|---|---|
| Comparison | <, > | < | Below or above the level. |
| Level | 0 – 100 | 30 | 30 and 70 are the textbook levels; 20 and 80 are stricter. |
| Length | 2 – 5,000 | 14 | Wilder's original setting is 14. |
| Timeframe | the run's candles, or 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 1w | the run's candles | Optional. At least the run's candle size and a whole multiple of it. |
On a higher timeframe
Add a timeframe at the end to read RSI from bigger candles than the run uses, for example rsi(14) < 30 on 4h. The engine builds those candles from the run's own candles (UTC, weeks start on Monday) and evaluates the block only on candles that have closed, so there is no look-ahead. Lengths and lookbacks count the bigger candles.
RSI is a state on a higher timeframe: the result from the last completed bigger candle holds on every run candle until the next one closes.
The timeframe must be at least the run's candle size and a whole multiple of it; otherwise the run stops with an error and is not charged. Multi-timeframe conditions covers the details, including warm-up.
How traders use it
- Oversold dip buying:
rsi(14) < 30, ideally with a trend filter or cooldown. - Taking profit into strength:
rsi(14) > 70withholding. - Momentum confirmation:
rsi(14) > 50with a breakout, since strong trends keep RSI above 50.
Example bot
bot "Oversold Sniper"
guard max_per_trade $2000
when rsi(14) < 30 and cooldown 24
then buy 100%
when rsi(14) > 70
then sell 100%
- Buys when RSI(14) drops below 30, at most once every 24 candles, and never more than $2,000 at a time.
- Sells the whole position once RSI(14) rises above 70.
Pitfalls
- In strong trends RSI can stay oversold or overbought for a long time. Buying every reading below 30 in a crash keeps catching a falling market.
- Because the block is a state, an entry rule fires on every oversold candle. Buys are skipped while you hold (unless stacking is on), but add a cooldown if you allow stacking.
- Optimising the length and both levels at once is a fast way to overfit. Keep the textbook values unless you have a reason.
RSI: frequently asked questions
Does stratester use Wilder's RSI like TradingView?
Yes. Average gains and losses are smoothed with Wilder's method (the same running average as TradingView's ta.rsi), seeded with a simple average of the first N changes.
Is "rsi(14) < 30" a crossing?
No. It is true on every candle while RSI is below 30. For a single signal, combine it with a cooldown or a position check.
What if RSI equals the level exactly?
The comparison is strict: < 30 needs a value below 30, and > 70 needs a value above 70.
Which length should I use on 1-hour candles?
14 is the standard on every timeframe. Shorter lengths make RSI jumpier and reach the extremes more often.
Why is RSI 100 sometimes?
If every change in the averaging window was a gain, the average loss is zero and RSI is 100 by definition.
Related blocks
Simulated results are hypothetical. They include only the fee and slippage you set on the bot, not every real-world cost or market condition, and past performance does not guarantee future results. Nothing here is financial advice.