Execution models and hidden price paths

Construct compatible intrabar histories, derive attainable joint outcomes and audit a backtest claim.

40 minutes · advanced · Original Poker4Quant lesson

What you will learn

Derive a sharp joint execution-outcome set from an OHLC bar, prove an unattainable policy comparison by crossing order and distinguish a replay convention from observed evidence.

Prerequisites: Price-time order matching · Implementation shortfall and unfilled orders · Reviewing and revising a quantitative model

Separate the observed bar from the simulated history

An open-high-low-close bar records four summaries: the first price, the largest price, the smallest price and the last price in a period. It does not list the order of all intermediate prices. That missing order matters when an instruction exits at whichever of two barriers is touched first. A deterministic program can always choose an ordering and return a precise profit. Precision in that output does not make its chosen history identifiable from the input. Our task is to find all possible outcomes under explicitly stated assumptions before interpreting a single replay.

Assume an invented bar opens at 100 chips, reaches high 106 and low 94, and closes at 102. A continuous price path connects its waypoints monotonically between successive points, stays within those extremes and visits both. Before the bar begins, each of two separate counterfactual policies already owns one unit bought at 100. Policy A sells on the first touch of stop 96 or target 103. Policy B sells on the first touch of stop 98 or target 105. Touch includes equality; each exit fills at that barrier, cancels its sibling and never reopens. There are no fees, spread, gaps, latency, quantity constraints or price impact. Both experiments use the same external price path. They do not compete for one unit of liquidity. These assumptions deliberately remove realistic fill uncertainty so that missing temporal information is the only uncertainty studied.

Replay first touches instead of sorting four prices

For a given path, walk forward segment by segment while each policy remains open. An upward segment from 100 to 106 crosses 103 before 105. A therefore exits at 103 for gain 103−100=3, and B exits at 105 for gain 5. Later visits to 94 cannot turn those closed positions into losses. Conversely, a first downward segment from 100 to 94 crosses 98 before 96. B exits at 98 for gain −2 and A exits at 96 for gain −4. The final close of 102 changes neither realized exit. The same four bar summaries permit both histories.

A barrier need not be a recorded waypoint. A straight segment from 100 to 106 passes continuously through 103 and 105. Skipping those values in a waypoint list is not evidence that their exits were skipped. Conversely, hitting the target and the stop sometime in the bar does not imply both orders execute: the first exit cancels the second. This is an absorbing execution state. Record the first crossing and keep it, rather than replacing it with the last or most favorable crossing. These are execution rules, not predictions about which route prices usually take.

Derive the joint outcome set with witnesses and an exclusion

Individually A can earn 3 or −4, and B can earn 5 or −2. Combining these lists mechanically produces four candidate pairs. Three are attainable on one common path. The history 100→106→94→102 produces (A,B)=(3,5). The history 100→94→106→102 produces (−4,−2). A third history, 100→103→94→106→102, produces (3,−2). A exits exactly at its target on the first segment; the descent then stops B at 98 before the later rise reaches 105. Every history starts at 100, has maximum 106, minimum 94 and ends at 102.

The fourth candidate (−4,5) is impossible. To get B’s target, the path must rise through A’s nearer target 103 on its way to 105. For A instead to have stopped at 96, it must already have descended through B’s nearer stop 98 before that rise. But that earlier descent would have closed B at its stop, preventing B’s target exit. Either ordering contradicts one of the requested outcomes. This exclusion depends on continuity, pre-existing active exits and common-path comparison. It is not a claim about gapped quotes or independently chosen histories.

We have now proved completeness. Every policy must exit at one of its two barriers because this bar reaches both extremes, so there are only four candidate pairs. The crossing argument excludes one and explicit compatible paths attain each of the other three. Therefore the exact attainable set is {(3,5),(3,−2),(−4,−2)}. Listing some successful examples alone would not establish that this set is exhaustive; exclusion plus witnesses supplies that certificate.

Compare policies on the same history and obtain sharp bounds

