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.
| Field | Frozen example specification |
|---|
| Chart context | One exchange-qualified symbol, standard daily candles, a fixed session and adjustment setting. Save the timezone and data retrieval date. |
| Trend input | TradingView DMI with DI length 14 and ADX smoothing 14. Use its ADX value at the completed daily close. |
| Trend state | Two consecutive closes with ADX >= 25 confirm Trend. Two consecutive closes with ADX <= 20 confirm Range-proxy. Otherwise retain the previous confirmed state. |
| Initialization | Start Unknown. A value between 20 and 25 cannot initialize a state. A failed threshold condition resets that threshold's consecutive-close count. |
| Volatility input | ATR length 14 with RMA smoothing. ATR% = 100 × ATR / close, using a positive close. |
| Volatility state | High when ATR% >= 2%; Normal when ATR% < 2%. This axis updates at every completed close without the two-close trend confirmation. |
| Unavailable data | Missing 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.
| Bar | ADX | ATR / close | Output after close | Reason |
|---|
| 1 | 26 | 1.50 / 100 = 1.50% | Range-proxy / Normal | First ADX >= 25 reading; no confirmation yet. |
| 2 | 27 | 2.40 / 100 = 2.40% | Trend / High | Second qualifying reading confirms Trend. |
| 3 | 23 | 2.00 / 100 = 2.00% | Trend / High | Middle band retains Trend; equality belongs to High. |
| 4 | 19 | 1.80 / 100 = 1.80% | Trend / Normal | First ADX <= 20 reading; Trend is retained. |
| 5 | 18 | 1.70 / 100 = 1.70% | Range-proxy / Normal | Second 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 reference | Predicted Trend | Predicted Range-proxy | Total |
|---|
| Trend | 2 | 1 | 3 |
| Range-proxy | 2 | 5 | 7 |
| Total | 4 | 6 | 10 |
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.
| Approach | Useful output | Boundary to test |
|---|
| ADX and ATR% rules | A reproducible label and an exact explanation for each switch. | Threshold sensitivity, lag, missing inputs, and rapid oscillation near cutoffs. |
| Markov-switching model | Estimated state probabilities and transition probabilities under a specified model. | State count, distribution assumptions, convergence, rare states, and parameter stability after refitting. |
| Retrospective segmentation | A 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.