OPEN-SOURCE SCRIPT
Aktualisiert Regime Classifier : TREND / CHOP / VOL (Multi-Index Tuning)

The Big Picture
The Regime Classifier is a single Pine Script that runs on any chart in TradingView and tells you what kind of market you are looking at. It analyzes the recent price action using three independent measurements and combines them into a single label that reads either TREND, CHOP, or VOL. This label appears as a colored tag at the top right of the most recent price bar, with green meaning the market is trending cleanly, red meaning it is choppy and directionless, and orange meaning it is in a high-volatility unstable phase.
The script is designed to be used across multiple charts — one instance on Nifty 50, another on Bank Nifty, another on Midcap 150, and so on for US indices. Each chart instance can be tuned independently from the indicator settings panel without touching the script itself. This is achieved through a configurable inputs section that exposes every important threshold as an adjustable parameter.
How The Script Is Structured
The script is organized into clearly demarcated sections, each separated by horizontal divider lines made of unicode characters. Reading from top to bottom, the sections are: a comprehensive documentation header, the Pine version declaration and indicator title, the inputs section, a position conversion block, the core calculations, the regime logic, the regime label and color assignments, the on-chart label display, the alert condition, a hidden plot for external referencing, and finally the diagnostic table.
This top-to-bottom flow matches the natural reading order. First you understand what the script does (header), then you see how it can be configured (inputs), then you see what it calculates (core calculations), then you see how those calculations are turned into decisions (regime logic), and finally you see how the decisions are displayed and made available (label, alert, plot, table).
The Documentation Header
The first major section of the script is a long block of comments that explains everything a user needs to know before using the indicator. This block is approximately one hundred lines long and is structured into seven distinct parts.
The first part explains what the indicator does in plain language, describing each of the three regimes — TREND, CHOP, and VOL — with their visual signature on the chart and the trading behavior recommended in each. The second part explains how the indicator makes its decisions, walking through the three underlying measurements (ADX, Bollinger Band Width Percentile, and EMA Whipsaw Filter) and explaining why each was chosen and what role it plays.
The third part is a detailed tuning guide showing recommended threshold values for seven different indices spanning Indian and US markets. This table is the most practical piece of documentation in the script because it tells the user exactly which numbers to enter when configuring the indicator on a specific chart.
The fourth part describes the diagnostic table, explaining what each row means and how to interpret the color coding. The fifth part is a deliberate disclosure of the indicator's limitations — what it cannot do, where it lags, and why these limitations are acceptable. The sixth part explains how to set up TradingView alerts using the indicator's built-in alert condition. The seventh part contains author and license information.
This entire header serves as both onboarding documentation for new users and a future reference for the author when revisiting the script after months away.
The Indicator Declaration
After the header comes the Pine version declaration and the indicator title. The script is written for Pine Script version 6, which is the current standard. The title is intentionally region-neutral, reading simply Regime Classifier with the three regime names listed. This neutrality matters because the same script is used across many different markets and indices, so the title should not imply it is specific to any one of them.
The overlay parameter is set to true, which means the indicator draws on top of the price chart rather than creating its own pane below the chart. This is the right choice for an indicator that places labels and tables on the chart but does not plot any price-like values that need their own scale.
The Inputs Section
The inputs section exposes every adjustable parameter to the user through TradingView's settings panel. There are nine inputs in total, organized into four logical groups.
The first input is the Configuration Label, which is a dropdown menu containing eight options corresponding to seven different indices plus a Custom option for any other instrument. This label is purely informational — it does not affect calculations. Its purpose is to give the user a clear visual indicator on each chart of which tuning preset is active. When you have multiple charts open, this label tells you at a glance whether you are looking at the Nifty 50 instance, the Bank Nifty instance, or another configuration.
The second input is the Diagnostic Table Position, which is another dropdown menu with nine options corresponding to the nine standard positions where Pine Script can place a table on a chart. This input lets the user move the diagnostic table to wherever it best fits the chart layout without having to edit the script.
The next group of inputs concerns the ADX calculation. The ADX Length controls the lookback period for the indicator (defaulting to fourteen, the classical value). The ADX Trend Threshold sets the value above which ADX is considered to confirm a trending market. The ADX Chop Threshold sets the value below which ADX contributes to a chop classification.
The third group concerns Bollinger Band Width. The Bollinger Length controls the period for the band calculation. The Bollinger StdDev controls how wide the bands are relative to the middle line. The BBW Percentile Lookback determines how many bars of history the current band width is ranked against. The BBW Volatility Percentile sets the threshold above which the indicator flags VOL.
The fourth group concerns the EMA Whipsaw Filter. The EMA Length sets the period of the moving average used to detect whipsawing. The EMA Whipsaw Lookback determines how many recent bars are checked for crossover counts.
Every input has a tooltip that explains its purpose when the user hovers over it in the settings panel. This makes the indicator self-documenting at the point of use.
The Position Conversion Block
After the inputs comes a small but important block that converts the user's selection from the Diagnostic Table Position dropdown into the actual Pine Script position constant required by the table.new function. The dropdown stores the user's choice as a text string like "Top Right" or "Bottom Left," but Pine Script's table function requires a specific built-in constant such as position.top_right or position.bottom_left.
The conversion block uses an if-else if chain to map each text option to its corresponding constant. The result is stored in a variable called posConstant, which is later used when creating the diagnostic table. This indirection is necessary because Pine Script does not allow dynamic position selection at the table creation point — you cannot pass a string variable directly. The conversion block solves this with a small one-time mapping.
The Core Calculations
This section computes the three underlying measurements that the regime logic depends on.
The first calculation is the ADX. The script uses Pine Script's built-in ta.dmi function, which returns three values — the Plus Directional Indicator, the Minus Directional Indicator, and the ADX itself. The script captures all three but uses only the ADX value for trend strength assessment. The other two are kept available for potential future enhancement but are not currently consumed.
The second calculation produces the Bollinger Band Width. The script first computes the Simple Moving Average over the configured length, then computes the standard deviation of price over the same length, then constructs the upper and lower bands by adding and subtracting a multiple of the standard deviation from the moving average. The band width is calculated as the upper minus the lower, divided by the middle, which normalizes the width to be comparable across instruments at different price levels.
After computing the raw band width, the script ranks it against its own history using the percentrank function. This produces a value between zero and one hundred indicating where the current band width falls compared to the previous one hundred bars (or whatever lookback the user configured). A value of ninety means the current width is wider than ninety percent of recent history, indicating volatility expansion.
The third calculation is the EMA whipsaw count. The script computes a twenty-period exponential moving average, then identifies every bar where price crossed above the EMA (a crossover) or below the EMA (a crossunder) within the recent lookback window. It sums these events to get a total cross count over the lookback. If this count reaches three or more, a boolean flag called isWhipsawing is set to true.
The Regime Logic
This is the heart of the script — the section where the three calculations are combined into a single regime classification. The logic uses three boolean flags computed in a specific priority order.
The first flag is isVol, which is set to true when the BBW percentile rank meets or exceeds the user's volatility threshold. This is checked first because volatility takes priority over everything else in the classification. A market in extreme volatility cannot be considered a clean trend regardless of what ADX says.
The second flag is isTrend, which requires three conditions to all be true. First, the market must not be in VOL state. Second, ADX must be at or above the trend threshold. Third, the whipsaw filter must not be active. Only when all three conditions hold does the indicator classify the market as TREND.
The third flag is isChop, which is the default fallback. It is set to true when the market is neither in VOL nor in TREND, and either ADX is below the chop threshold or whipsawing is active.
This priority structure — VOL first, TREND second, CHOP as fallback — biases the indicator toward conservative classification. If conditions are ambiguous, the indicator defaults to CHOP, which is the regime where the system tells you to stand aside. This bias is intentional because preventing bad trades is more valuable than catching every good one.
The Regime Label, Color, And Code Assignment
After determining which flag is true, the script assigns the appropriate label text, label color, and numeric code to three variables. The label text is one of TREND, CHOP, VOL, or MIXED. The label color is green for TREND, red for CHOP, orange for VOL, and gray for MIXED. The numeric code is one for TREND, negative one for CHOP, two for VOL, and zero for MIXED.
The MIXED state is a defensive fallback that should rarely if ever occur. It exists to handle the theoretical edge case where none of the three primary conditions is true, which can only happen due to floating-point precision issues at exactly the threshold boundaries.
The assignment logic uses if-else if blocks rather than nested ternary expressions. This is a deliberate choice because Pine Script's parser sometimes has trouble with multi-way nested ternaries that mix string and color types. The if-else structure is unambiguous and produces reliable compilation across Pine versions.
The On-Chart Label Display
This section renders the regime classification visually on the chart. The script uses Pine Script's persistent variable mechanism, declaring a label variable with the var keyword that retains its value across bars. On every bar, the script first deletes the previous label and then creates a new one positioned at the high of the current bar.
This delete-and-recreate pattern ensures that only one label exists on the chart at any time, always at the most recent bar. Without this pattern, the script would create a new label on every bar and accumulate hundreds of historical labels, cluttering the chart.
The label uses the style_label_down style, which makes it look like a tag pointing downward at the price bar. The text shows the current regime, the background color matches the regime color, the text itself is white for high contrast, and the size is set to large for visibility.
The Alert Condition
This section enables TradingView users to set up alerts that fire whenever the regime changes from one bar to the next. The script uses Pine Script's history-referencing operator to compare the current regime to the previous bar's regime. When they differ, the regimeChanged boolean is true, and the alertcondition function makes this state available to TradingView's alert engine.
When a user creates an alert in TradingView and selects this script as the source, the Regime Changed condition appears as a selectable trigger. The alert message is a simple text string indicating that the regime has shifted on the current ticker and timeframe. Users can configure delivery via popup, email, mobile push, or webhook depending on their TradingView subscription.
The Hidden Plot
After the alert section, the script includes a single plot statement that outputs the numeric regime code. This plot is hidden from the chart using the display.none parameter, so it does not visually clutter the chart. Its purpose is to make the regime code accessible to other Pine scripts that might want to reference this indicator's output.
For example, if a user later builds a separate strategy script that should only enter trades when the Regime Classifier shows TREND, that strategy can use Pine Script's input source mechanism to read this hidden plot value and gate its trade logic accordingly. The plot is essentially a structured way of exposing the regime decision to downstream automation while keeping the chart clean.
The Diagnostic Table
The final and largest section of the script renders a small information table on the chart showing the indicator's internal state. The table is created once using the var keyword (so it persists across bars) and is positioned according to the user's choice from the Diagnostic Table Position dropdown.
The table has two columns and six rows. The first row shows the Configuration Label, identifying which tuning preset is active on this chart. The second row is a header row labeling the columns as Metric and Value. The remaining four rows show the four diagnostic measurements.
The ADX row displays the current ADX value with two decimal places, color-coded green when above the trend threshold and orange when below. The BBW Rank row shows the current BBW percentile rank, color-coded orange when in volatility territory and white otherwise. The EMA Crosses row shows the count of recent EMA crossings, color-coded red when at or above the whipsaw threshold and white otherwise. The Whipsaw row shows a clean YES or NO indicator with red coloring for YES and green for NO.
The table updates only on the most recent bar by checking the barstate.islast condition. This optimization avoids unnecessary recomputation on historical bars, where the table would not be visible anyway.
The diagnostic table is what makes the indicator transparent rather than a black box. When the user sees a CHOP label and wants to understand why, they can read the table and see exactly which condition is responsible. If ADX is fifteen, the answer is clear — directional momentum has not been confirmed. If Whipsaw is YES, the answer is clear — the market has been crossing the EMA too frequently to be considered trending. This transparency builds user trust in the indicator and helps the user develop intuition about market regime over time.
How The Sections Work Together
Reading the script as a whole, you can trace a clear flow from input to output. The user configures parameters in the inputs section. The position conversion block translates the position selection into the format Pine Script needs. The core calculations transform raw price data into the three measurements (ADX, BBW Rank, Whipsaw count). The regime logic combines these measurements into a single classification. The label and color assignment renders the classification into visible elements. The on-chart label, the alert condition, the hidden plot, and the diagnostic table each consume the classification in different ways — for visual display, for notifications, for downstream automation, and for transparency.
Every section has a single clear purpose. Nothing is duplicated. The script is approximately three hundred lines including comments, but the actual executable Pine code is closer to ninety lines. The comment-to-code ratio reflects the priority on documentation and readability over compactness.
Why It Is Built This Way
The script reflects several deliberate design choices that may not be obvious from reading the code alone.
The choice of three measurements (ADX, BBW Percentile, Whipsaw) rather than one or two reflects the reality that no single technical indicator is reliable across all market conditions. Combining three independent measurements with a priority order significantly reduces the false signals that any one of them would produce alone.
The choice to put the configuration in inputs rather than constants reflects the reality that one set of thresholds cannot fit all markets. A bank index, a tech-heavy index, and a small-cap index have fundamentally different volatility characteristics, and the indicator must be tunable to fit each.
The choice to bias toward CHOP as the default fallback reflects the trading philosophy that protecting capital is more valuable than catching every move. The indicator is designed to keep the user out of bad markets even at the cost of occasionally missing the start of good ones.
The choice to provide a diagnostic table reflects the reality that black-box indicators erode user trust. By showing the user exactly which numbers are driving the classification, the script invites scrutiny rather than blind acceptance.
The choice to write extensive narrative documentation in the comment header reflects the reality that scripts are read by humans, including future versions of yourself, who need to understand the design intent and not just the code mechanics.
These choices add complexity to the script but produce an indicator that is genuinely useful, tunable, transparent, and maintainable.
What This Script Is Not
It is worth noting what this script does not attempt to do. It does not generate buy or sell signals. It does not calculate position sizes. It does not draw entry levels, stops, or targets on the chart. It does not provide a backtesting framework. It does not optimize its own thresholds. It does not access external data feeds.
These omissions are intentional. The script does one thing — classify market regime — and does it cleanly. Other concerns belong in other scripts. A trading system built around this indicator would consist of multiple scripts, each handling a separate concern, with the regime classifier serving as the foundational filter that determines whether the trading system should be active at all.
This separation of concerns is good software architecture in any context. Each script has clear boundaries, can be tested independently, can be improved without breaking other components, and can be replaced if a better version is developed.
In Summary
The Regime Classifier is a Pine Script v6 indicator that classifies any market chart into one of three regimes (TREND, CHOP, VOL) using three independent measurements (ADX, Bollinger Band Width Percentile, EMA Whipsaw Filter) combined with a priority-ordered logic that biases toward conservative classification. It is fully configurable through inputs, transparent through a diagnostic table, deployable across multiple charts with per-chart tuning, alert-enabled for hands-off monitoring, and extensively documented in plain language. It is one component of a larger trading system, focused on the single critical question of whether the current market environment is suitable for trading at all.
The Regime Classifier is a single Pine Script that runs on any chart in TradingView and tells you what kind of market you are looking at. It analyzes the recent price action using three independent measurements and combines them into a single label that reads either TREND, CHOP, or VOL. This label appears as a colored tag at the top right of the most recent price bar, with green meaning the market is trending cleanly, red meaning it is choppy and directionless, and orange meaning it is in a high-volatility unstable phase.
The script is designed to be used across multiple charts — one instance on Nifty 50, another on Bank Nifty, another on Midcap 150, and so on for US indices. Each chart instance can be tuned independently from the indicator settings panel without touching the script itself. This is achieved through a configurable inputs section that exposes every important threshold as an adjustable parameter.
How The Script Is Structured
The script is organized into clearly demarcated sections, each separated by horizontal divider lines made of unicode characters. Reading from top to bottom, the sections are: a comprehensive documentation header, the Pine version declaration and indicator title, the inputs section, a position conversion block, the core calculations, the regime logic, the regime label and color assignments, the on-chart label display, the alert condition, a hidden plot for external referencing, and finally the diagnostic table.
This top-to-bottom flow matches the natural reading order. First you understand what the script does (header), then you see how it can be configured (inputs), then you see what it calculates (core calculations), then you see how those calculations are turned into decisions (regime logic), and finally you see how the decisions are displayed and made available (label, alert, plot, table).
The Documentation Header
The first major section of the script is a long block of comments that explains everything a user needs to know before using the indicator. This block is approximately one hundred lines long and is structured into seven distinct parts.
The first part explains what the indicator does in plain language, describing each of the three regimes — TREND, CHOP, and VOL — with their visual signature on the chart and the trading behavior recommended in each. The second part explains how the indicator makes its decisions, walking through the three underlying measurements (ADX, Bollinger Band Width Percentile, and EMA Whipsaw Filter) and explaining why each was chosen and what role it plays.
The third part is a detailed tuning guide showing recommended threshold values for seven different indices spanning Indian and US markets. This table is the most practical piece of documentation in the script because it tells the user exactly which numbers to enter when configuring the indicator on a specific chart.
The fourth part describes the diagnostic table, explaining what each row means and how to interpret the color coding. The fifth part is a deliberate disclosure of the indicator's limitations — what it cannot do, where it lags, and why these limitations are acceptable. The sixth part explains how to set up TradingView alerts using the indicator's built-in alert condition. The seventh part contains author and license information.
This entire header serves as both onboarding documentation for new users and a future reference for the author when revisiting the script after months away.
The Indicator Declaration
After the header comes the Pine version declaration and the indicator title. The script is written for Pine Script version 6, which is the current standard. The title is intentionally region-neutral, reading simply Regime Classifier with the three regime names listed. This neutrality matters because the same script is used across many different markets and indices, so the title should not imply it is specific to any one of them.
The overlay parameter is set to true, which means the indicator draws on top of the price chart rather than creating its own pane below the chart. This is the right choice for an indicator that places labels and tables on the chart but does not plot any price-like values that need their own scale.
The Inputs Section
The inputs section exposes every adjustable parameter to the user through TradingView's settings panel. There are nine inputs in total, organized into four logical groups.
The first input is the Configuration Label, which is a dropdown menu containing eight options corresponding to seven different indices plus a Custom option for any other instrument. This label is purely informational — it does not affect calculations. Its purpose is to give the user a clear visual indicator on each chart of which tuning preset is active. When you have multiple charts open, this label tells you at a glance whether you are looking at the Nifty 50 instance, the Bank Nifty instance, or another configuration.
The second input is the Diagnostic Table Position, which is another dropdown menu with nine options corresponding to the nine standard positions where Pine Script can place a table on a chart. This input lets the user move the diagnostic table to wherever it best fits the chart layout without having to edit the script.
The next group of inputs concerns the ADX calculation. The ADX Length controls the lookback period for the indicator (defaulting to fourteen, the classical value). The ADX Trend Threshold sets the value above which ADX is considered to confirm a trending market. The ADX Chop Threshold sets the value below which ADX contributes to a chop classification.
The third group concerns Bollinger Band Width. The Bollinger Length controls the period for the band calculation. The Bollinger StdDev controls how wide the bands are relative to the middle line. The BBW Percentile Lookback determines how many bars of history the current band width is ranked against. The BBW Volatility Percentile sets the threshold above which the indicator flags VOL.
The fourth group concerns the EMA Whipsaw Filter. The EMA Length sets the period of the moving average used to detect whipsawing. The EMA Whipsaw Lookback determines how many recent bars are checked for crossover counts.
Every input has a tooltip that explains its purpose when the user hovers over it in the settings panel. This makes the indicator self-documenting at the point of use.
The Position Conversion Block
After the inputs comes a small but important block that converts the user's selection from the Diagnostic Table Position dropdown into the actual Pine Script position constant required by the table.new function. The dropdown stores the user's choice as a text string like "Top Right" or "Bottom Left," but Pine Script's table function requires a specific built-in constant such as position.top_right or position.bottom_left.
The conversion block uses an if-else if chain to map each text option to its corresponding constant. The result is stored in a variable called posConstant, which is later used when creating the diagnostic table. This indirection is necessary because Pine Script does not allow dynamic position selection at the table creation point — you cannot pass a string variable directly. The conversion block solves this with a small one-time mapping.
The Core Calculations
This section computes the three underlying measurements that the regime logic depends on.
The first calculation is the ADX. The script uses Pine Script's built-in ta.dmi function, which returns three values — the Plus Directional Indicator, the Minus Directional Indicator, and the ADX itself. The script captures all three but uses only the ADX value for trend strength assessment. The other two are kept available for potential future enhancement but are not currently consumed.
The second calculation produces the Bollinger Band Width. The script first computes the Simple Moving Average over the configured length, then computes the standard deviation of price over the same length, then constructs the upper and lower bands by adding and subtracting a multiple of the standard deviation from the moving average. The band width is calculated as the upper minus the lower, divided by the middle, which normalizes the width to be comparable across instruments at different price levels.
After computing the raw band width, the script ranks it against its own history using the percentrank function. This produces a value between zero and one hundred indicating where the current band width falls compared to the previous one hundred bars (or whatever lookback the user configured). A value of ninety means the current width is wider than ninety percent of recent history, indicating volatility expansion.
The third calculation is the EMA whipsaw count. The script computes a twenty-period exponential moving average, then identifies every bar where price crossed above the EMA (a crossover) or below the EMA (a crossunder) within the recent lookback window. It sums these events to get a total cross count over the lookback. If this count reaches three or more, a boolean flag called isWhipsawing is set to true.
The Regime Logic
This is the heart of the script — the section where the three calculations are combined into a single regime classification. The logic uses three boolean flags computed in a specific priority order.
The first flag is isVol, which is set to true when the BBW percentile rank meets or exceeds the user's volatility threshold. This is checked first because volatility takes priority over everything else in the classification. A market in extreme volatility cannot be considered a clean trend regardless of what ADX says.
The second flag is isTrend, which requires three conditions to all be true. First, the market must not be in VOL state. Second, ADX must be at or above the trend threshold. Third, the whipsaw filter must not be active. Only when all three conditions hold does the indicator classify the market as TREND.
The third flag is isChop, which is the default fallback. It is set to true when the market is neither in VOL nor in TREND, and either ADX is below the chop threshold or whipsawing is active.
This priority structure — VOL first, TREND second, CHOP as fallback — biases the indicator toward conservative classification. If conditions are ambiguous, the indicator defaults to CHOP, which is the regime where the system tells you to stand aside. This bias is intentional because preventing bad trades is more valuable than catching every good one.
The Regime Label, Color, And Code Assignment
After determining which flag is true, the script assigns the appropriate label text, label color, and numeric code to three variables. The label text is one of TREND, CHOP, VOL, or MIXED. The label color is green for TREND, red for CHOP, orange for VOL, and gray for MIXED. The numeric code is one for TREND, negative one for CHOP, two for VOL, and zero for MIXED.
The MIXED state is a defensive fallback that should rarely if ever occur. It exists to handle the theoretical edge case where none of the three primary conditions is true, which can only happen due to floating-point precision issues at exactly the threshold boundaries.
The assignment logic uses if-else if blocks rather than nested ternary expressions. This is a deliberate choice because Pine Script's parser sometimes has trouble with multi-way nested ternaries that mix string and color types. The if-else structure is unambiguous and produces reliable compilation across Pine versions.
The On-Chart Label Display
This section renders the regime classification visually on the chart. The script uses Pine Script's persistent variable mechanism, declaring a label variable with the var keyword that retains its value across bars. On every bar, the script first deletes the previous label and then creates a new one positioned at the high of the current bar.
This delete-and-recreate pattern ensures that only one label exists on the chart at any time, always at the most recent bar. Without this pattern, the script would create a new label on every bar and accumulate hundreds of historical labels, cluttering the chart.
The label uses the style_label_down style, which makes it look like a tag pointing downward at the price bar. The text shows the current regime, the background color matches the regime color, the text itself is white for high contrast, and the size is set to large for visibility.
The Alert Condition
This section enables TradingView users to set up alerts that fire whenever the regime changes from one bar to the next. The script uses Pine Script's history-referencing operator to compare the current regime to the previous bar's regime. When they differ, the regimeChanged boolean is true, and the alertcondition function makes this state available to TradingView's alert engine.
When a user creates an alert in TradingView and selects this script as the source, the Regime Changed condition appears as a selectable trigger. The alert message is a simple text string indicating that the regime has shifted on the current ticker and timeframe. Users can configure delivery via popup, email, mobile push, or webhook depending on their TradingView subscription.
The Hidden Plot
After the alert section, the script includes a single plot statement that outputs the numeric regime code. This plot is hidden from the chart using the display.none parameter, so it does not visually clutter the chart. Its purpose is to make the regime code accessible to other Pine scripts that might want to reference this indicator's output.
For example, if a user later builds a separate strategy script that should only enter trades when the Regime Classifier shows TREND, that strategy can use Pine Script's input source mechanism to read this hidden plot value and gate its trade logic accordingly. The plot is essentially a structured way of exposing the regime decision to downstream automation while keeping the chart clean.
The Diagnostic Table
The final and largest section of the script renders a small information table on the chart showing the indicator's internal state. The table is created once using the var keyword (so it persists across bars) and is positioned according to the user's choice from the Diagnostic Table Position dropdown.
The table has two columns and six rows. The first row shows the Configuration Label, identifying which tuning preset is active on this chart. The second row is a header row labeling the columns as Metric and Value. The remaining four rows show the four diagnostic measurements.
The ADX row displays the current ADX value with two decimal places, color-coded green when above the trend threshold and orange when below. The BBW Rank row shows the current BBW percentile rank, color-coded orange when in volatility territory and white otherwise. The EMA Crosses row shows the count of recent EMA crossings, color-coded red when at or above the whipsaw threshold and white otherwise. The Whipsaw row shows a clean YES or NO indicator with red coloring for YES and green for NO.
The table updates only on the most recent bar by checking the barstate.islast condition. This optimization avoids unnecessary recomputation on historical bars, where the table would not be visible anyway.
The diagnostic table is what makes the indicator transparent rather than a black box. When the user sees a CHOP label and wants to understand why, they can read the table and see exactly which condition is responsible. If ADX is fifteen, the answer is clear — directional momentum has not been confirmed. If Whipsaw is YES, the answer is clear — the market has been crossing the EMA too frequently to be considered trending. This transparency builds user trust in the indicator and helps the user develop intuition about market regime over time.
How The Sections Work Together
Reading the script as a whole, you can trace a clear flow from input to output. The user configures parameters in the inputs section. The position conversion block translates the position selection into the format Pine Script needs. The core calculations transform raw price data into the three measurements (ADX, BBW Rank, Whipsaw count). The regime logic combines these measurements into a single classification. The label and color assignment renders the classification into visible elements. The on-chart label, the alert condition, the hidden plot, and the diagnostic table each consume the classification in different ways — for visual display, for notifications, for downstream automation, and for transparency.
Every section has a single clear purpose. Nothing is duplicated. The script is approximately three hundred lines including comments, but the actual executable Pine code is closer to ninety lines. The comment-to-code ratio reflects the priority on documentation and readability over compactness.
Why It Is Built This Way
The script reflects several deliberate design choices that may not be obvious from reading the code alone.
The choice of three measurements (ADX, BBW Percentile, Whipsaw) rather than one or two reflects the reality that no single technical indicator is reliable across all market conditions. Combining three independent measurements with a priority order significantly reduces the false signals that any one of them would produce alone.
The choice to put the configuration in inputs rather than constants reflects the reality that one set of thresholds cannot fit all markets. A bank index, a tech-heavy index, and a small-cap index have fundamentally different volatility characteristics, and the indicator must be tunable to fit each.
The choice to bias toward CHOP as the default fallback reflects the trading philosophy that protecting capital is more valuable than catching every move. The indicator is designed to keep the user out of bad markets even at the cost of occasionally missing the start of good ones.
The choice to provide a diagnostic table reflects the reality that black-box indicators erode user trust. By showing the user exactly which numbers are driving the classification, the script invites scrutiny rather than blind acceptance.
The choice to write extensive narrative documentation in the comment header reflects the reality that scripts are read by humans, including future versions of yourself, who need to understand the design intent and not just the code mechanics.
These choices add complexity to the script but produce an indicator that is genuinely useful, tunable, transparent, and maintainable.
What This Script Is Not
It is worth noting what this script does not attempt to do. It does not generate buy or sell signals. It does not calculate position sizes. It does not draw entry levels, stops, or targets on the chart. It does not provide a backtesting framework. It does not optimize its own thresholds. It does not access external data feeds.
These omissions are intentional. The script does one thing — classify market regime — and does it cleanly. Other concerns belong in other scripts. A trading system built around this indicator would consist of multiple scripts, each handling a separate concern, with the regime classifier serving as the foundational filter that determines whether the trading system should be active at all.
This separation of concerns is good software architecture in any context. Each script has clear boundaries, can be tested independently, can be improved without breaking other components, and can be replaced if a better version is developed.
In Summary
The Regime Classifier is a Pine Script v6 indicator that classifies any market chart into one of three regimes (TREND, CHOP, VOL) using three independent measurements (ADX, Bollinger Band Width Percentile, EMA Whipsaw Filter) combined with a priority-ordered logic that biases toward conservative classification. It is fully configurable through inputs, transparent through a diagnostic table, deployable across multiple charts with per-chart tuning, alert-enabled for hands-off monitoring, and extensively documented in plain language. It is one component of a larger trading system, focused on the single critical question of whether the current market environment is suitable for trading at all.
Versionshinweise
Part 6: Important Notes On The New FeaturesA few things worth knowing about how to actually use the new features:
The MA Suite:
You now have 5 MAs available. By default, MA1 (9), MA2 (21), MA3 (50), and MA5 (200) are enabled. MA4 (100) is disabled. You can toggle each on or off and change their lengths from the settings panel. If you have other MA indicators on the chart, disable those — this single indicator now handles all of them.
The RS Lead Counter:
For Indian stocks, leave the benchmark as NSE:NIFTY. For US stocks, change it to SP:SPX or NASDAQ:NDX. The counter only counts when the stock is in TREND while the benchmark is not. A counter of 5 or more is meaningful — that's a leadership signal. A counter of 0 means either the stock is not trending, or both stock and benchmark are trending (no relative strength edge).
The Long-Term Bias:
This is independent of regime. A stock can be CHOP regime but BULLISH bias (consolidating in an uptrend). This is often the highest-quality setup environment — patient consolidation in a long-term uptrend. Conversely, a stock that is TREND regime but BEARISH bias is in a counter-trend bounce — much lower quality.
Use The Bias To Filter Direction:
BULLISH bias + TREND regime = strong long candidate
BEARISH bias + TREND regime = strong short candidate (or avoid if long-only)
Bias and regime conflict = caution, often counter-trend trades
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.