Systemicalpha

Relative Strength Index

systemic:core-rsiIndicatorsfunction1 cr

Inputs

NameTypeDescription
WindowintegerThe **Window** parameter sets the lookback period for the RSI calculation—the number of periods used to compute average gains and losses.
PricefloatarrayThe **Price** input accepts a time series of numerical values representing the prices you want to analyze. Typically, this is the **closing price** of an asset, though any consistent price measure (open, high, low, VWAP, etc.) can be used.

Outputs

NameTypeDescription
RSIfloatarrayThe **RSI** output is a time series of values ranging from **0 to 100**, matching the length of your input price data. Each value represents the Relative Strength Index at that point in time.

The Relative Strength Index (RSI) is one of the most powerful and widely used momentum oscillators in technical analysis. Created by J. Welles Wilder Jr. and introduced in his seminal 1978 book New Concepts in Technical Trading Systems, the RSI measures the velocity and magnitude of price movements to identify overbought and oversold conditions.

Unlike price itself, which can trend indefinitely, RSI is bounded between 0 and 100—making it immediately interpretable and comparable across any asset, timeframe, or market condition.

RSI=100−1001+RSRSI = 100 - \frac{100}{1 + RS}

Where RS (Relative Strength) is the ratio of smoothed average gains to smoothed average losses:

RS=Average GainAverage LossRS = \frac{\text{Average Gain}}{\text{Average Loss}}

Understanding RSI: The Intuition

At its core, RSI asks a simple but profound question: "How strong are the bulls compared to the bears?"

  • When prices consistently rise, gains accumulate and losses diminish → RS increases → RSI approaches 100
  • When prices consistently fall, losses accumulate and gains diminish → RS approaches 0 → RSI approaches 0
  • When buying and selling pressure are balanced → RS ≈ 1 → RSI ≈ 50
flowchart TD
    subgraph Input["📊 Price Data"]
        P["Closing Prices"]
    end
    
    subgraph Changes["Δ Price Changes"]
        D["Calculate Daily Changes<br/>ΔP = Pₜ − Pₜ₋₁"]
    end
    
    subgraph Separate["Separate Movements"]
        G["Gains: Δ > 0"]
        L["Losses: Δ < 0"]
    end
    
    subgraph Smooth["Wilder Smoothing"]
        AG["Average Gain"]
        AL["Average Loss"]
    end
    
    subgraph Calculate["RSI Calculation"]
        RS["RS = Avg Gain / Avg Loss"]
        RSI["RSI = 100 − 100 / 1 + RS"]
    end
    
    P --> D
    D --> G & L
    G --> AG
    L --> AL
    AG & AL --> RS --> RSI

The Mathematics in Detail

Let's walk through the RSI calculation step by step, ensuring you understand not just the what, but the why.

Step 1: Calculate Daily Price Changes

For each period tt, compute the change from the previous period:

ΔPt=Pt−Pt−1\Delta P_t = P_t - P_{t-1}

Step 2: Separate Gains and Losses

We then separate upward movements (gains) from downward movements (losses):

Gaint=max⁡(ΔPt,0)\text{Gain}_t = \max(\Delta P_t, 0) Losst=∣min⁡(ΔPt,0)∣\text{Loss}_t = |\min(\Delta P_t, 0)|

Note: Losses are expressed as positive values. A price drop of $5 produces a Loss of 5, not -5.

Step 3: Apply Wilder's Smoothing

This is where RSI differs from simpler moving averages. Wilder's smoothing is a special form of exponential moving average (EMA) with a smoothing factor α=1/n\alpha = 1/n:

First value (Simple Average):

Avg Gain1=∑i=1nGainin\text{Avg Gain}_1 = \frac{\sum_{i=1}^{n} \text{Gain}_i}{n}

Subsequent values (Wilder Smoothing):

Avg Gaint=(Avg Gaint−1)×(n−1)+Gaintn\text{Avg Gain}_t = \frac{(\text{Avg Gain}_{t-1}) \times (n-1) + \text{Gain}_t}{n}

This formula gives previous values more weight, creating a smooth, less erratic indicator. Unlike a simple moving average, Wilder's smoothing remembers all past data—not just the last nn periods.

Step 4: Calculate RSI

