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.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.