OPEN-SOURCE SCRIPT

Stochastic Intrabar Evidence

288
Stochastic Intrabar Evidence examines a question that a close-only stochastic chart cannot answer on its own: if the oscillator opened and closed on the same side of its reference, did it necessarily visit the opposite side inside that candle?

The indicator separates what a completed OHLC candle requires, leaves unresolved, or excludes. It combines familiar K/D lines with mathematically bounded intrabar evidence, excursion depth and an auditable event selection. It uses chart OHLC only, without requesting lower-timeframe data or inventing an observed tick path.

Its practical purpose is to distinguish an excursion established by the OHLC model from one that is merely possible. This is a completed-bar diagnostic for reviewing oscillator behavior, not an early signal, trade recommendation or performance forecast.

1. What to read first

The defaults are a 14-bar stochastic range, 3-period K smoothing, 3-period D smoothing and SMA. Cyan is K; gold is D. All evidence uses completed candles.

Evidence subject defaults to K versus D. Alternatives compare K with the upper or lower fixed reference, initially 80 and 20. The strict-side margin defaults to 0.05 oscillator points, not 0.05 percent and not a price tick. For K-D, above means greater than +0.05 and below means less than -0.05, subject to a separate numerical guard.

The opening oscillator position is calculated using this candle's Open and its opening running range. It is not the previous candle's closing oscillator value.

The primary verdict applies when the opening and closing positions are on the same strict side:

REQUIRED: every price-observation sequence compatible with the model visits the opposite side beyond the margin. This is a mathematical statement under the stated assumptions, not certainty about a trade.

UNRESOLVED: both a visit and a no-visit sequence fit the same OHLC. The indicator cannot establish which occurred. This is neither a known historical excursion nor a probability estimate.

EXCLUDED: no compatible sequence makes that margin-exceeding opposite-side visit. Smaller movements inside the margin are not excluded; future continuation is not implied.

BOUNDARY: an extremal bound is too close to a classification threshold for a definitive verdict. The separate numerical guard is 0.0000001 oscillator point.

NO SAME-SIDE PAIR: the opening and closing positions differ in side, or an endpoint is near the reference. This is not equivalent to EXCLUDED.

UNAVAILABLE: the data, retained range or calculation warm-up is insufficient.

2. Marker legend and excursion depth

Mint circle: REQUIRED opposite-side visit.
Amber diamond: UNRESOLVED opposite-side visit.
Upper lane: an upper-side visit while both endpoints are below the reference.
Lower lane: a lower-side visit while both endpoints are above the reference.

These are oscillator-side directions, not buy/sell signals or forecasts of price direction. Markers become available only after the candle closes.

The default Side lanes place marks above 100 or below 0 for separation from K/D. These coordinates are layout positions, not out-of-range stochastic readings. Lane gap is adjustable. Optional UP/DN text adds a question mark to unresolved marks; it is off by default to reduce clutter.

Evidence bounds is an alternative placement: circles use the required K extremum and diamonds the outer possible K extremum. These anchors remain bounds, not measured tick extrema.

Depth R / P reports required and possible maximum penetration beyond the opposite-side margin, in nonnegative oscillator points. An unresolved visit has zero required depth. Depth distinguishes a marginal excursion from a deeper one without treating either as a better trade.

The detailed Extreme R / P row uses signed extrema relative to K-D or K-level. Lower-side visits use minima, so the possible value can be more negative than the required value. Upper-side visits use maxima. Classification uses unrounded numbers; a positive depth smaller than the display unit is shown as less than that unit instead of zero.

3. Practical workflow

Start with standard candles and the default settings. Check the inspector's evidence-bar time before interpreting its verdict.

Use REQUIRED to identify a within-candle excursion that the two endpoints omit. Treat UNRESOLVED as a limit of the available data, not as a weaker confirmed event. Use EXCLUDED only to rule out the particular margin-exceeding visit under examination.

Then inspect Depth R / P and, when needed, the extrema bounds. Use All evidence (audit) when reviewing every qualifying candle instead of only changes in the event stream. Any trading application needs separate validation with an explicit rule, execution assumptions and costs.

4. Event selection, hidden marks and notifications

An eligible evidence event is a REQUIRED or UNRESOLVED same-side visit. The default Event repetition setting, Class or direction changes, reduces consecutive events with the same class and direction. A nonqualifying candle resets the comparison, so the same class may be reported again afterward.