RS=Average GainAverage LossRS = \frac{\text{Average Gain}}{\text{Average Loss}} RSI=100−1001+RSRSI = 100 - \frac{100}{1 + RS}

Edge Case: If Average Loss = 0 (all prices rose), RSI = 100. If Average Gain = 0 (all prices fell), RSI = 0.


RSI Zones and Interpretation

The RSI scale naturally divides into meaningful zones:

RSI RangeZoneInterpretation
70–100🔴 OverboughtStrong bullish momentum; potential exhaustion. Watch for reversal signals.
50–70🟢 BullishUpward momentum dominates. Trend followers stay long.
30–50🟠 BearishDownward momentum dominates. Trend followers stay short or in cash.
0–30🔵 OversoldStrong bearish momentum; potential exhaustion. Watch for bounce signals.

The 50 Line: The Momentum Divider

The 50 level is the equilibrium point—gains and losses are balanced. Think of it as the "momentum equator":

  • RSI > 50: Bulls are winning more battles than bears
  • RSI < 50: Bears are winning more battles than bulls
  • RSI crossing 50: A potential shift in the balance of power
flowchart LR
    subgraph Bearish["🐻 Bear Territory"]
        OS["Oversold<br/>RSI < 30"]
        B["Bearish<br/>30 ≤ RSI < 50"]
    end
    
    subgraph Neutral["⚖️ Equilibrium"]
        EQ["RSI = 50"]
    end
    
    subgraph Bullish["🐂 Bull Territory"]
        BU["Bullish<br/>50 < RSI ≤ 70"]
        OB["Overbought<br/>RSI > 70"]
    end
    
    OS --> B --> EQ --> BU --> OB

Adjusting RSI Thresholds for Different Markets

The classic 30/70 thresholds were designed for traditional stock markets. Different markets may require adjustments:

Market TypeSuggested OversoldSuggested OverboughtRationale
Stocks (normal)3070Classic Wilder thresholds
Strong uptrend4080Overbought persists longer in bull markets
Strong downtrend2060Oversold persists longer in bear markets
Cryptocurrency2080Higher volatility requires wider bands
Forex (major pairs)3070Classic thresholds work well

Pro Tip: Rather than changing thresholds arbitrarily, observe where your specific asset tends to reverse. Historical backtesting reveals optimal zones for each instrument.


Window (Lookback Period) Selection

The window parameter determines how many periods are used in the RSI calculation. This is a critical choice:

WindowSensitivityBest For
7Very HighScalping, day trading, catching quick reversals
9HighShort-term swing trading
14Balanced ⭐Wilder's original—works well for most applications
21LowPosition trading, filtering noise
25+Very LowLong-term trend analysis

The Trade-off

flowchart LR
    subgraph Short["Short Window 7-9"]
        S1["✓ More signals"]
        S2["✓ Faster response"]
        S3["✗ More false signals"]
        S4["✗ Whipsaws in choppy markets"]
    end
    
    subgraph Long["Long Window 21+"]
        L1["✓ Fewer false signals"]
        L2["✓ Smoother line"]
        L3["✗ Slower to react"]
        L4["✗ May miss opportunities"]
    end
    
    Short -.->|"Trade-off"| Long

Trading Strategies with RSI

Strategy 1: Classic Overbought/Oversold

The simplest and most intuitive RSI strategy:

SignalConditionAction
Oversold bounceRSI drops below 30, then rises back above 30Consider buying
Overbought reversalRSI rises above 70, then falls back below 70Consider selling

⚠️ Warning: In strong trends, RSI can remain overbought or oversold for extended periods. An asset in a powerful bull run may see RSI stay above 70 for weeks. Use this strategy in ranging markets, or combine with trend filters.

Strategy 2: RSI Divergence

Divergence occurs when price and RSI move in opposite directions—often a powerful reversal signal:

TypePrice ActionRSI ActionSignal
Bullish DivergenceLower lowHigher lowSelling pressure weakening → potential upward reversal
Bearish DivergenceHigher highLower highBuying pressure weakening → potential downward reversal

Divergence works because it reveals hidden shifts in momentum before they manifest in price.

Strategy 3: The 50-Line Cross

A trend-following approach:

  • Bullish: RSI crosses above 50 → momentum shifting bullish, consider long positions
  • Bearish: RSI crosses below 50 → momentum shifting bearish, consider short positions

