Pine Script v6 | v7.3
Dynamic thresholds + multi-timeframe analysis + divergence detection + stats filtering + smart alerts
Traditional RSI uses fixed 30/70 thresholds, but different assets have different volatility regimes. This indicator uses Z-Score statistics to calculate adaptive thresholds based on each asset's historical distribution.
| Z-Score | Percentile | Meaning |
|---|---|---|
| ยฑ2ฯ | P2 / P98 | Extreme zone |
| ยฑNฯ | Dynamic | Dynamic normal overbought/oversold reference |
| Icon | Name | Condition | Priority |
|---|---|---|---|
| ๐ | MTF Resonance | Multi-timeframe oversold alignment + Z < -2ฯ | โ โ โ โ โ |
| ๐ | Divergence + Extreme | Bullish divergence inside the extreme oversold zone | โ โ โ โ โ |
| ๐ฅ | Extreme Oversold | Z-Score breaks below -2ฯ (about P2) | โ โ โ โโ |
| โฌ๏ธ | Normal Oversold | Z-Score breaks below -Nฯ (normal_threshold) |
โ โ โโโ |
| Bullish Divergence | Price makes a new low while RSI does not | โ โโโโ |
| Icon | Name | Condition | Priority |
|---|---|---|---|
| ๐ | MTF Resonance | Multi-timeframe overbought alignment + Z > +2ฯ | โ โ โ โ โ |
| ๐ | Divergence + Extreme | Bearish divergence inside the extreme overbought zone | โ โ โ โ โ |
| โ๏ธ | Extreme Overbought | Z-Score breaks above +2ฯ (about P98) | โ โ โ โโ |
| โฌ๏ธ | Normal Overbought | Z-Score breaks above +Nฯ (normal_threshold) |
โ โ โโโ |
| Bearish Divergence | Price makes a new high while RSI does not | โ โโโโ |
Priority system: When multiple conditions are true on the same bar, only the highest-priority signal is shown.
| Icon | Status | Z-Score Range |
|---|---|---|
| ๐ข | Extreme oversold | Z < -2ฯ |
| ๐ก | Oversold | -2ฯ โค Z < -Nฯ* |
| โช | Neutral | -Nฯ โค Z โค +Nฯ |
| ๐ | Overbought | +Nฯ < Z โค +2ฯ |
| ๐ด | Extreme overbought | Z > +2ฯ |
*N = the dynamic normal threshold (
normal_threshold). The script calculates it from volatility, so it can be near 1.0ฯ in high-volatility markets and around 1.8ฯ in lower-volatility markets.
Each signal carries a quality grade based on multi-factor scoring:
| Grade | Score | Interpretation |
|---|---|---|
| [A] | โฅ80 | High quality, tradable |
| [B] | 60-79 | Good, tradable |
| [C] | 40-59 | Mixed, trade cautiously |
| [D] | <40 | Low quality, usually skip |
Scoring factors: MTF resonance (+25) | divergence (+25) | RSI pivot confirmation (+10) | weekly trend alignment (+15) | volume surge (+10) | deeper extremes (+10/+20) | ADX counter-trend penalty (-10)
| Mark | Meaning | Notes |
|---|---|---|
| โ | Passed the stats filter | Can appear in dashboard signal rows and alert messages |
| Failed the stats filter but still shown | Common in Alert Only or Soft mode |
|
| ๐ซ | Signal exists but is hidden | Can be caused by Smart normal-signal hiding, trend protection, or Hard filtering |
| None | Not triggered or stats filter disabled | For example persistent state text such as ๐ฅๆ็ปญ or ่ถ
ๅๅบ |
Note: Alerts fire only for signals that pass the stats filter. In practice, alert text usually shows
โor no mark at all, and does not sendโ ๏ธ.
- Automatically calculates the lookback window from the statistical formula
n = (Z ร ฯ / E)ยฒ - Adjusts
lookback_minandlookback_maxfrom asset volatility - Three precision presets: High / Normal / Low
- Includes health checks for sample coverage, distribution width, and statistical validity
- Four line modes:
Unified,Z-Score,Percentile, andBoth - Optional gradient fills and custom bull/bear colors
- Dashboard supports both
MobileandFulllayouts with four size presets
- Automatic fractal timeframe selection or manual selection of three timeframes
- Weighted resonance detection, with the highest timeframe counting double
๐resonance signals are the top-priority signals
- Volatility-adaptive behavior for Low Vol / Normal / High Vol / Crypto
- Single-anchor divergence detection, plotted at the structure pivot
- Extreme-zone divergence
๐versus regular divergenceโ๏ธ/โ๏ธ - Alerts can append
โกๅฎๆถ่็ฆปwhen realtime divergence is present
- Weekly trend filter to reduce counter-trend trades
- Three protection levels: Aggressive / Moderate / Loose
Percentile Confirmcan require extreme signals to satisfy both Z-Score and P5/P95 conditions- Smart normal-signal mode automatically hides normal signals during weekly extreme conditions
- High-priority signals (
๐/๐/๐ฅ/โ๏ธ) use a 1-bar cooldown - Normal signals
โฌ๏ธ/โฌ๏ธuse fixed or adaptive cooldown bars - Same-side signal upgrades can bypass cooldown, such as
โฌ๏ธ -> ๐ฅ -> ๐
- Stats modes:
Signal Type,Grade, andRanking - Uses Bayesian adjustment to reduce small-sample bias before filtering by sample count and adjusted win rate
- Three filter modes:
Alert Only: chart signals stay visible, alerts are filteredSoft: failed signals are downgraded visuallyHard: failed signals are hidden
- A single alert aggregates all signal types
- Includes RSI, Z-Score, approximate percentile, and quality grade
- Alert icons match the script output:
๐MTFๅ ฑๆฏ/๐่็ฆป/๐ฅๆ็ซฏ/โ๏ธๆ็ซฏ/โฌ๏ธ่ถ ๅ/โฌ๏ธ่ถ ไนฐ - Can append
โ็กฎ่ฎค,โฉๅ่ฝฌ, andโกๅฎๆถ่็ฆปwhen conditions apply - Optional ATR-based risk hints for stop-loss and take-profit suggestions
- Separate file: adaptive_rsi_strategy_harness.pine
Trade Side:Long Only / Short Only / BothBacktest ModeBaseline: raw production signalsProduction: only the signals that would make it into production alerts
- Full guide: docs/STRATEGY_REPORT.md
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ADAPTIVE RSI 35.2 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Z-Score -2.15ฯ (โP2) โ
โ Percentile P5 (โ1.5ฯ ~ โ2ฯ) โ
โ Signal ๐ฅ[A]โ โ
โ Status ๐ข EXTREME OVERSOLD โ
โ Protection โ W.RSI:45 ๐โ โ
โ Lookback 456(150-800) โ
โ
โ
โ
โ Normal โฌ๏ธ1.50ฯ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ MTF 1m|5m|15m ๐ข|โช|๐ข โ
โ Resonance ๐ข 3/4 โ
โ Divergence Auto ๐ข BULL (5/60) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Ranking (20b) โ
โ ๐[A]๐(12)โ +4.5%|85% โ
โ ๐[A]๐(8)โ +4.2%|82% โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโ
โ RSI 35.2 โ
โ Signal ๐ฅ[A]โโ Signal + grade + mark
โ Status ๐ขEXT โ Pure status
โโโโโโโโโโโโโโโโโโโ
- Open TradingView and go to Pine Editor.
- Paste the contents of
adaptive_rsi.pine. - Click
Add to chart.
- Right-click the indicator and choose
Add Alert. - Set the condition to Any alert() function call.
- If you want ATR hints in alerts, enable
Include Risk Hints in Alerts.
| Scenario | Dashboard | Normal Signals | Protection Level | Filter Mode |
|---|---|---|---|---|
| Intraday trading | Full | Smart | Moderate | Alert Only |
| Swing trading | Full | Off | Moderate | Hard |
| Mobile monitoring | Mobile | Off | Loose | Alert Only |
Alert Only: best default for most users; keep all chart context while filtering alertsSoft: useful when you want context but lower-quality signals de-emphasizedHard: use when you only want historically qualified signals and a cleaner chart
- Open a separate Pine script.
- Paste adaptive_rsi_strategy_harness.pine.
- Use TradingView
Strategy TesterwithTrade SideandBacktest Mode.
AAPL: ๐ข BUY โ ๐MTFๅ
ฑๆฏ | RSI:25.3 Z:-2.1ฯ (โP2) [A]โ
AAPL: ๐ด SELL โ โ๏ธๆ็ซฏ | RSI:78.5 Z:2.3ฯ (โP98) [B]โ
With risk hints enabled:
AAPL: ๐ข BUY โ ๐ฅๆ็ซฏ โ็กฎ่ฎค โกๅฎๆถ่็ฆป | RSI:25.3 Z:-2.1ฯ (โP2) [A]โ | SL:-1.5% TP:+3.0%
Note: Alerts do not send
โ ๏ธsignals that fail the stats filter. If stats filtering is disabled, the filter mark at the end of the alert also disappears.
- Keeps the public
v7.2signal model as the main baseline - Retains only minimal correctness fixes:
lookbackfloor stays above the statistical lower bound- weekly protection uses confirmed weekly data
- lower-timeframe MTF uses proper lower-TF aggregation
- Adds adaptive_rsi_strategy_harness.pine for Strategy Tester validation
- Tiered cooldown with upgrade exemption
- High-priority signals (
๐/๐/๐ฅ/โ๏ธ) use a 1-bar cooldown - Same-side upgrades can bypass cooldown, such as
Normal -> Extreme -> MTF - Faster response when signal quality deteriorates quickly
- Includes percentile confirm, stats filtering, ranking, and ATR risk hints
This project uses a custom Pine Script Static Analyzer for local and CI checks.
GitHub Actions runs lint checks automatically when changes touch .pine, .pine-lint.yml, or tools/pine_linter/**.
python3 tools/pine_linter/cli.py --config .pine-lint.yml adaptive_rsi.pine
python3 tools/pine_linter/cli.py --config .pine-lint.yml --format markdown --output lint-report.md adaptive_rsi.pine| Rule | Severity | Description |
|---|---|---|
| SEC001 | error | request.security() must use lookahead=barmerge.lookahead_off |
| SEC002 | warning | request.security() inside conditional branches may repaint |
| SYN001 | warning | Multi-line ternary expressions are fragile in Pine v6 |
| SYN002 | info | switch statements should include a default branch |
| SYN003 | warning | table.clear() must receive an explicit range |
| NAM001-003 | info | Naming convention checks for constants, functions, and types |
| QUA001 | info | Tooltips should include bilingual text |
| QUA002 | warning | request.security() outputs should be checked for na |
Config file: .pine-lint.yml