Define D as B’s gain minus A’s gain in chips per unit. On the three feasible pairs, D is respectively 5−3=2, −2−3=−5, and −2−(−4)=2. Thus D belongs to {−5,2}; its sharp lower and upper bounds are −5 and 2. Sharp means each bound is achieved by a permitted path, not just that no value lies outside it. Zero lies between the bounds but is not a possible realized difference in this model. An interval envelope need not describe every attainable value.

Subtracting separate marginal intervals would give [−2,5]−[−4,3]=[−5,9]. That is a valid outer enclosure but its upper endpoint is unattainable: nine requires pairing B’s best result with A’s worst result, precisely the impossible pair. Separate scenario choices silently let the policies experience different histories. At the attainable endpoints, B wins by two on some paths and loses by five on another, so neither policy dominates across all compatible paths. Choosing a pessimistic result for each policy separately is also insufficient to establish a paired ranking.

No probability distribution over histories has been supplied. If q denotes an assumed total probability of the feasible mixed outcome (3,−2), then the conditional model mean would be E[D]=−5q+2(1−q)=2−7q. It is positive for q<2/7, zero at q=2/7 and negative for q>2/7. This is a sensitivity formula, not an estimate of q. Giving equal probability to the three displayed witness paths would be an additional arbitrary model; there are infinitely many compatible paths and no uniform selection rule here. The arithmetic of the bounds needs no such probability assumption.

Ask which extra observation would resolve the claim

Suppose an additional reliable record establishes that 98 was touched before 103. B must then stop at 98, but A need not stop: the price could reverse upward before 96 and reach 103, or continue down to 96 first. The extra record rules out the all-target pair while leaving both the mixed and all-stop pairs. Their differences are still −5 and 2, so this observation shrinks the outcome set without shrinking its interval bounds. More information need not improve every summary.

By contrast, observing that 105 was reached before 98 forces the all-target outcome: A must have exited at 103 on the way up, and B exits at 105. The difference is then two. A useful data request targets the particular crossing order needed to distinguish remaining outcomes, rather than merely asking for a larger file or more decimal places. In each case the record must concern the interval when the exits were active.

Use the workshop to challenge a replay claim

The path workshop lets you select a proposed outcome pair and append up to eight interior waypoints. Open 100 and close 102 remain fixed. Add 106 then 94 and audit the all-target witness. Undo both points, reverse their order and audit the all-stop witness. Next insert 103 before 94 and 106 to construct the mixed outcome. The audit reports each first-exit segment, exit price, gain and paired difference. A mismatch identifies the path actually constructed; a missing extreme is diagnosed separately because it fails to reproduce the observed bar.

Select the impossible pair and attempt to build it. The audit explains the crossing obstruction after checking that your draft matches the bar. Add repeated points or a late rally after an exit and confirm that a closed position stays closed. Edits invalidate earlier feedback; undo removes the last interior point and reset clears the draft and hint. The segment number is a position in your constructed sequence, not an observed market timestamp. The eight-point editor limit is for usability; the mathematical exclusion applies to every continuous compatible path, however many reversals it has. The activity is local to the visit and does not award account progress.

Write a bounded execution-model review

A defensible review states the data resolution, when each order became active, the assumed within-bar route, the first-touch and cancellation conventions, and which results survive alternative compatible routes. For this example, report the three joint outcomes and the sharp difference bounds rather than claiming a unique historical winner. To learn the actual ordering, request finer timestamped observations that separate the competing first touches. Smaller OHLC bars can still leave both barriers in one sub-bar. More observations help only if they resolve the relevant ordering and cover the relevant period.

Keep the information clock separate from this path ambiguity. Our exits were fixed before the bar. A strategy that observes the finished bar’s high or close to design its exits cannot automatically claim those exits were active at the earlier open. Repairing that timing problem can change the experiment rather than merely change a calculation. Likewise, removing continuity or adding queue competition requires a different execution model. The present bounds certify this fictional mechanism, not executable market returns.

