Skip to content

aaajiao/Adaptive-RSI-Pro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

100 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Adaptive RSI Pro

ไธญๆ–‡่ฏดๆ˜Ž / Chinese README

TradingView Pine Script License

Pine Script v6 | v7.3

Dynamic thresholds + multi-timeframe analysis + divergence detection + stats filtering + smart alerts


Core Concept

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

Signal Legend

Buy Signals (shown near the bottom)

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 โ˜…โ˜†โ˜†โ˜†โ˜†

Sell Signals (shown near the top)

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.

Status Indicators

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.

Quality Grades

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)

Display Marks

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 โš ๏ธ.


Key Features

1. Adaptive Thresholds

  • Automatically calculates the lookback window from the statistical formula n = (Z ร— ฯƒ / E)ยฒ
  • Adjusts lookback_min and lookback_max from asset volatility
  • Three precision presets: High / Normal / Low
  • Includes health checks for sample coverage, distribution width, and statistical validity

2. Threshold Lines and Visual Modes

  • Four line modes: Unified, Z-Score, Percentile, and Both
  • Optional gradient fills and custom bull/bear colors
  • Dashboard supports both Mobile and Full layouts with four size presets

3. Multi-Timeframe (MTF) Analysis

  • 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

4. Divergence Detection

  • 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

5. Trend Protection

  • Weekly trend filter to reduce counter-trend trades
  • Three protection levels: Aggressive / Moderate / Loose
  • Percentile Confirm can require extreme signals to satisfy both Z-Score and P5/P95 conditions
  • Smart normal-signal mode automatically hides normal signals during weekly extreme conditions

6. Cooldown Upgrade Awareness

  • 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 โฌ†๏ธ -> ๐Ÿ”ฅ -> ๐ŸŒŸ

7. Signal Statistics and Filtering

  • Stats modes: Signal Type, Grade, and Ranking
  • 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 filtered
    • Soft: failed signals are downgraded visually
    • Hard: failed signals are hidden

8. Smart Alert

  • 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

9. Strategy Harness


Dashboard

Full Mode (Desktop)

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ 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%                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Mobile Mode

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  RSI      35.2  โ”‚
โ”‚  Signal   ๐Ÿ”ฅ[A]โœ“โ”‚  Signal + grade + mark
โ”‚  Status   ๐ŸŸขEXT โ”‚  Pure status
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Quick Start

1. Add the Indicator

  1. Open TradingView and go to Pine Editor.
  2. Paste the contents of adaptive_rsi.pine.
  3. Click Add to chart.

2. Configure Alerts

  1. Right-click the indicator and choose Add Alert.
  2. Set the condition to Any alert() function call.
  3. If you want ATR hints in alerts, enable Include Risk Hints in Alerts.

3. Suggested Presets

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

4. Filter Mode Tips

  • Alert Only: best default for most users; keep all chart context while filtering alerts
  • Soft: useful when you want context but lower-quality signals de-emphasized
  • Hard: use when you only want historically qualified signals and a cleaner chart

5. Strategy Validation

  1. Open a separate Pine script.
  2. Paste adaptive_rsi_strategy_harness.pine.
  3. Use TradingView Strategy Tester with Trade Side and Backtest Mode.

Alert Examples

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.


Current Version

v7.3

  • Keeps the public v7.2 signal model as the main baseline
  • Retains only minimal correctness fixes:
    • lookback floor 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

v7.2

  • 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

Code Quality

This project uses a custom Pine Script Static Analyzer for local and CI checks.

GitHub CI

GitHub Actions runs lint checks automatically when changes touch .pine, .pine-lint.yml, or tools/pine_linter/**.

Pine Script Lint

Local Check

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

Lint Rules

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

About

Dynamic overbought/oversold thresholds + Multi-timeframe analysis + Divergence detection + Signal statistics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages