TradingView research workflows

Market regime detection on TradingView

Market regime detection assigns a label to observable market conditions under a stated rule or fitted model. On TradingView, define trend strength and volatility separately, record when each label becomes available, then test the frozen definition on later data. A regime label describes the information used to create it; it does not establish the next price move or prove that a strategy will profit.

See the decision guide

A trending vs ranging market is a definition to test

TradingView describes ADX as a measure of trend strength. It does not identify direction by itself. ATR% measures the size of recent true ranges relative to price. A strong trend can have either high or low volatility, so combining these into a single bull-or-bear label loses information. The following two-axis definition is an illustrative research specification, not a validated trading system.

  • The 20, 25, and 2% thresholds are example choices. Select or estimate them using training data and record all alternatives tried; they are not universal market boundaries.
  • Range-proxy means low ADX under this rule. It does not prove a bounded trading range or mean reversion. Record direction separately if your question requires it.
  • For a percentile-based volatility cutoff, specify the percentile method and estimate it on training data only. If the cutoff rolls, predeclare the trailing window and use only information available at each close.
FieldFrozen example specification
Chart contextOne exchange-qualified symbol, standard daily candles, a fixed session and adjustment setting. Save the timezone and data retrieval date.
Trend inputTradingView DMI with DI length 14 and ADX smoothing 14. Use its ADX value at the completed daily close.
Trend stateTwo consecutive closes with ADX >= 25 confirm Trend. Two consecutive closes with ADX <= 20 confirm Range-proxy. Otherwise retain the previous confirmed state.
InitializationStart Unknown. A value between 20 and 25 cannot initialize a state. A failed threshold condition resets that threshold's consecutive-close count.
Volatility inputATR length 14 with RMA smoothing. ATR% = 100 × ATR / close, using a positive close.
Volatility stateHigh when ATR% >= 2%; Normal when ATR% < 2%. This axis updates at every completed close without the two-close trend confirmation.
Unavailable dataMissing inputs or a nonpositive close produce Unknown, reset confirmation counts, and suppress state-change alerts. The first valid state after Unknown is initialization, not a transition.

Worked transition log: confirmation has a cost

Assume the prior state was already confirmed as Range-proxy, the prior qualifying streaks are zero, and all inputs below are valid. These invented readings demonstrate the rule, not observed market performance. Each row is one completed daily candle; the output becomes available only at its close.

  • The trend state changes twice across four adjacent pairs: 2 / 4 = 50%. The initial state before bar 1 is excluded from that denominator. A larger sample is needed to interpret switching frequency.
  • Trend confirmation occurs one completed bar after the first threshold crossing. This is mechanical confirmation delay, not measured delay from an independently known market turning point.
  • A sequence of ADX 26, 24, 27 never has two consecutive readings at or above 25. From Range-proxy it remains Range-proxy, even if the chart appears to be trending.
  • The two axes change independently. At bar 4 the output is Trend / Normal. Avoid interpreting a volatility decline as an automatic trend reversal.
BarADXATR / closeOutput after closeReason
1261.50 / 100 = 1.50%Range-proxy / NormalFirst ADX >= 25 reading; no confirmation yet.
2272.40 / 100 = 2.40%Trend / HighSecond qualifying reading confirms Trend.
3232.00 / 100 = 2.00%Trend / HighMiddle band retains Trend; equality belongs to High.
4191.80 / 100 = 1.80%Trend / NormalFirst ADX <= 20 reading; Trend is retained.
5181.70 / 100 = 1.70%Range-proxy / NormalSecond qualifying reading confirms Range-proxy.

Freeze a chronological training and validation protocol

For an example experiment, use 2023 through 2024 for development and January through June 2025 for validation, provided those dates were unseen when the rule was chosen. If you have already inspected them, reserve a later untouched interval. Dates alone do not make a sample independent. Record the exact split before evaluating results.

  • During training, choose features, thresholds, confirmation length, reference labels, and acceptance criteria. Preserve failed variants and the number of trials.
  • Calculate indicators from an earlier warm-up period. Carry their causal history and confirmed state into validation, but do not use validation results to choose settings. List excluded warm-up and unavailable observations.
  • At each validation close, append inputs, output state, prior state, timestamp, and rule version. Save screenshots at the time of observation or label historical screenshots as retrospective.
  • If evaluation labels require the next five candles, exclude training observations whose five-candle label window enters validation. Those future candles may score a past prediction later; they must never feed the original signal.
  • If you retune after seeing validation, call that period development and reserve a new holdout. In a rolling study, refit only at predeclared dates with data then available.
  • Keep the same symbol, session, timeframe, and adjustment settings across comparisons. Test a second market separately before assuming that its price and volatility distribution are interchangeable.

Measure errors without inventing ground truth

