Tool
Pullback / Continuation
calc.pullback
Inputs
The moving average price retraces toward — wire in an EMA/SMA the trend respects. Used as the touch target in ‘to_ma’ mode.
The current swing leg from a zigzag — its two pivots define the trend direction and the leg length the retrace is measured against.
Outputs
A bundle describing the pullback: whether a qualifying retrace-and-continuation is present this bar, its depth, and the supporting context for downstream stages.
Pullback detects a healthy pullback inside an existing trend — a temporary retrace toward a moving average or partway down a swing leg — then flags the continuation. It’s the ‘buy the dip in an uptrend’ tool, helping you join a trend on the pause rather than chase the breakout.
How it works
You wire in a moving average and the current swing leg (from a zigzag). The `mode` picker decides how the pullback is measured: ‘to_ma’ watches for price retracing back to touch the moving average, while ‘pct_of_leg’ measures the retrace as a fraction of the leg’s length. The `source` picker chooses which price of each bar is tested (open/high/low/close or a blend like hl2). `proximity_atr` and `atr_period` set how close a touch counts in volatility terms, and `min_depth`/`max_depth` bound how shallow or deep the retrace may be to qualify.
Modes
Mode options
Counts the pullback when price retraces back to (or within ATR of) the moving average, then turns to continue the trend.
When to use: Trend-following entries that buy the dip to a dynamic support like a 20- or 50-EMA.
Measures the pullback as a fraction of the prior swing leg, qualifying it when the retrace falls between min_depth and max_depth.
When to use: Fibonacci-style entries that want a retrace into a specific zone of the leg (e.g. 38–61%).
Source options
Tests the pullback against each bar’s open price.
When to use: When the open best represents the level you measure the retrace from.
Tests the pullback against each bar’s high price.
When to use: When the bar’s high is the relevant extreme for the retrace.
Tests the pullback against each bar’s low price.
When to use: When the bar’s low is the relevant extreme for the retrace (common for a dip in an uptrend).
Tests the pullback against each bar’s close price.
When to use: The usual choice — a closed-bar retrace is the most robust read.
Tests the pullback against the bar’s median price, the average of high and low.
When to use: A smoother midpoint when you don’t want a single extreme driving the measurement.
Tests the pullback against the typical price, the average of high, low, and close.
When to use: When you want close weighted in alongside the bar’s range.
Tests the pullback against the average of open, high, low, and close.
When to use: The smoothest single-bar price when you want every component blended.
Configuration
How the pullback is measured — ‘to_ma’ watches for price retracing back to the moving average, ‘pct_of_leg’ measures the retrace as a fraction of the prior swing leg.
Which price of each bar is tested for the pullback: open, high, low, close, or a blend (hl2 = median, hlc3 = typical, ohlc4 = average).
How close to the moving average a touch must come to count, measured in ATRs — larger is more lenient (a near-miss still qualifies), smaller demands an almost-exact touch. Used in ‘to_ma’ mode.
How many bars the ATR used for the proximity test is averaged over; larger smooths the volatility estimate, smaller makes it react faster to recent ranges.
The shallowest retrace that still qualifies, as a fraction of the leg (pct_of_leg mode) — it filters out tiny dips that aren’t real pullbacks.
The deepest retrace that still qualifies, as a fraction of the leg — beyond this the move is treated as a trend reversal, not a pullback.
Connects to
Examples
- Trend continuation long: in ‘to_ma’ mode with source close, fire a buy when price pulls back within an ATR of a rising 50-EMA and turns up to continue.
- Fibonacci pullback: in ‘pct_of_leg’ mode with min_depth 0.382 and max_depth 0.618, take entries only when the retrace lands in the golden zone of the prior leg.
Common mistakes
- Setting max_depth too high so deep retraces that are actually reversals still pass as pullbacks.
- Using ‘to_ma’ mode with a proximity_atr so tight that price almost never registers a touch, leaving the tool silent.