06 — Oscillators

Relative Strength Index#

✓ Mathematical1 min read
◆ The PatternRSI = 100 − 100/(1 + RS), where RS = Avg Gain / Avg Loss over N periods (default 14).

The Relative Strength Index — J. Welles Wilder's momentum oscillator (1978).

RS = Average Gain / Average Loss (over N periods)
RSI = 100 − 100 / (1 + RS)

Default period: 14. Scale: 0–100.

Zones:
• RSI > 70 → overbought (price may pull back)
• RSI < 30 → oversold (price may bounce)
Divergence: Price makes new high but RSI doesn't → bearish divergence (momentum weakening)
Pattern bridge: RSI normalizes momentum to [0,100] — a sigmoid-like activation bounding raw gains and losses. In statistics, it’s a ratio of mean gains to mean losses.
How to validate this in practice
  1. Download OHLCV data and compute RSI using only historical closes.
  2. Define the trading rule before testing: threshold, hold period, stop, and transaction cost.
  3. Use walk-forward validation; tune thresholds on one period and test on the next.
  4. Compare against buy-and-hold and cash baselines.
  5. Report Sharpe, max drawdown, hit rate, turnover, and cost sensitivity.
Common pitfall — indicator worship: RSI is a deterministic formula, not proof of predictive edge. The trading claim is heuristic until validated out of sample.
Performance in practice
  • RSI(14) overbought/oversold alone has a ~50% hit rate — no better than a coin flip. The edge comes from divergences: when price makes new highs but RSI doesn't, reversal probability rises to ~65%
  • In strong trends, RSI can stay above 70 for weeks. Treating every "overbought" as a sell signal will lose money in trending markets
  • Andrew Cardwell's updated RSI framework uses 40-80 in bull markets, 20-60 in bear markets — dynamic zones adapted to regime
When to use this
Use when: Ranging/sideways markets. Looking for divergences as confirmation. Setting stop-loss levels. Combining with trend filters (only buy oversold in uptrends).
Skip when: Strong trending markets (RSI stays pinned). As a standalone entry signal. Low timeframes with high noise. News-driven moves where momentum is fundamentals-driven.
Use this pattern on real data
Pattern Portal Case: Market Strategy Backtest
Treat the indicator as a hypothesis. Validate with costs, walk-forward periods, and drawdown metrics.
Quick start — copy to notebook
pip install yfinance pandas pandas-ta
import yfinance as yf
import pandas_ta as ta

df = yf.download('SPY', start='2018-01-01', auto_adjust=True)
df['RSI_14'] = ta.rsi(df['Close'], length=14)
df['signal'] = (df['RSI_14'] < 30).astype(int).shift(1).fillna(0)
df['strategy'] = df['signal'] * df['Close'].pct_change()
print(df[['Close', 'RSI_14', 'signal', 'strategy']].tail())
← Previous
VWAP
Open in the full reader, with the topic sidebar →