OPEN-SOURCE SCRIPT

Alpha Relative Strength & Performance [Pineify]

2 974
Alpha Relative Strength & Performance [Pineify]

The Alpha Relative Strength & Performance (Alpha RSP) indicator is a dual-metric relative strength analysis tool that measures both an asset's outperformance ratio and its momentum trajectory against a user-defined benchmark — providing a complete, four-quadrant classification of relative strength state. Inspired by the Relative Rotation Graph (RRG) methodology developed by Julius de Kempenaer, Alpha RSP distills the two-dimensional RRG framework into a single-pane oscillator that traders can apply to any asset and any benchmark. Instead of simply comparing price returns, the indicator computes a double-smoothed RS Ratio (where the asset sits relative to its own trend of outperformance) and an RS Momentum reading (whether that outperformance is accelerating or decelerating). Together, these two metrics classify the asset into one of four states — Strong, Improving, Weakening, or Weak — with color-coded plotting, area fills, crossover signals, and a real-time dashboard table. This gives traders an objective, quantitative framework for sector rotation, pair trading, and relative performance timing.

Key Features

  • Double-smoothed RS Ratio oscillator — uses two layers of Weighted Moving Average (WMA) smoothing on the raw price ratio to produce a stable, noise-resistant measure of relative outperformance centered around the 100 equilibrium line.

  • RS Momentum (second derivative) — calculates the rate of change of the RS Ratio itself, revealing whether outperformance is accelerating or decelerating before the RS Ratio line visually turns.

  • Four-quadrant state classification — categorizes the asset into Strong (Leading), Improving, Weakening, or Weak (Lagging) based on the combination of RS Ratio and RS Momentum relative to 100, mirroring the proven RRG quadrant system.

  • Momentum-confirmed crossover signals — bullish entry signals require the RS Ratio to cross above 100 with pre-confirmed positive momentum; bearish exit signals require a cross below 100 with pre-confirmed negative momentum, filtering out low-conviction transitions.

  • Net Performance delta — independently calculates bar-by-bar alpha (asset return minus benchmark return) as a supplementary metric displayed in the info table.

  • Real-time dashboard table — a four-row info panel displays the current quadrant state, RS Ratio value, RS Momentum value, and net performance percentage, all color-coded for instant visual assessment.

  • Flexible benchmark selection — compare against any symbol available on TradingView (SPY, QQQ, BTCUSD, sector ETFs, etc.), making the indicator applicable to equities, crypto, forex, and commodities.

  • Built-in alert conditions — four configurable alerts cover bullish entries, bearish exits, and sustained strong/weak state detection for hands-free monitoring.


How It Works

The indicator follows a multi-stage calculation pipeline that transforms a raw price ratio into a classified relative strength state:

  1. Benchmark data sourcing: The benchmark's closing price is fetched using request.security() with a one-bar lookback and lookahead enabled. This ensures only confirmed (already closed) benchmark data is used, preventing repainting. A validity check guards against missing data, falling back to neutral values (1.0 for ratios, 100 for normalized metrics) when the benchmark is unavailable.

  2. Relative Strength (RS) calculation: The raw RS is computed as Asset Close / Benchmark Close. A rising RS means the asset is gaining value faster (or losing value slower) than the benchmark. This raw ratio is then smoothed with a Weighted Moving Average (WMA) of configurable length to establish the asset's trend of relative performance.

  3. RS Ratio normalization: The RS Ratio measures where the current RS sits relative to its own WMA trend: RS_Ratio = WMA(RS / WMA_RS) × 100. Values above 100 indicate the asset is outperforming its own recent relative trend (leading); values below 100 indicate underperformance (lagging). The double WMA smoothing — first on the raw RS, then on the ratio — significantly reduces noise while preserving responsiveness.

  4. RS Momentum derivation: RS Momentum is the rate of change of the RS Ratio: RS_Mom = RS_Ratio / WMA(RS_Ratio) × 100. This "second derivative" of relative strength reveals whether the RS Ratio is accelerating (above 100) or decelerating (below 100). Momentum turns often precede RS Ratio turns, providing an early warning of quadrant transitions.

  5. State classification and signal generation: The combination of RS Ratio and RS Momentum relative to the 100 baseline classifies the asset into one of four quadrants. Crossover signals are generated when the RS Ratio crosses the 100 line with momentum confirmation from the previous bar, ensuring entries and exits occur only during high-conviction quadrant transitions.