Important: a change in depth alone does not create a new default event. A much deeper visit can therefore produce no new marker or event notification if its class and direction repeat. Select Every qualifying bar when that reduction is inappropriate for your research.

Marker mode offers three choices:
- Event stream: follow the selected repetition rule.
- All evidence (audit): bypass repetition and spacing; select every eligible evidence event.
- Spaced event stream: apply the repetition rule, then minimum marker spacing.

The default visible marker window is 160 chart bars. Counts show selected/all eligible events and the hidden total in that same window. A forming candle occupies a window slot but has no event marker. Older marks are display-clipped, not removed from historical calculations.

Counts describe coded selection, not actual alert delivery. Manually hiding individual plots in the Style tab is not detectable by Pine and does not change these counts or eligibility rules.

5. Inspector and historical inspection

Quick read is the default six-row inspector at Normal text size. It summarizes K/D, the opposite-side verdict, depth, evidence-bar times, marker counts and notification scope. Other pages are Decision, Extrema and endpoints, Event audit and Reading guide.

The inspector describes the latest completed candle, not the historical candle under the cursor. While a new candle is forming, it refers to the previous candle and indicates one chart bar of distance. This is not elapsed wall-clock time. For historical evidence, use the Data Window.

The time zone is explicit and defaults to UTC. Pine cannot read the chart's display time zone; select the desired evidence zone separately. Quick read compresses redundant date/time fields without dropping necessary sub-minute precision. Detailed pages, tooltips and descriptive alerts retain full timestamps. These are candle boundaries, not excursion times.

Sixteen evidence series supplement K/D in the Data Window: opening K; four K-extrema bounds; uncertainty width; above/below classes; same-side visit class; visit direction; two signed opposite extrema; two penetration depths; selected-mark flag before history clipping; and event-notification eligibility.

Class codes are 0 excluded, 1 unresolved, 2 required and 3 numerical boundary. Undefined data or absent context stays undefined where applicable. The secondary above/below detail uses FORCED/POSSIBLE terminology; an endpoint alone may imply those states, so they are not the main event diagnostic.

6. Alert setup

Adding the indicator does not create a running alert.

For detailed messages, leave Enable descriptive alert() messages enabled and create one TradingView alert using Any alert() function call. The script calls alerts only at bar close. Messages identify the symbol, timeframe, evidence-bar times, time zone, relation, margin, direction, class, signed extrema and depth. Coincident optional state information is combined into one message.

Event notification scope defaults to Match marker selection. This follows the same selection gate as the marks, including audit/spaced mode and Show directional event marks. Turning marks off suppresses matching event notices. On a realtime close, the newest event is within the visible marker window.

All event-stream events ignores marker visibility and spacing but still follows Event repetition. It does not include audit-only extra marks unless those also qualify for the selected event stream.

Optional endpoint-state notices are a separate channel and default to Off. Class change only reports changes in the above/below classification pair; Every closed bar sends deliberately repetitive state reports. These are not matching excursion markers.

Two alternative alert conditions are provided:
- Selected required opposite-side visit
- Selected unresolved opposite-side visit

They follow the same event scope but provide less detail than the dynamic messages. Use one route unless duplicate notifications are intended. Existing alerts retain their creation-time script/settings snapshot; recreate them after changing the intended configuration. Historical eligibility is not proof that a message was sent or received.

7. How the bounds are calculated

The retained range uses the preceding N-1 chart bars. The current bar begins at Open; its running high and low then expand with observations.

A compatible sequence begins at Open, ends at Close, stays within the candle's final Low and High, and reaches both extremes. Repeated visits and jumps between observations are allowed. The calculation assumes no specific high/low order and assigns no probabilities to possible paths.

Let [a,b] be the retained low/high. Let [L,H] be that range expanded by the current candle's Low/High, and [Lo,Ho] the retained range expanded only by Open. Define F(p,h,l) = 100 * (p-l) / (h-l).

RawOpen = F(Open,Ho,Lo)
RawClose = F(Close,H,L)
Possible minimum floor = F(Low,H,L)
Required minimum ceiling = min(RawOpen, RawClose, F(Low,Ho,L))
Required maximum floor = max(RawOpen, RawClose, F(High,H,Lo))
Possible maximum ceiling = F(High,H,L)

