OPEN-SOURCE SCRIPT
RSI For Loop | PW

RSI For Loop – True Dominance Oscillator
RSI For Loop – True Momentum Dominance Through Historical Comparison
The Relative Strength Index (RSI) is excellent at measuring recent price change intensity, but a reading of 70 or 30 has completely different implications depending on the market regime. RSI For Loop removes this ambiguity by transforming RSI into a clean, zero-centered dominance / percentile-rank oscillator that always tells you exactly how strong or weak the current momentum is compared to recent history.
How it works
- Standard RSI is calculated normally (default length 46).
- A simple for-loop compares the current RSI value against the actual RSI value of every previous bar inside the user-defined lookback window (default 1 to 99 bars ≈ one full quarter on daily charts).
- Current RSI higher → +1 point
- Current RSI lower → –1 point
The resulting score ranges from –99 to +99 and is naturally centered around zero:
1. +40 = current momentum beats ~70 % of the last 99 bars (approximation)
2. –60 = current momentum is weaker than ~80 % of the last 99 bars (approximation)
3. Near zero = balanced or ranging market
Additional statistical layers
- A very long rolling median of the score (default 240 periods) serves as a slow, robust dynamic centerline
- Upper and lower 3σ bands are calculated from the standard deviation of the underlying RSI median (default length 60) to highlight truly rare extreme-dominance phases
- Asymmetric trend thresholds (default Long +15 / Short –28) reflect the empirical observation that downside momentum is usually sharper and faster
Origin and development
The core idea of using a for-loop on RSI was originally introduced by viResearch in his invite-only “RSI For Loop” script.
While studying that concept I realised I needed an even more regime-robust strength gauge that looks back far enough to capture full market cycles (2–4 months). Therefore I completely rewrote the loop to compare against actual historical RSI values instead of fixed levels, added a 240-period median centerline, 3σ extreme bands, asymmetric thresholds, and visual signals. All parameters were extensively tested across dozens of major assets (BTC, ETH, SOL, SUI, BNB, XRP, TRX, DOGE, LINK, PAXG, CVX, HYPE, VIRTUAL + 20+ more cryptos; Magnificent 7 stocks, QQQ, SPX, XAUUSD) with the goal of achieving consistent profitability, high Sortino ratio and low drawdown in simple trend-following setups.
The final defaults represent the most robust compromise found — they keep you in real trends for dozens or hundreds of bars while staying almost silent in choppy, ranging markets.
Important Note
The optimization process is tailored to MY needs and have to be adjusted to you prefered timeframe!
I was mainly looking for an indicator that shows the underlying strength of an asset, the trend componant was only a bonus in my eyes.
How to use it
1. Green triangle below bar → score crosses above +15 → new bullish regime confirmed → enter or add to longs
2. Magenta triangle above bar → score crosses below –28 → exit longs or go cash/short
While score stays clearly positive → bullish bias hold

3. Score touching or breaking the 3σ bands → extreme conviction zone (add to winners or prepare for exhaustion)
Strength
Recommended defaults (My preference)
RSI length 46
Loop range 1–99
Long threshold +15
Short threshold –28
Median length 240
SD length 60
Recommended Universal Settings (Tested for low Max-Drawdown, high Sortino)
RSI length 44
Loop range 1–60
Long threshold +14
Short threshold –10
Median length 180
SD length 28
Works on every asset class, but the current settings are tuned for major liquid markets.
Disclaimer: This is not financial advice. Backtests are based on past results and are not indicative of future performance.
RSI For Loop – True Momentum Dominance Through Historical Comparison
The Relative Strength Index (RSI) is excellent at measuring recent price change intensity, but a reading of 70 or 30 has completely different implications depending on the market regime. RSI For Loop removes this ambiguity by transforming RSI into a clean, zero-centered dominance / percentile-rank oscillator that always tells you exactly how strong or weak the current momentum is compared to recent history.
How it works
- Standard RSI is calculated normally (default length 46).
- A simple for-loop compares the current RSI value against the actual RSI value of every previous bar inside the user-defined lookback window (default 1 to 99 bars ≈ one full quarter on daily charts).
- Current RSI higher → +1 point
- Current RSI lower → –1 point
The resulting score ranges from –99 to +99 and is naturally centered around zero:
1. +40 = current momentum beats ~70 % of the last 99 bars (approximation)
2. –60 = current momentum is weaker than ~80 % of the last 99 bars (approximation)
3. Near zero = balanced or ranging market
Additional statistical layers
- A very long rolling median of the score (default 240 periods) serves as a slow, robust dynamic centerline
- Upper and lower 3σ bands are calculated from the standard deviation of the underlying RSI median (default length 60) to highlight truly rare extreme-dominance phases
- Asymmetric trend thresholds (default Long +15 / Short –28) reflect the empirical observation that downside momentum is usually sharper and faster
Origin and development
The core idea of using a for-loop on RSI was originally introduced by viResearch in his invite-only “RSI For Loop” script.
While studying that concept I realised I needed an even more regime-robust strength gauge that looks back far enough to capture full market cycles (2–4 months). Therefore I completely rewrote the loop to compare against actual historical RSI values instead of fixed levels, added a 240-period median centerline, 3σ extreme bands, asymmetric thresholds, and visual signals. All parameters were extensively tested across dozens of major assets (BTC, ETH, SOL, SUI, BNB, XRP, TRX, DOGE, LINK, PAXG, CVX, HYPE, VIRTUAL + 20+ more cryptos; Magnificent 7 stocks, QQQ, SPX, XAUUSD) with the goal of achieving consistent profitability, high Sortino ratio and low drawdown in simple trend-following setups.
The final defaults represent the most robust compromise found — they keep you in real trends for dozens or hundreds of bars while staying almost silent in choppy, ranging markets.
Important Note
The optimization process is tailored to MY needs and have to be adjusted to you prefered timeframe!
I was mainly looking for an indicator that shows the underlying strength of an asset, the trend componant was only a bonus in my eyes.
How to use it
1. Green triangle below bar → score crosses above +15 → new bullish regime confirmed → enter or add to longs
2. Magenta triangle above bar → score crosses below –28 → exit longs or go cash/short
While score stays clearly positive → bullish bias hold
3. Score touching or breaking the 3σ bands → extreme conviction zone (add to winners or prepare for exhaustion)
Recommended defaults (My preference)
RSI length 46
Loop range 1–99
Long threshold +15
Short threshold –28
Median length 240
SD length 60
Recommended Universal Settings (Tested for low Max-Drawdown, high Sortino)
RSI length 44
Loop range 1–60
Long threshold +14
Short threshold –10
Median length 180
SD length 28
Works on every asset class, but the current settings are tuned for major liquid markets.
Disclaimer: This is not financial advice. Backtests are based on past results and are not indicative of future performance.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.