Calculate first, then assign the upper and lower labels
Zerodha documents the HLC formulas; Frank Ochoa explicitly notes that their TC and BC results can exchange positions. Keep raw values during debugging, then assign chart labels by numerical order. The pivot is halfway between the two outer levels. If both outer values are equal, all three lines coincide. That happens when the close equals the high-low midpoint, because width is two thirds of the absolute distance between those two prices.
| Value | Calculation | Meaning |
|---|
| Pivot | (H + L + C) / 3 | Central line |
| Raw BC | (H + L) / 2 | Midpoint of the reference high and low |
| Raw TC | 2 × Pivot - raw BC | Reflection of raw BC across Pivot |
| Displayed BC | min(raw BC, raw TC) | Lower boundary |
| Displayed TC | max(raw BC, raw TC) | Upper boundary |
| Width | Displayed TC - displayed BC | Nonnegative distance between boundaries |
Three hypothetical closes show why sorting matters
Assume a completed reference session has H = 110 and L = 90, in price points. Change only its closing price. Keep full precision internally and round for display. These invented inputs test arithmetic; they do not describe a traded instrument.
- For C = 97: Pivot = (110 + 90 + 97) / 3 = 99; raw TC = 198 - 100 = 98. Plotting raw TC as the upper boundary would invert the range.
- For C = 100.30: Pivot = 300.30 / 3 = 100.10. The next-session band is 100.00 to 100.20, despite the reference session having a 20-point high-low range.
| Close | Pivot | Raw BC | Raw TC | Displayed BC / TC | Width |
|---|
| 103 | 101 | 100 | 102 | 100 / 102 | 2 |
| 97 | 99 | 100 | 98 | 98 / 100 | 2 |
| 100.30 | 100.10 | 100 | 100.20 | 100 / 100.20 | 0.20 |
A narrow CPR does not measure the whole price path
Let M = (H + L) / 2. Substitution gives width = abs(2 × Pivot - 2 × M) = (2 / 3) × abs(C - M). This is an algebraic consequence of the formulas. A close at M creates zero width even if the high-low range is large. CPR alone cannot establish how much time price spent consolidating or which direction the next session will take.
- Ochoa describes unusually narrow ranges as a guide to potential trending behavior and warns that the method can fail. Treat that as a hypothesis to test, not an implication of the formula.
- Define narrow before inspecting outcomes. For a research test, one possible rule is width below the 20th percentile of the previous 60 completed widths. That is a proposed definition, not an established best setting.
- Keep the symbol, reference period, and session policy consistent in that comparison. Width alone supplies neither a direction nor an entry price.
An opening move above the band can fail immediately
Continue the third calculation: BC = 100.00, Pivot = 100.10, TC = 100.20. Assume a session starting at 09:30 and standard five-minute bars. Before the open, define this observation rule: an open above TC starts an upward hypothesis; the first completed bar closing at or below TC cancels it for that session. This is a demonstration rule, not a trade recommendation.
- The narrow band remains exactly 0.20 wide throughout this path. Its arithmetic has not failed; the opening continuation hypothesis has.
- A wick-based cancellation would occur at a different time. Record whether the rule uses intrabar touches or completed closes before comparing alerts.
- Canceling an observation is not a simulated stop fill. A strategy still needs order timing, exits, sizing, fees, and slippage before any profit or loss can be calculated.
| Observation time | Hypothetical price | Rule status |
|---|
| 09:30 open | 100.60 | Above TC by 0.40; upward hypothesis starts |
| 09:35 first bar close | 100.35 | Still above TC; hypothesis remains active |
| 09:40 second bar close | 99.90 | Below TC and BC; hypothesis is canceled |
| 09:45 third bar close | 100.10 | Inside CPR; no restart under the stated rule |
Check the reference period on TradingView
For a daily CPR on an intraday chart, use the prior completed daily HLC and make the resulting levels available when the next daily period begins. A weekly CPR requires the prior completed week. The chart interval and reference interval are separate choices; inspect the selected script rather than assuming all CPR indicators use the same defaults.
- TradingView documents that unconfirmed higher-timeframe data can change during live bars. A developing CPR based on the current day is a different calculation and should be labeled separately.
- When reviewing Pine higher-timeframe requests, check that they retrieve confirmed prior values with consistent historical and live timing. Do not expose the final high, low, or close before that source period has finished.
- Reload the chart and compare saved values around a period boundary. Stable arithmetic does not compensate for a different data source or a history-versus-live timing mismatch.
| Check | Expected behavior for a fixed daily CPR |
|---|
| Source candle | H, L, and C all come from the same completed daily candle |
| Session and feed | Record the symbol, feed, session selection, and source daily candle boundaries |
| During the next day | The three reference levels stay fixed; live prices change their relationship to the band |
| New reference period | Levels update from the newly completed source candle |
| Missing source candle | Show unavailable and suppress dependent alerts; do not substitute zero |
Turn the calculation into a Pineify implementation request
Give the Pine Script AI Coding Agent the source period, session policy, raw formulas, sorted plot labels, and alert confirmation rule. Ask it to expose H, L, C, raw BC, raw TC, Pivot, and sorted boundaries so that you can compare its output with the table above.
- Use the C = 97 row to check inverted raw boundaries and the C = 100.30 row to check a narrow band. Also test a midpoint close, missing data, and the first bar of a new reference period.
- Request a fixed prior-period indicator first. Check the generated source and syntax result, then verify bar values and alert timestamps on TradingView.
- Only after those checks, define entries, exits, sizing, and costs for a separate strategy test. The three plotted levels do not determine those choices.