This generates fewer signals than overbought/oversold but is more reliable for trend confirmation.

Strategy 4: Failure Swings (Andrew Cardwell's Method)

A failure swing is a pattern that provides early reversal signals without requiring divergence:

Bullish Failure Swing:

  1. RSI falls below 30 (oversold)
  2. RSI bounces above 30
  3. RSI pulls back but holds above 30
  4. RSI breaks above the prior bounce high → Buy signal

This pattern shows that bears couldn't push RSI back into oversold territory—a sign of returning strength.


Combining RSI with Other Indicators

RSI is powerful alone but becomes even more effective when combined with complementary indicators:

flowchart TD
    subgraph Data["📈 Price Data"]
        P["Closing Prices"]
    end
    
    subgraph Trend["Trend Filter"]
        SMA["SMA-200<br/>Trend Direction"]
    end
    
    subgraph Momentum["Momentum"]
        RSI["RSI-14<br/>Overbought/Oversold"]
    end
    
    subgraph Logic["🔀 Decision Logic"]
        AND["AND Gate"]
        C1["Price > SMA-200"]
        C2["RSI crosses above 30"]
    end
    
    subgraph Signal["📍 Trade Signal"]
        BUY["Buy Signal"]
    end
    
    P --> SMA & RSI
    SMA --> C1
    RSI --> C2
    C1 & C2 --> AND --> BUY

Example System: Only buy when:

  1. Price is above the 200-period SMA (confirming uptrend)
  2. RSI crosses above 30 (oversold bounce in an uptrend)

This filters out oversold bounces in downtrends—which often fail.


Real-World Application: Sector Rotation

RSI excels at relative strength analysis across multiple assets. By comparing RSI values across sectors or assets, you can identify:

  • Emerging leaders: Assets with rising RSI while others stagnate
  • Weakening sectors: Falling RSI despite overall market strength
  • Rotation opportunities: When RSI of asset A peaks while asset B is bottoming

This approach is used by institutional traders to shift allocations before major moves become obvious on price charts.


Common Pitfalls to Avoid

PitfallWhy It's DangerousSolution
Buying purely on RSI < 30Oversold can get more oversoldWait for RSI to cross back above 30
Shorting at RSI > 70Overbought can persist in strong trendsConfirm with trend analysis
Using one timeframeMiss the bigger pictureCheck higher timeframe RSI for context
Ignoring the trendMean reversion fails in trendsCombine with SMA or ADX

Strengths and Limitations

✅ Strengths

  • Bounded scale (0-100): Easy to interpret, comparable across assets
  • Versatile: Works on any asset class and any timeframe
  • Multiple uses: Overbought/oversold, divergence, trend confirmation
  • Well-researched: Decades of backtesting and academic study

⚠️ Limitations

  • Lagging indicator: Based on past prices, so it reacts to moves rather than predicts them
  • False signals in trends: Can stay overbought/oversold for extended periods
  • Requires confirmation: Best used with other indicators or price action

Indicator Assessment

%%{init: {"quadrantChart": {"titleFontSize": 14}, "themeVariables": {"quadrant1Fill": "#e8f5e9", "quadrant2Fill": "#fff3e0", "quadrant3Fill": "#ffebee", "quadrant4Fill": "#e3f2fd"}}}%%
quadrantChart
    title RSI Indicator Assessment
    x-axis Low Popularity --> High Popularity
    y-axis Low Reliability --> High Reliability
    quadrant-1 High potential  
    quadrant-2 Established
    quadrant-3 Niche
    quadrant-4 Widely used
    Stocks: [0.90, 0.70]
    Crypto: [0.80, 0.60]
DimensionStocksCryptoExplanation
Popularity9/108/10One of the most widely used indicators globally; taught in virtually every technical analysis course
Reliability7/106/10Highly reliable in ranging markets; less so in strong trends where it can stay overbought/oversold
Complexity3/103/10Simple concept (measuring gain vs. loss strength); Wilder smoothing adds minor complexity
Versatility9/108/10Works across all timeframes, all asset classes; multiple strategies (divergence, crossover, zones)
Recent Interest7/108/10Evergreen indicator with steady interest; crypto traders particularly favor momentum indicators

Further Reading

Rendering diagrams...
© 2026 WanoLabs. All rights reservedAlpha build v0.1.5