Intrabar Ambiguity: Which Hit First, Stop or Target?

WHAT IT DOES
Intrabar Ambiguity counts the exit bars in which a stop and a target both sit inside one bar's range, so open, high, low and close cannot say which was hit first. It replays one hypothetical ATR-based trade at a time through a shadow ledger and settles each such bar twice: with a fixed rule on the bar's open, high and low, and with the lower-timeframe bars inside it. The table shows how often the two answers differ and how far the win rate moves.
WHAT IS ORIGINAL HERE
A bar records a range, not the order of the prices inside it. When a stop and a target both sit in that range, the order decides win or loss. This script isolates those bars and keeps two outcomes for the same trades, the rule's and the lower-timeframe data's, so the two win rates differ only by the order assumed inside ambiguous bars. Bars that cannot be settled are counted apart. It keeps its own ledger and does not use the Strategy Tester.
LEDGER RULES
- One trade at a time, long or short. Entry at a bar's close; the stop and the target are placed there, a chosen number of ATRs away.
- Exits are checked from the next bar on. A bar that opens beyond the stop or the target exits there. Gap exits are never ambiguous.
- Otherwise a bar touches the stop when its low (long) or high (short) reaches it, and the target likewise. Both touched makes the bar ambiguous.
- A trade that touches neither closes at the close of the Nth bar after entry: a win if that close is above the entry for a long, below it for a short.
- After an exit, the next trade opens at that bar's close, so its range is never reused.
- Only confirmed bars update the ledger. A trade still open on the last bar is not counted.
HOW AMBIGUITY IS RESOLVED
Rule. TradingView documents that on historical bars the strategy broker emulator does not know the intrabar path. It assumes that if the bar's high is closer to its open than the low is, price went open, high, low, close; otherwise open, low, high, close. The "Bar Magnifier" strategy setting uses lower-timeframe data instead. That documented assumption of the broker emulator is the rule here: high first means target first for a long and stop first for a short; low first is the reverse.
Lower timeframe. It walks the lower-timeframe bars inside the exit bar in time order. The first one that touches the stop or the target decides. If that one touches both, or none touches either, the bar is unresolved. If the lower timeframe is not below the chart timeframe, or TradingView returns no lower-timeframe bars, it is counted as "no lower-timeframe data".
Exit counts follow the rule. The LTF-corrected win rate uses the lower-timeframe outcome where there is one and the rule's otherwise.
HOW TO USE IT
1. Add it to a chart. Choose the direction, the ATR length, the stop and target distances in ATRs, and the time exit.
2. Choose a lower timeframe below the chart's, for example 5 on a 4 hour chart.
3. Read the table. Marks sit on ambiguous exit bars: red cross, the lower timeframe disagrees with the rule; gray circle, it agrees; orange square, unresolved or no data.
HOW TO READ THE TABLE
Trades closed; exits split into stop / target / time, ambiguous bars under the rule's answer.
Ambiguous exit bars: both levels touched, as a share of trades. Resolved with lower timeframe: those an intrabar decided.
Rule agreed / disagreed: among resolved bars, with the share that disagreed. Red when at least one did.
Unresolved in one intrabar: both levels inside one lower-timeframe bar, or no touch found. No lower-timeframe data: nothing to resolve the bar.
Win rate, rule and LTF-corrected: all closed trades, ambiguous bars settled by the rule or, where possible, the lower timeframe. Win rate, resolved bars: the same two over resolved bars only.
LIMITATIONS
- Lower-timeframe bars are not tick data: when both levels fall inside one, the order is unknown.
- TradingView limits intrabars by plan, so old bars can have none. The disagreement share covers only resolved bars.
- The ledger counts outcomes, not returns, with no commission, slippage or spread. A gap exit is counted at the level the bar opened beyond.
- The trades are hypothetical, not a signal.
- Only loaded bars count, so history depth, symbol and timeframe change every number.
- Not the Strategy Tester. Counts, not a trading rule. Not financial advice.
The chart shows BTCUSDT (Binance) on the 4 hour timeframe with the default settings. The table is in the bottom right.
Intrabar Ambiguity counts the exit bars in which a stop and a target both sit inside one bar's range, so open, high, low and close cannot say which was hit first. It replays one hypothetical ATR-based trade at a time through a shadow ledger and settles each such bar twice: with a fixed rule on the bar's open, high and low, and with the lower-timeframe bars inside it. The table shows how often the two answers differ and how far the win rate moves.
WHAT IS ORIGINAL HERE
A bar records a range, not the order of the prices inside it. When a stop and a target both sit in that range, the order decides win or loss. This script isolates those bars and keeps two outcomes for the same trades, the rule's and the lower-timeframe data's, so the two win rates differ only by the order assumed inside ambiguous bars. Bars that cannot be settled are counted apart. It keeps its own ledger and does not use the Strategy Tester.
LEDGER RULES
- One trade at a time, long or short. Entry at a bar's close; the stop and the target are placed there, a chosen number of ATRs away.
- Exits are checked from the next bar on. A bar that opens beyond the stop or the target exits there. Gap exits are never ambiguous.
- Otherwise a bar touches the stop when its low (long) or high (short) reaches it, and the target likewise. Both touched makes the bar ambiguous.
- A trade that touches neither closes at the close of the Nth bar after entry: a win if that close is above the entry for a long, below it for a short.
- After an exit, the next trade opens at that bar's close, so its range is never reused.
- Only confirmed bars update the ledger. A trade still open on the last bar is not counted.
HOW AMBIGUITY IS RESOLVED
Rule. TradingView documents that on historical bars the strategy broker emulator does not know the intrabar path. It assumes that if the bar's high is closer to its open than the low is, price went open, high, low, close; otherwise open, low, high, close. The "Bar Magnifier" strategy setting uses lower-timeframe data instead. That documented assumption of the broker emulator is the rule here: high first means target first for a long and stop first for a short; low first is the reverse.
Lower timeframe. It walks the lower-timeframe bars inside the exit bar in time order. The first one that touches the stop or the target decides. If that one touches both, or none touches either, the bar is unresolved. If the lower timeframe is not below the chart timeframe, or TradingView returns no lower-timeframe bars, it is counted as "no lower-timeframe data".
Exit counts follow the rule. The LTF-corrected win rate uses the lower-timeframe outcome where there is one and the rule's otherwise.
HOW TO USE IT
1. Add it to a chart. Choose the direction, the ATR length, the stop and target distances in ATRs, and the time exit.
2. Choose a lower timeframe below the chart's, for example 5 on a 4 hour chart.
3. Read the table. Marks sit on ambiguous exit bars: red cross, the lower timeframe disagrees with the rule; gray circle, it agrees; orange square, unresolved or no data.
HOW TO READ THE TABLE
Trades closed; exits split into stop / target / time, ambiguous bars under the rule's answer.
Ambiguous exit bars: both levels touched, as a share of trades. Resolved with lower timeframe: those an intrabar decided.
Rule agreed / disagreed: among resolved bars, with the share that disagreed. Red when at least one did.
Unresolved in one intrabar: both levels inside one lower-timeframe bar, or no touch found. No lower-timeframe data: nothing to resolve the bar.
Win rate, rule and LTF-corrected: all closed trades, ambiguous bars settled by the rule or, where possible, the lower timeframe. Win rate, resolved bars: the same two over resolved bars only.
LIMITATIONS
- Lower-timeframe bars are not tick data: when both levels fall inside one, the order is unknown.
- TradingView limits intrabars by plan, so old bars can have none. The disagreement share covers only resolved bars.
- The ledger counts outcomes, not returns, with no commission, slippage or spread. A gap exit is counted at the level the bar opened beyond.
- The trades are hypothetical, not a signal.
- Only loaded bars count, so history depth, symbol and timeframe change every number.
- Not the Strategy Tester. Counts, not a trading rule. Not financial advice.
The chart shows BTCUSDT (Binance) on the 4 hour timeframe with the default settings. The table is in the bottom right.
Custom Pine Script v6: indicators, strategies, alerts, with look-ahead and repaint checks. Backtest audits in Python.
Hire me on Upwork: upwork.com/freelancers/~01fa3c5136b53674c8
Proofs on GitHub: github.com/guillemustafa-ux
Hire me on Upwork: upwork.com/freelancers/~01fa3c5136b53674c8
Proofs on GitHub: github.com/guillemustafa-ux
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Custom Pine Script v6: indicators, strategies, alerts, with look-ahead and repaint checks. Backtest audits in Python.
Hire me on Upwork: upwork.com/freelancers/~01fa3c5136b53674c8
Proofs on GitHub: github.com/guillemustafa-ux
Hire me on Upwork: upwork.com/freelancers/~01fa3c5136b53674c8
Proofs on GitHub: github.com/guillemustafa-ux
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.