The unknown intrabar minimum lies between its floor and ceiling; the maximum lies between its floor and ceiling. Each endpoint is attainable separately within this model. The four endpoints do not identify one actual path. High-first and low-first sequences demonstrate attainable bounds; neither is assumed to be the observed order.

Completed smoothing history stays fixed inside the candle. A candidate current observation replaces the current sample rather than adding another bar. Candidate D is updated together with candidate K:

Candidate K = final K + wK * (candidate Raw - final Raw)
Candidate D = final D + wD * (candidate K - final K)
Candidate K-D = final K-D + (1-wD) * (candidate K - final K)

SMA uses weight 1/n. EMA uses 2/(n+1) after a complete SMA seed; RMA uses 1/n. Undefined inputs restart contiguous warm-up. Seed behavior can differ from other implementations. With D length 1, K equals D and there is no strict K-D side.

For visit direction +1 (upper) or -1 (lower), penetration is max(0, direction * signed extreme - margin).

8. Optional extrema display

Show intrabar extrema bounds is off by default. When enabled, blue shows the necessary extrema span and amber edges show uncertainty in the extrema. These are not volatility bands, confidence intervals or future targets.

Because jumps are allowed, the span does not assert that every intermediate value was observed. Connections between adjacent bars are visual interpolation. If the candle remains inside the retained range, extrema uncertainty is zero, but order, duration and crossing count can remain unknown. Envelope visibility does not alter event selection.

9. Reproducible examples

These are synthetic arithmetic examples, not market-performance results. Use 14/3/3 SMA, a 0.05-point margin and fully initialized history.

Required lower visit: retained range 0 to 100, preceding Raw values stable at 50; current O=60, H=61, L=10, C=60. Opening and closing K-D are approximately +2.222. The minimum is approximately -8.889, giving required/possible penetration of 8.839/8.839 points. The endpoints omit the excursion; no profitable reversal is implied.

Unresolved lower visit: retained range 99 to 100, preceding Raw values stable at 60; O=100, H=101, L=100, C=101. Both endpoint spreads are approximately +8.889. Depending on the unknown order, the minimum can lie from -2.222 to +8.889. Required/possible penetration is 0/2.172 points. The diamond does not identify which path occurred.

Excluded upper visit: retained range 0 to 100, preceding Raw values stable at 50; O=40, H=41, L=39, C=40. Both endpoints are below D, and even the largest possible K-D is approximately -2.000. An upper visit beyond +0.05 is excluded under the model.

10. Contribution and customization

The stochastic and moving-average formulas are established tools, not novelty claims. The contribution is the combined treatment of tight OHLC-consistent intrabar bounds, same-side opposite visits, signed excursion depth and transparent event/notification selection. It addresses what the available data can establish, rather than adding another crossover signal, composite score or assumed tick path. No claim of worldwide exclusivity is made.

Users can change reference lengths, SMA/EMA/RMA smoothing, comparison subject, margin, minimum usable range, repetition, marker selection, placement, history, spacing, alerts, colors, line widths and inspector settings. These are research controls, not optimized trading presets. On narrow panes, reduce the inspector text size or hide it; there is no automatic viewport adaptation.

The Pine source is open under Mozilla Public License 2.0 for inspection, learning and modification, subject to the license and applicable publication rules.

11. Data and interpretation limits

- Standard OHLC charts only. Nonstandard charts are disabled. Close is the only supported source.
- A complete valid H/L/C window, valid current Open, initialized smoothing and a usable preceding N-1-bar range are required. A flat retained range can leave evidence unavailable even when K/D becomes available.
- Evidence, markers, inspector and alerts use completed candles. Preview live K/D only affects the reference lines, not the evidence.
- No lower-timeframe requests, lookahead or intrabar-persistent latch is used. Data corrections, missing bars, loaded starting history and input changes can still alter recalculated results; this is not an unconditional never-repaint promise.
- An opposite-side visit is not a replay of ta.crossover or ta.crossunder. Those functions compare with the preceding chart bar, not the preceding tick. The indicator cannot establish whether an arbitrary alert fired.
- Actual tick order, exact crossing count, excursion time, dwell time, execution price and fills are not recovered.
- Event frequency and depth are not win rates, confidence scores or evidence of trading advantage. No order execution, transaction-cost analysis or out-of-sample strategy performance is supplied.

Use the study to understand the information limits of a closed-bar oscillator. Any trading decision requires separate analysis and risk management.

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.