Trading Ideas and Insights

  • Sector rotation timing: Apply Alpha RSP to sector ETFs (XLK, XLF, XLE, etc.) against SPY as the benchmark. Assets in the Strong quadrant (green) are the current market leaders — favor long positions in these sectors. Assets in the Weak quadrant (red) are lagging — avoid or consider short positions. The quadrant rotation (Strong → Weakening → Weak → Improving → Strong) follows a predictable clockwise pattern that can be used to anticipate sector leadership changes.

  • Pair trading confirmation: When comparing two correlated assets, use Alpha RSP on one asset with the other as the benchmark. A sustained Strong state suggests going long the asset and short the benchmark; a sustained Weak state suggests the reverse. The crossover signals provide specific entry and exit timing for the pair trade.

  • Momentum-based entries: The bullish entry signal (green circle) fires when the RS Ratio crosses above 100 with positive momentum — this is the moment the asset transitions into the Strong quadrant. Historically, assets entering the Strong quadrant tend to continue outperforming for multiple bars, making this a high-probability entry point for relative outperformance trades.

  • Early warning via momentum divergence: Monitor the RS Momentum independently. When an asset is in the Strong quadrant but RS Momentum drops below 100, it transitions to Weakening (yellow) — outperformance is decelerating even though the asset still leads. This early warning allows traders to tighten stops or reduce position size before the RS Ratio itself crosses below 100.

  • Benchmark-relative alpha tracking: The Net Performance row in the info table shows the bar-by-bar return difference between the asset and benchmark. Use this to monitor whether your holdings are generating positive alpha on each bar, independent of the smoothed RS calculations.


How Multiple Indicators Work Together

Alpha RSP integrates several analytical components into a unified relative strength assessment system, each serving a distinct purpose:

  1. Weighted Moving Average smoothing (trend extraction): WMA is applied twice in the calculation chain — first to smooth the raw RS ratio, then to normalize the RS Ratio and compute RS Momentum. WMA was chosen over SMA or EMA because its linear weighting scheme provides a good balance between responsiveness and smoothness. The double application creates a cascading filter that removes short-term noise while preserving the medium-term trend of relative performance.

  2. RS Ratio (position measurement): The RS Ratio answers the question "is the asset currently outperforming or underperforming its own recent relative trend?" By normalizing the raw RS against its WMA, the indicator creates a mean-reverting oscillator centered at 100 that is comparable across different assets and timeframes — regardless of the absolute price levels of the asset and benchmark.

  3. RS Momentum (direction measurement): The RS Momentum answers the question "is the relative outperformance getting better or worse?" This second derivative adds the critical directional dimension that the RS Ratio alone cannot provide. An asset can be above 100 (leading) but with momentum below 100 (weakening) — meaning it still outperforms but is losing its edge. This distinction is what enables the four-quadrant classification.

  4. Crossover signals with momentum confirmation (timing mechanism): Raw crossovers of the RS Ratio above/below 100 would generate signals at every quadrant boundary. By requiring momentum confirmation from the previous bar, the signal filter ensures that only transitions into the Strong quadrant (bullish) or Weak quadrant (bearish) generate signals — skipping the ambiguous transitions into Improving or Weakening states.


The synergy is hierarchical: raw price ratio → WMA-smoothed trend → normalized RS Ratio (position) → RS Momentum (direction) → four-quadrant classification → momentum-confirmed crossover signals. Each layer adds a dimension of analysis, and the final signals require alignment across all layers — the asset must cross the outperformance threshold AND have confirmed momentum direction to trigger.