TradingView’s official broker-emulator documentation explicitly describes assumed intrabar routes from OHLC data and the use of lower-timeframe bars when available. Backtrader’s official execution documentation separates order creation from later eligible data and states its treatment of volume. These sources motivate declaring simulator conventions. Our paired barriers, exclusion proof, witness paths and arithmetic are original; they do not reproduce either platform’s fill algorithm. No platform installation, real backtest, video review or trading performance is claimed.

Worked example

Given the bar (100,106,94,102), audit the claim that B can beat A by nine chips on the same continuous price history.

  1. A exits at 103 or 96, so its gains are 3 or −4. B exits at 105 or 98, so its gains are 5 or −2.
  2. 100→106→94→102 gives exits (103,105), gains (3,5) and difference 2. Independently reconcile cash: (105−100)−(103−100)=105−103=2.
  3. 100→94→106→102 gives exits (96,98), gains (−4,−2) and difference 2. Cash check: 98−96=2.
  4. 100→103→94→106→102 gives exits (103,98), gains (3,−2) and difference −5. Cash check: 98−103=−5.
  5. Nine would require exits (96,105). A descent to 96 first stops B at 98; a rise to 105 first takes A out at 103. The requested paired exits cannot coexist.
  6. The sharp bound is −5≤B−A≤2, with only −5 and 2 attained. With a hypothetical mixed-outcome probability q, E[B−A]=2−7q; OHLC alone does not identify q.

The nine-chip claim combines incompatible histories. A deterministic OHLC replay selects a convention inside an identified set; it does not recover the missing order from the bar.

Hands-on: Build compatible execution histories

Construct common-path witnesses, inspect first exits and challenge an impossible outcome pair without changing the bar.

Build compatible execution histories

One bar: open 100, high 106, low 94, close 102. Two separate one-unit long experiments start at 100 before the bar. A exits at its first touch of stop 96 or target 103; B at stop 98 or target 105. Segments are continuous and monotone. Exits fill at the barrier, cancel the other exit and never reopen. No fees, spread, gaps, queue or impact. Both policies see the same path, not each other’s orders.

Choose an outcome to investigate

Selected pair: A +3, B +5.

Construct the interior path

Append up to eight waypoints. Segments connect adjacent prices continuously. The final 102 is automatic. Point order matters; repeated points are permitted.

Path: 100 → 102.

0 of 8 interior points used. Both extremes must be visited.

Build a path, then audit your chosen outcome.

Segment 1 starts at open 100. Each appended waypoint ends the next segment; the final segment ends at close 102. A certificate proves possibility, not the observed route.

Common mistakes

  • Treating open, high, low, close as an observed chronological route.
  • Replacing an earlier exit with a later, more favorable touch.
  • Discarding a barrier crossing because the barrier was not a listed waypoint.
  • Combining each policy’s separate best or worst outcome as if both used the same path.
  • Assuming every number between sharp bounds is attainable.
  • Assigning equal probability to a convenient list of witness paths.
  • Using end-of-bar information to justify orders at the earlier open.

Keep these ideas

  • An OHLC bar loses event order that a first-exit rule needs.
  • Compatible paths prove attainability; crossing-order arguments exclude impossible joint outcomes.
  • Pair policy outcomes on one history before bounding their difference.
  • Bounds without a path law are not an expected return; a replay convention is not observed history.

Further reading

  • TradingView Pine Script documentation: broker emulator and historical bar detail ↗

    Bounded read of Broker emulator and Adjusting historical bar detail: default inferred intrabar routes, gap handling, lower-timeframe observations and incomplete coverage. Original continuous common-path model and joint-outcome proof are not TradingView algorithm outputs. No source example, video or platform execution claimed. Checked 2026-10-25.

  • Backtrader documentation: Order Execution Logic, Market, Limit and Stop ↗

    Read execution guidelines and Market, Close, Limit and Stop sections: later eligible data, declared volume simplification and OHLC price-matching conventions. Supports explicit timing and fill assumptions only. Original barrier example is not a Backtrader run; no source code, source numerical example or video reused. Checked 2026-10-25.

Check your understanding

Untimed · 5 checks · Guest progress stays in this browser. Sign in to save account snapshots.

Loading saved lesson…

Take the track assessment →