OPEN-SOURCE SCRIPT

Recent Range Detector

572
Overview
The Recent Range Detector is a specialized indicator designed to identify when an asset is currently range-bound, providing traders with clear support and resistance levels for range trading strategies. Unlike traditional indicators that focus on trend detection, this tool specifically answers the question: "Is the price range-bound right now, and what are the exact trading levels?"

Key Features
Smart Range Detection - Uses a multi-factor scoring system to identify legitimate ranges
Dynamic Support/Resistance Levels - Automatically calculates and displays key trading levels
Range Quality Scoring - Provides confidence levels (Strong/Moderate/Weak Range)
Touch Validation - Counts actual price touches to confirm range reliability
Breakout Detection - Alerts when price exits the established range
Visual Clarity - Clean boxes, lines, and labels for easy interpretation

How It Works
The indicator analyses recent price action using three core metrics:

  1. Touch Quality (40%) - How many times price has respected support/resistance levels
  2. Containment Quality (40%) - What percentage of recent bars stayed within the range
  3. Recent Respect (20%) - Whether the latest price action confirms the range


These combine into a Range Score (0-1) that determines range strength and reliability.

Settings & Parameters

Range Lookback Period (Default: 15)
  • Number of bars to analyse for range detection
  • Shorter periods = more responsive to recent ranges
  • Longer periods = more stable, fewer false signals


Range Tolerance (Default: 2.0%)
  • Tolerance for price touches around exact highs/lows
  • Lower values = stricter range requirements
  • Higher values = more flexible range detection


Minimum Touches (Default: 3)
  • Required number of support/resistance touches for valid range
  • Higher values = more confirmed ranges, fewer signals
  • Lower values = more sensitive, earlier detection


Visual Options
  • Show Range Box: Displays the range boundaries
  • Show Support/Resistance Lines: Extends levels into the future


Understanding the Output

Range Score (0.000 - 1.000)
  • 0.7+ = Strong Range (Green) - High confidence range trading setup
  • 0.5-0.7 = Moderate Range (Yellow) - Decent range with some caution
  • 0.3-0.5 = Weak Range (Orange) - Low confidence, be careful
  • <0.3 = Not Ranging - Avoid range trading strategies


Range Status Classifications
  • Strong Range - Perfect for range trading strategies
  • Moderate Range - Good range with normal risk
  • Weak Range - Marginal range, use smaller positions
  • Not Ranging - Price is trending or too choppy for range trading


Key Metrics in Info Table
Range Size (%) - Size of the range relative to price level
  • 5-15% = Ideal range size for most strategies
  • <5% = Tight range, lower profit potential
  • >15% = Wide range, higher profit potential but more risk


Support/Resistance Levels - Exact price levels for entries/exits
  • Use these as your key trading levels
  • Support = potential buy zone
  • Resistance = potential sell zone


Total Touches - Number of times price respected the levels
  • 3-5 touches = Newly formed range
  • 6-10 touches = Well-established range
  • 10+ touches = Very strong, reliable range


Price Position (%) - Current location within the range
  • 0-20% = Near support (potential long opportunity)
  • 80-100% = Near resistance (potential short opportunity)
  • 40-60% = Middle of range (wait for better entry)


Visual Elements

Range Box
  • Green Box = Strong Range (Score ≥ 0.7)
  • Yellow Box = Moderate Range (Score 0.5-0.7)
  • Orange Box = Weak Range (Score 0.3-0.5)


Support/Resistance Lines
- Horizontal lines showing exact trading levels
- Extend into the future for forward guidance
- Colour matches the range strength

Background Colouring
- Subtle background tint during range periods
- Helps quickly identify ranging vs trending markets

Breakout Signals
- 📈 RANGE BREAK UP - Price breaks above resistance
- 📉 RANGE BREAK DOWN - Price breaks below support
- Only appears for confirmed ranges (Score ≥ 0.5)

Trading Applications

Range Trading Strategy
1. Look for Range Score ≥ 0.5
2. Buy near support (Price Position 0-20%)
3. Sell near resistance (Price Position 80-100%)
4. Set stops just outside the range
5. Exit on breakout signals

Breakout Strategy
1. Identify strong ranges (Score ≥ 0.7)
2. Wait for volume-confirmed breakout
3. Enter in breakout direction
4. Use previous resistance as support (or vice versa)

Market Context
- Strong ranges often occur after trending moves
- Use higher timeframes to confirm overall market structure
- Combine with volume analysis for better entries/exits

Best Practices

What to Look For
✅ Range Score ≥ 0.5 for trading consideration
✅ Multiple touches (5+) for confirmation
✅ Clear price rejection at levels
✅ Reasonable range size (5-15% for most assets)
✅ Recent price respect of boundaries

What to Avoid
❌ Trading ranges with Score < 0.3
❌ Very tight ranges (<3% size) - low profit potential
❌ Ranges with only 1-2 touches - not confirmed
❌ Ignoring breakout signals
❌ Trading against the higher timeframe trend

Alerts Available
- Range Detected - New range formation
- Range Break Up - Upward breakout
- Range Break Down - Downward breakout
- Range Ended - Range condition ended

Timeframe Recommendations
- Daily Charts - Best for swing trading ranges
- 4H Charts - Good for intermediate-term ranges
- 1H Charts - Suitable for day trading ranges
- Lower Timeframes - May produce more noise

Conclusion
The Recent Range Detector eliminates guesswork in range identification by providing objective, quantified range analysis. It's particularly valuable for traders who prefer range-bound strategies or need to identify when trending strategies should be avoided.

Remember: No indicator is perfect. Always combine with proper risk management, volume analysis, and broader market context for best results.

Disclaimer
This indicator is for educational purposes only and should not be considered as financial advice. Trading involves risk, and past performance does not guarantee future results. Always conduct your own research and consider your risk tolerance before making any trading decisions.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.