Swing High Low - Definition and SequenceSwing High Low - Definition and Sequence marks confirmed swing highs and lows and studies how their interpretation changes with confirmation time and price definition.
Its central question is practical: does a swing identified from a wick also exist at the same candle when using body edges or closes, and how does price behave after that first confirmation?
The script connects three observations: the same origin across progressively longer confirmation windows, its dependence on wick/body/close definitions, and the subsequent sequence of outside excursions, consecutive outside closes and inside returns. Comparison groups are fixed using information available at Stage I, rather than defined by which origins later survive Stage III.
The chart stays compact. Detailed measurements are available through table tooltips and the Data Window. This is an open-source research indicator, not an automatic entry system, a best-parameter selector or a strategy backtest.
Quick start
Use standard candles and begin with the default Confirmation bars placement. Magenta downward triangles mark high confirmations; mint upward triangles mark low confirmations. A triangle identifies the candle that confirmed an earlier extreme, not necessarily the extreme candle itself.
For the detailed research, open settings group 07, Definition and ordered-path study. Set Inspect record (0 = latest origin, 1 = latest completed) to 1. Then hover over the numeric cells on the relevant HIGH or LOW side:
Origin price: the selected origin's wick/body/close definition tests.
Origin age: its ordered post-confirmation path.
Depth / ATR: signed isolation margins and first-confirmation group statistics.
N / open: sample admission, completion, pending observations and exclusions.
An inspection offset of 0 follows the latest accepted origin, which may still be unfinished. Offsets 1, 2 and higher select successively older completed admitted records. Each inspected record identifies its own time and price. Inspection changes only these tooltip sections: the printed latest-origin values and chart markers retain their usual meanings. An unavailable offset displays no record rather than substituting another one.
Three confirmation stages
The defaults use six left-context bars and right-side windows of 3, 8 and 21 bars. Stage II is entered as five additional bars after Stage I; Stage III adds another thirteen bars. The left context remains fixed. These are not three independent symmetric pivot detectors.
Stage I accepts an origin only when its initial right window has closed and the configured conditions are satisfied. Stages II and III test that same origin after their longer right windows have elapsed. Later stages do not replace it with a nearby, more convenient extreme. Failure to reach a later stage does not retrospectively remove the Stage-I event from the observation population.
Highs and lows are processed separately. Alternating highs and lows are not forced, and no order is inferred when both sides qualify from the same candle.
Price definition selects Wicks, Bodies or Close. Wicks uses high/low; Bodies uses max(open, close) for highs and min(open, close) for lows; Close uses closing prices for both sides.
Equal-extreme selection controls ties within the specified windows. Rightmost allows equal older extremes but no equal newer extreme. Leftmost allows equal newer extremes but no equal older extreme. Strict allows no equality on either side. These rules do not merge equal prices across unlimited history.
The optional two-sided shoulder-depth filter excludes the origin candle, measures the selected-source retreat on each side, and takes the smaller retreat divided by origin ATR. Its default minimum is 0.20 ATR; zero disables this filter. Minimum same-side spacing defaults to three bars between accepted origins. ATR length defaults to 14, and research normalization uses ATR frozen at the origin rather than a later volatility value.
HH, LH and EH compare each accepted high with the preceding accepted high. HL, LL and EL do the corresponding comparison for lows. EH and EL use the configurable equality tolerance, initially one tick. This tolerance affects the classification labels, not the pivot tie rule. With no preceding accepted same-side origin, the initial classification is H or L.
Chart symbols and timing
Triangles represent Stage I, circles Stage II, and diamonds Stage III. The default presentation limits primary markers to 30 per side, later-stage symbols to six per side within the most recent 100 visible closed bars, and primary text captions to one per side. Colors, sizes, transparency, pins, captions and limits are configurable.
Hovering over a symbol provides its origin price and time, confirmation time, stage, delay, depth and normalized drift. Use the origin timestamp to associate different confirmation symbols with the same swing.
Confirmation bars is the default placement. Origin bars (backdated) places only Stage I on its earlier origin after confirmation, with a dotted trace to the confirmation candle. This is delayed historical annotation: the marker was not available on the origin candle. Later-stage symbols, event outputs and alerts are not shifted backward.
Adaptive density selects chart symbols using visible-bar spacing, not subsequent success or failure. Zooming, panning or adding bars can change which symbols are displayed and their vertical clearance. Fixed spacing and All within limits are alternatives; count, age and finite-cache limits still apply. Each of the two presentation caches holds up to 2,400 events for the selected viewport.
These display controls do not change detection, research samples or alerts. Consequently, a label can compare against an accepted origin that is not currently visible. Chart marks are not an exhaustive event ledger, and presentation recalculation should not be confused with a claim that every historical drawing remains permanently visible.
Same-origin definition tests
For every accepted origin, the definition study asks whether that exact candle is also an extreme under wick, body-edge and closing-price representations. Each representation uses its own price on the same origin candle; the study does not search for replacement pivots.
Each of the three scheduled stages tests all three price definitions against Rightmost, Leftmost and Strict: up to 27 geometry checks. These are related conditions, not 27 independent models. Strict implies both other tie rules; without relevant ties, those rules can give identical answers.
The Origin price tooltip displays W for wick, B for body edge and C for close. Within each bracket, R/L/S indicates the tie rules that pass; a dash indicates failure and a question mark indicates unavailable data. A pending stage has not reached its scheduled confirmation close.
For example, W B C describes an origin that is strictly isolated as a wick extreme, but not as a body-edge or closing-price extreme. The accompanying 0-3 count is the number of source definitions passing the currently selected tie rule, not a confidence score or reversal probability.
Later definition rows are evaluated even when the main selected-source origin fails Stage II or III. They do not promote the main detector's marker. Alternative depth filters and accepted-origin spacing are not rerun, so this is a fixed-candle geometry comparison, not three complete alternative detector histories.
Signed isolation margins
The Depth / ATR tooltip includes a separate margin for each price definition and stage:
High margin = (origin source price - highest competing source price) / origin ATR.
Low margin = (lowest competing source price - origin source price) / origin ATR.
Competitors are the fixed left context and the relevant right window, excluding the origin candle. Positive means strictly isolated, zero means tied, and negative means exceeded by another candle. Missing or nonpositive origin ATR leaves the margin unavailable.
These margins measure separation from the strongest competing extreme. They differ from the shoulder-depth filter, which measures retreat on both sides. The visible Depth / ATR number remains shoulder depth; margins are not summed into a quality score.
Ordered path after Stage I
This study observes the next 24 closed candles after Stage I by default. Its horizon is adjustable from 1 to 150. The confirmation candle is excluded.
For a high, outside means above the selected origin price and inward means downward. For a low, outside means below the origin and inward means upward. Wick excursions always use chart highs and lows, even when the main detector uses Bodies or Close.
The outside boundary is beyond the origin by max(outside ATR buffer, minimum tick buffer). Defaults are 0.05 origin ATR and one tick. A wick or close must strictly cross that boundary; equality does not qualify. The inside-return clearance defaults to 0.05 origin ATR. These distances remain fixed for the record.
The record identifies the first outside wick; the first inward excursion of the configured size from the Stage-I confirmation close, initially 1.0 origin ATR; the first run of consecutive outside closes, initially two; and the first subsequent run of closes inside the origin by the return clearance, initially one.
A nonqualifying close resets an unfinished run. An inside return must follow completion of the outside-close run on later candles; it cannot be inferred from that acceptance candle's wick. Acceptance is simply the name of a price condition, not evidence of participant intent.
Path codes have the following meanings:
0: No outside wick within the observed window.
1: Outside wick occurred, but the required outside-close run did not complete.
2: Outside-close run completed, but no subsequent required inside-return run completed.
3: Outside-close run completed and was followed by the required inside-return run.
-1 in the Data Window: Unusable path, excluded from path-group statistics.
Code 1 can include isolated outside closes: it does not mean every excursion was wick-only. Code 3 records a return milestone, not a guarantee that the final candle remains inside. Code 0 applies only to the configured observation window.
The tooltip also reports event delays, outside-close count, maximum outward distance, maximum inward movement before the first outside-wick candle, and confirmation-to-horizon close drift. The confirmation candle's own outside wick is reported separately. First means first within this post-confirmation window, not necessarily first since the swing origin.
When the first outward wick and first inward excursion occur on the same candle, their order is recorded as SAME BAR - intrabar order unknown. The complete first outside-wick candle is excluded from the pre-outside inward-movement measurement. No favorable intrabar route or executable trade fill is assumed.
Groups fixed at first confirmation
At Stage I, origins with complete definition data are assigned to either All three definitions at I or Definition-sensitive at I, using the selected tie rule. That membership remains fixed even if later definition results or main-stage retention change.
Completed usable paths are compared by group. The tooltip provides sample counts, outside-wick and outside-close-run counts, inside-return counts, outside acceptance as a percentage of the group, returns as a percentage of completed outside-close acceptances, mean return delay among records that returned, ending close drift and event-order counts.
This answers a specific research question: how did the subsequent paths of definition-consistent and definition-sensitive origins differ in the selected sample? It does not establish that either group is a profitable filter. Initial price shapes differ, the main detector already conditions the sample, and observations may be dependent. Late outside acceptance leaves less time for a return before the horizon ends. No observed return means none within that window, not none forever.
Confirmation-retention readout
Latest shows the most recent accepted origin's classification and attained stage. A clock or ellipsis indicates observation in progress; a square means the observation window ended, not that all stages passed. An attained stage is a historical fact, not a statement that the level remains unbroken now.
Origin price, Origin age and the printed Depth / ATR refer to that latest accepted origin. Age is measured in chart bars.
II / I and III / I use the same rolling sample of initial origins that completed the full Stage-III observation horizon with usable source data. The default capacity is 100 per side. Pending observations do not enter either denominator. These percentages are extreme-retention frequencies, not win rates or forecasts.
Extra III / ATR measures additional origin-to-close drift while waiting from Stage I to Stage III, restricted to origins that attained III with usable ATR. Positive means downward additional close movement for a high, or upward for a low. It can be negative. This is distinct from movement after confirmation.
N / open shows the retention sample size and its pending observations. Detailed studies have separate populations and completion times; their counts are available in the tooltip, not substituted into this visible value.
Equal-length windows after each confirmation
The post-confirmation study measures the next H closed candles after each attained stage, with H = 12 by default. Each measurement starts from that stage's confirmation close and excludes its confirmation candle.
It records signed close drift, maximum movement away from and toward the confirmation close, and whether the selected source retained the original extreme throughout that window under the selected tie rule. Distances use origin ATR. Maximum excursions use wick highs/lows, are floored at zero and do not imply an order of execution.
All stage measurements for one admitted origin enter the completed sample together at origin + Stage-III right bars + H. This common deadline applies even when later stages are absent. Missing later-stage results are not zero observations.
A separate matched comparison uses the same Stage-III-retained origins for all three stage means and reports their paired III-minus-I difference. It remains conditional on later Stage-III attainment. Earlier measurement windows can overlap the interval required to qualify Stage III. Matching origin identities and waiting for a common deadline do not remove that selection effect or demonstrate a causal benefit of waiting.
Hover HIGH or LOW for Stage-I post-confirmation statistics, II / I and III / I numeric values for later-stage statistics, and Extra III / ATR for the matched comparison. These details do not replace the printed retention values.
Worked timing and interpretation example
Number the swing origin as bar 0. With the defaults, Stage I becomes known after bar 3 closes, Stage II can become known after bar 8, and Stage III after bar 21. Each stage concerns the same origin.
The ordered path uses bars 4 through 27. Its definition/path record becomes complete after bar 27 closes: origin + max(21, 3 + 24).
The equal-length post-confirmation study uses bars 4-15 after Stage I, 9-20 after Stage II when attained, and 22-33 after Stage III when attained. Its entire record becomes available after bar 33 closes. The retention readout, definition/path record and equal-length study therefore have different deadlines: +21, +27 and +33 in this example.
For an illustrative swing-high origin at 100 with origin ATR of 2 and a tick size of 0.01, the default outside boundary is 100.10. Two consecutive post-confirmation closes strictly above 100.10 complete outside acceptance. A later close strictly below 99.90 completes the default inside return. If these events occur within the path horizon, the record reaches code 3, irrespective of whether Stage III was attained.
If that origin had W B C at Stage I, it remains in the definition-sensitive group. The later return does not retroactively improve its initial agreement. This example illustrates the rules, not a measured trading result or a recommended setup.
Sampling, missing data and historical inspection
Both detailed studies default to All accepted origins and offer their own Non-overlapping per side setting. Non-overlap admits an origin only when its Stage-I confirmation is strictly after the preceding admitted origin's common deadline on that side. Admission is decided at Stage I. A later failure or exclusion does not cause retrospective replacement with a skipped origin. Opposite-side windows may overlap; non-overlap does not prove independence.
The equal-length study excludes whole records with missing required OHLC/source data between first confirmation and common maturity, or unusable origin ATR. Its rolling capacity counts usable completed initial origins.
The definition/path study retains completed admitted records, including records whose paths are unusable. Such paths are excluded from path-group statistics, while usable definition tests can remain in their respective denominators. Unknown initial definitions cannot enter either initial-definition group. Missing or malformed required path OHLC and missing or nonpositive origin ATR do not become successful holds. Counts of pending records, exclusions and admission skips are reported separately.
The table shows the latest closed-bar state of the loaded execution, not the historical bar under the cursor. Panning changes chart presentation, not the table's statistical cutoff. Use historical Data Window outputs or Bar Replay to inspect earlier available information. Tooltip timestamps identify bar-open times in the exchange timezone; observations become available only after the relevant bar closes.
Data Window, alerts and controls
The Data Window includes six stage-price event series; optional historical post-confirmation means, held frequencies and sample sizes; individual results on their common completion candle; matched comparisons and sample accounting; and six definition/path event outputs containing origin time, initial agreement and path code for each side. Outcome timestamps identify earlier origins without moving those outcomes backward in time.
Eleven alert conditions cover the six stage confirmations, any stage confirmation, retention-horizon completion, the two side-specific post-confirmation completions, and definition/path completion. Conditions commit at bar close. A completion notification may include an unusable record and is not a successful-outcome notification. Ordered-path completion is not a real-time breach or return alert.
Detection rules, confirmation spans, price sources, depth and spacing filters, ATR length, research horizons, buffers, required close runs, sample capacities, admission policies and record inspection are editable. Presentation has separate controls for placement, density, marker budgets, ages, captions, colors, typography and table position. Research can be enabled or disabled without changing the primary detector. Hiding Data Window outputs does not disable the corresponding study calculations.
Scope and limitations
The contribution is the connected same-origin research workflow: definition sensitivity at first confirmation, progressively longer confirmation records, and subsequent paths compared under explicitly defined observation windows. Pivots, ATR, tie handling and price-path analysis are established building blocks; their number is not evidence of independent confirmation or exclusive novelty.
The script uses chart OHLC without external data requests or imported indicator libraries. It is published as open-source Pine Script v6 under the Mozilla Public License 2.0. It does not identify market participants, infer hidden orders, recommend a best stage or definition, or simulate trades, costs or portfolio returns.
Results depend on settings, available history, feed revisions and chart construction. Non-standard charts describe constructed OHLC. Finite samples, serial dependence, overlapping windows, conditional comparisons and repeated parameter exploration limit interpretation. No significance test, predictive accuracy or trading-performance claim is implied. Drawing caches and platform resource limits are finite; extreme settings can increase processing time.
Use the indicator to inspect swing definitions and confirmation behavior, with clear separation between what was known at confirmation and what was observed afterward.
Chỉ báo






















