PROTECTED SOURCE SCRIPT

RegimeLens [JOAT]

28
RegimeLens — Market Regime Detection and Classification

RegimeLens identifies whether the market is in a Trending, Ranging, or Volatile state using a proprietary combination of trend strength analysis, volatility measurement, and percentile-based classification. Understanding the current market regime helps traders adapt their approach to current conditions—because the strategy that works in a trend will fail in a range.

Why This Script is Protected

This script is published as closed-source to protect the proprietary regime classification algorithm and the specific threshold calibration methodology from unauthorized republishing. The unique combination of ADX analysis, Bollinger Band width percentiles, ATR percentile ranking, and the transition zone logic represents original work that goes beyond standard regime detection approaches.

What Makes This Indicator Unique

Unlike simple trend indicators, RegimeLens:
  • Classifies markets into four distinct regimes, not just "trending" or "not trending"
  • Uses percentile-based volatility analysis for more adaptive classification
  • Includes a transition zone logic to prevent rapid regime flip-flopping
  • Tracks regime duration and strength for additional context
  • Provides visual regime changes with on-chart labels


What This Indicator Does

  • Classifies market into four regimes: Trend Up, Trend Down, Ranging, or Volatile
  • Displays Bollinger Bands colored according to current regime
  • Marks regime changes with on-chart labels
  • Colors price bars according to detected regime
  • Tracks regime duration and strength metrics
  • Provides comprehensive dashboard with all regime metrics


Core Methodology

The indicator analyzes multiple market dimensions to determine the current regime:

  • Trend Strength Analysis (ADX) — Measures directional movement strength regardless of direction. High ADX indicates trending; low ADX indicates ranging.

  • Directional Bias (DI+ vs DI-) — Determines whether bullish or bearish forces dominate when a trend is detected.

  • Volatility Expansion/Contraction (BB Width) — Tracks Bollinger Band width relative to historical norms using percentile ranking.

  • ATR Percentile Ranking — Compares current ATR to its historical distribution to identify abnormally high volatility conditions.


Regime Definitions

  • Trend Up (Green) — ADX above trending threshold with DI+ > DI- and price above basis. Strong directional movement with bullish bias confirmed.

  • Trend Down (Red) — ADX above trending threshold with DI- > DI+ and price below basis. Strong directional movement with bearish bias confirmed.

  • Ranging (Yellow) — ADX below ranging threshold indicating sideways consolidation. Low directional strength suggests mean-reversion strategies may work better.

  • Volatile (Purple) — Both ATR percentile AND BB width percentile above the high volatility threshold. Indicates unstable, potentially dangerous conditions where normal strategies may fail.


The classification uses a priority system where high volatility conditions take precedence, followed by trend strength evaluation, with ranging as the default state for low-activity periods.

istantanea

Regime Strength Calculation

Each regime has an associated strength score (0-100%) that indicates how firmly the market is in that state:
  • For trends: Based on ADX relative to threshold plus BB percentile
  • For ranging: Based on inverse ADX plus inverse BB percentile
  • For volatile: Based on ATR percentile


This helps identify when regime transitions may be approaching—declining strength often precedes regime changes.

Visual Features

  • Regime-Colored Bollinger Bands — Upper, basis, and lower bands all colored by current regime
  • Band Fill — 85% transparent fill between bands in regime color
  • Background Highlighting — Optional 90% transparent background in regime color
  • Regime Change Labels — On-chart markers when regime changes (arrows for trends, diamond for range, X for volatile)
  • Bar Coloring — Optional price bar coloring by regime


Color Scheme

  • Trend Up Color — Default: #00C853 (bright green)
  • Trend Down Color — Default: #FF1744 (bright red)
  • Range Color — Default: #FFD600 (yellow)
  • Volatile Color — Default: #AA00FF (purple)


Dashboard Information

The on-chart table (top-right corner) displays:
  • Current regime name with color coding
  • ADX value (highlighted if above trend threshold)
  • DI+ / DI- comparison with directional coloring
  • Bollinger Band width percentage
  • Volatility percentile (highlighted if above volatile threshold)
  • Regime strength percentage
  • Duration in bars since last regime change


Inputs Overview

Detection Settings:
  • ADX Length — Period for ADX/DI calculation (default: 14, range: 5-50)
  • BB Length — Period for Bollinger Bands (default: 20, range: 10-100)
  • BB Multiplier — Standard deviation multiplier (default: 2.0, range: 1.0-4.0)
  • ATR Length — Period for ATR calculation (default: 14, range: 5-50)


Thresholds:
  • Trending ADX Threshold — ADX level above which market is considered trending (default: 25, range: 15-50)
  • Ranging ADX Threshold — ADX level below which market is considered ranging (default: 20, range: 10-40)
  • High Volatility Percentile — Percentile above which volatile regime is triggered (default: 75, range: 50-95)


Visual Settings:
  • Trend Up/Down/Range/Volatile Colors — Fully customizable color scheme
  • Show Background — Toggle regime-colored background
  • Show Regime Bands — Toggle Bollinger Bands display
  • Show Dashboard — Toggle the information table
  • Color Price Bars — Toggle bar coloring by regime


How to Use It

Strategy Selection:
  • Trend Up/Down — Use trend-following strategies (breakouts, pullbacks, moving average systems)
  • Ranging — Use mean-reversion strategies (support/resistance bounces, oscillator extremes)
  • Volatile — Reduce position size, widen stops, or stay flat until conditions stabilize


For Regime Change Trading:
  • Watch for regime change labels as potential entry points
  • Trend regime starting often signals breakout opportunity
  • Ranging regime starting after trend may signal consolidation before continuation
  • Volatile regime is a warning to be cautious


For Risk Management:
  • Increase position size during strong trend regimes
  • Decrease position size during volatile or ranging regimes
  • Use regime strength to gauge conviction
  • Monitor duration—very long regimes may be due for change


Alerts Available

  • MRD Trend Up — Market regime changed to trending bullish
  • MRD Trend Down — Market regime changed to trending bearish
  • MRD Ranging — Market regime changed to sideways consolidation
  • MRD Volatile — Market regime changed to high volatility state
  • MRD Any Change — Notification on any regime transition


Best Practices

  • Don't fight the regime—adapt your strategy to current conditions
  • Volatile regime is a warning sign, not a trading signal
  • Use regime strength to gauge how established the current state is
  • Combine with other indicators appropriate for the detected regime


This indicator is provided for educational purposes. It does not constitute financial advice. Past performance does not guarantee future results. Always conduct your own analysis and use proper risk management before making trading decisions.

— Made with passion by officialjackofalltrades

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.