Before you begin: Complete structure mapping and swing amplitude lessons; understand percentage changes.
Implement a close-based directional state
Freeze an extreme only after a declared reversal
Distinguish pivot occurrence from confirmation time
Mechanism and interpretation
A percentage-reversal algorithm turns a price sequence into alternating extrema by requiring a minimum move against the current candidate. This lesson defines an original close-only rule. Start from a stated seeded low and an upward-search state. Update the candidate high whenever a strictly higher close arrives. Confirm that high when a later close is at or below high×(1−p), then switch to downward search with the confirmation close as the initial candidate low. Confirm a low when a later close is at or above low×(1+p), then switch upward. Equality qualifies; equal candidate extrema retain the earliest timestamp.
These rules are causal when evaluated in sequence, but the confirmed pivot is drawn at an earlier observation. Store both times. The confirmation lag and distance are part of the algorithm's cost of certainty. A5% decline followed by a 5% rise does not return to the same price, because percentage denominators differ. This asymmetry is a mathematical consequence of the definition, not a coding error. Other swing algorithms may choose logarithmic or symmetric thresholds and will produce different maps.
Worked case — synthetic data
Synthetic closes after a seeded low 100 are 106,110,108,104.5,103 and 108.15. With p=5%, the candidate high moves from 106 to 110. A close 108 does not meet the reversal threshold 110×0.95=104.5. The next close 104.5 qualifies and confirms the earlier 110 high. The new downward candidate becomes 104.5, then 103. Its upward reversal threshold is 103×1.05=108.15, so the last close confirms the 103 low.
The historical vertices 100,110,103 conceal two separate waiting periods. A decision made when 110 first appeared could not know that it would remain the candidate high. Likewise the 103 low was not confirmed until 108.15 arrived. A chart that places a marker at 103 is describing where the extreme occurred, not when an algorithm could have acted on the completed label. Keep a table of state before the bar, candidate after the bar and newly confirmed pivot to make this distinction auditable.
Context and failure modes
Close-only processing misses intrabar extremes by design. An OHLC version needs an ordering convention when one candle crosses both directions; copying the close-only output is not a valid substitute. Threshold choice controls map density but does not establish predictive quality. Initial seeding, equal-price handling, missing data and corporate-action adjustments must also be fixed before comparing implementations.
Practice task
The algorithm is searching upward with candidate high 220 and p=5%. Subsequent closes are 211,209 and 205. Identify the first confirming close and the new downward candidate after all three observations.
Worked practice answer
The threshold is 220×0.95=209. Close 211 does not qualify;209 confirms the 220 high. Downward search begins with 209 and updates to 205. The 205 low remains provisional until a later close reaches 205×1.05=215.25 or higher.
Topic assessment
Choose an answer before opening each explanation. These questions test the specific mechanism in this lesson.
1. When is a candidate high confirmed under this rule?
At the first new high automatically
One bar before the high occurs
At a later qualifying reversal close
Reveal answer and explanation
C. The reversal condition makes the earlier extreme a confirmed pivot.
2. What is the 110 high's 5% reversal threshold?
104.5
105
115.5
Reveal answer and explanation
A. Multiplying 110 by 0.95 gives 104.5.
3. Why store occurrence and confirmation times?
Confirmation time is irrelevant to a backtest
The plotted extreme predates the information needed to confirm it
They are always identical
Reveal answer and explanation
B. Using occurrence time as availability would introduce future information.
Primary references and scope
Original explanation and synthetic calculations. Chart thresholds are explicit research conventions, not exchange rules or proof of predictive ability.