Market regimes are usually latent, so classification accuracy requires an explicit reference definition. Reusing the same ADX thresholds as both classifier and truth only checks implementation. A future-window label, independently specified annotation, or simulated known state answers a different question; document which one you use and when it becomes available.

  • This invented matrix contains ten scored, available observations: accuracy = (2 + 5) / 10 = 70%; Trend precision = 2 / 4 = 50%; Trend recall = 2 / 3 = 66.7%. An always-Range-proxy baseline also scores 7 / 10 = 70%. Accuracy alone hides missed trends and false trend labels.
  • Report Unknown coverage separately. If two additional observations were Unknown, scored coverage is 10 / 12 = 83.3%. Do not silently remove difficult observations or call Unknown a correct classification.
  • For lag, predeclare how reference transitions match detected transitions, the maximum matching window, and treatment of early or unmatched signals. Report median and worst matched delay, missed transitions, and false transitions separately.
  • Measure state duration, switches per 100 eligible adjacent pairs, and performance around transitions. Adjacent candles share information; ten rows are not ten independent experiments.
  • A filter that labels conditions well can still reduce net strategy returns. Compare the same strategy with and without the filter over the same dates, with costs, exposure, trade count, and drawdown reported separately.
Hypothetical referencePredicted TrendPredicted Range-proxyTotal
Trend213
Range-proxy257
Total4610

Rule-based labels versus statistical regime models

A rule-based detector makes the definition and its threshold behavior directly inspectable. A hidden-state or Markov-switching model estimates latent states under statistical assumptions. The statsmodels example distinguishes filtered probabilities, which use observations through the current time, from smoothed probabilities, which use the full sample. Smoothed historical states are not contemporaneous signals.

  • Filtered probabilities still leak information if their parameters were estimated on the entire future sample. Fit on training data, then filter forward under a frozen or causally updated model.
  • State numbers have no inherent financial meaning. Assign names from training characteristics and preserve that mapping when evaluating; a refit may reorder states.
  • Compare models on the same available observations and the same evaluation definition. Additional states or attractive retrospective colors do not establish better live decisions.
ApproachUseful outputBoundary to test
ADX and ATR% rulesA reproducible label and an exact explanation for each switch.Threshold sensitivity, lag, missing inputs, and rapid oscillation near cutoffs.
Markov-switching modelEstimated state probabilities and transition probabilities under a specified model.State count, distribution assumptions, convergence, rare states, and parameter stability after refitting.
Retrospective segmentationA description of historical episodes using the full sample.Future information may explain history but cannot support an earlier alert.

Keep TradingView alerts consistent with the experiment

TradingView documents that values on an open candle can change and that higher-timeframe requests can repaint when they use unconfirmed data. For this daily-close specification, accept labels only at the completed daily close. A chart-timeframe close does not confirm a still-open daily candle on an intraday chart.

  • Start with the stated daily chart and matching indicators. Record the values in the Data Window and reconcile a few threshold, equality, and reset cases by hand.
  • If implementing a custom overlay, request separate trend and volatility outputs, explicit Unknown handling, and alerts only for valid confirmed state changes. Initialization should not create a false transition.
  • Compare saved realtime observations with the chart after reloading. Record feed revisions, session changes, or a changed history start instead of rewriting the original observation.
  • A completed-close label cannot justify a fill earlier in that candle. Keep the label timestamp separate from the order timestamp and test execution assumptions independently.

Build the chart aid and preserve the research record

Pineify Pine Script AI Coding Agent can draft a chart indicator from your written specification. Give it the complete state table, initialization, confirmation counts, and alert timing; then request syntax checking and compare the generated output with the worked cases. Compilation checks syntax, not whether the labels are useful or predictive.

  • Use a named setup such as Regime-v1 in Trading Journal and put the frozen hypothesis and rule in its description. Session notes can hold the run ID, split, observed transitions, errors, and review decision.
  • Save chart screenshots in your own research folder and put their filenames or links in the session notes. This workflow does not assume a built-in screenshot attachment or automatic TradingView synchronization.
  • Keep a separate row-level log for the matrix and transition calculations. Journal notes organize the review; they do not automatically fit a regime model or calculate classification accuracy.
  • Record a rejected or inconclusive result with its original version. A later rule revision should not overwrite the assumptions that produced earlier labels.
Where Pineify fits

Pine Script AI Coding Agent

Turn the written state and alert specification into a draft chart indicator, request syntax checking, and verify its outputs against your saved cases.

Also useful: Trading Journal. Keep the hypothesis, rule version, screenshot references, and review decisions in setup descriptions and session notes.

Explore Pine Script AI Coding Agent

Frequently asked questions

Educational information, not investment advice. Thresholds, readings, dates, and classification counts are illustrative research choices, not validated trading recommendations. Regime labels, backtests, and generated indicators do not guarantee predictions or profits.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.