Unique Aspects

  • RRG methodology in a single pane: Traditional Relative Rotation Graphs require a two-dimensional scatter plot with RS Ratio on the x-axis and RS Momentum on the y-axis. Alpha RSP condenses this into a standard oscillator pane by plotting the RS Ratio as the primary line and encoding the momentum dimension through color (four-quadrant coloring). This makes the RRG framework accessible within TradingView's standard indicator layout without losing the quadrant classification.

  • Double WMA smoothing architecture: Most relative strength indicators use a single smoothing pass (e.g., SMA or EMA of the price ratio). Alpha RSP's double WMA approach — smoothing the raw RS, then smoothing the normalized ratio — creates a more stable oscillator that filters out short-term noise while remaining responsive to genuine trend changes in relative performance.

  • Non-repainting benchmark data: The indicator fetches benchmark data with a one-bar offset (close[1]) and lookahead enabled, ensuring that only confirmed historical data is used. This prevents the common repainting issue where indicators using request.security() produce different historical signals depending on when they are loaded.

  • Momentum-confirmed signals: Unlike simple ratio crossover systems, Alpha RSP requires the previous bar's momentum to confirm the direction of the crossover. This dual-condition filter significantly reduces false signals during choppy, mean-reverting relative performance periods where the RS Ratio oscillates around 100 without establishing a clear trend.


How to Use

  1. Add the indicator to your chart. It appears in a separate pane below the price chart, displaying the RS Ratio line, a dashed equilibrium baseline at 100, and a color-coded area fill.

  2. Set the Benchmark Symbol to the index or asset you want to compare against. Use SPY for broad US equity comparison, QQQ for tech-weighted comparison, BTCUSD for crypto relative analysis, or any other symbol relevant to your trading universe.

  3. Adjust the Calculation Window based on your trading timeframe. The default of 14 works well for daily charts. Use shorter values (7–10) for intraday or short-term swing trading; use longer values (21–50) for position trading or weekly charts.

  4. Monitor the line color for the current quadrant state: green = Strong (outperforming with rising momentum), blue = Improving (underperforming but momentum turning positive), yellow = Weakening (outperforming but momentum fading), red = Weak (underperforming with falling momentum).

  5. Watch for green circle signals — these mark Bullish Entry points where the RS Ratio crosses above 100 with confirmed positive momentum, indicating the asset is entering the Strong quadrant. Consider initiating or adding to long positions relative to the benchmark.

  6. Watch for red circle signals — these mark Bearish Exit points where the RS Ratio crosses below 100 with confirmed negative momentum, indicating the asset is entering the Weak quadrant. Consider reducing exposure or exiting positions.

  7. Check the info table in the bottom-right corner for a real-time summary of the current state, RS Ratio, RS Momentum, and net performance values.

  8. Set up alerts using the four built-in alert conditions to receive notifications for bullish entries, bearish exits, or sustained strong/weak states without watching the chart.


Customization

  • Benchmark Symbol (default: SPY): The reference asset for relative strength comparison. Choose a benchmark that represents the market or sector you want to measure outperformance against. For equity traders, SPY or a sector ETF is typical. For crypto traders, BTCUSD provides a relative strength reading against the dominant cryptocurrency.

  • Calculation Window (default: 14): Controls the WMA smoothing period for both the RS Ratio and RS Momentum calculations. Lower values (7–10) produce a more volatile, responsive oscillator that captures short-term relative strength shifts — suitable for active trading. Higher values (21–50) produce a smoother oscillator that focuses on medium-term relative trends — suitable for position trading and sector rotation strategies.

  • Quadrant Colors: All four quadrant colors are fully customizable. The default scheme (green/blue/yellow/red) follows the standard RRG color convention, but you can adjust these to match your chart theme or personal preference. Colors are applied to the RS Ratio line, area fill, signal markers, and info table simultaneously.


Conclusion

The Alpha Relative Strength & Performance indicator brings the proven Relative Rotation Graph methodology into a streamlined, single-pane oscillator format. By computing both an RS Ratio (where the asset stands relative to its benchmark trend) and an RS Momentum (whether that standing is improving or deteriorating), it provides a complete four-quadrant classification of relative strength that goes far beyond simple price ratio comparison. The double WMA smoothing architecture delivers clean, noise-resistant readings, while momentum-confirmed crossover signals filter out low-conviction transitions. Whether you are timing sector rotations, managing pair trades, or simply tracking whether your holdings are generating alpha relative to a benchmark, Alpha RSP provides an objective, quantitative framework for relative performance analysis across any market and timeframe.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.