Swing trend

Up while swing highs and lows both rise, down while both fall.

Swing trend from the last two confirmed pivot highs and lows (swing params as swing). Judged on each pivot confirmation with b = max(floor_pct % × close, trend_k × ATR before the candle): up = both the newer high and the newer low are more than b above the older ones; down is the mirror; held until the next confirmation. Both 0 = mixed. Not ready until two highs and two lows exist.

Swing trend is a structure detector: it marks price structure on the chart and counts against the plan's detector limit.

Settings

SettingDefaultRangeWhat it does
atr_period141 to 500ATR length (Wilder) for every buffer.
swing_k20.1 to 20Swing reversal in ATRs: a pivot is confirmed when a close moves this far back.
swing_min_pct0.10 to 10Smallest swing reversal, % of the close.
trend_k0.10 to 5A higher high or low must clear the earlier one by this many ATRs.
floor_pct0.020 to 10Smallest buffer of this detector, % of the close (each buffer is the larger of this and its ATR multiple).

What it gives

OutputWhat it is
Up trendTrue while swing highs and lows are rising.
Down trendTrue while swing highs and lows are falling.

What it reads

It reads the whole candle (open, high, low, close and volume).

Warm-up

With its default settings, Swing trend needs 241 closed candles before its first value. A backtest loads them before its start date, so the first trade can already use it.

Test it

Copy this sentence into the Algonney chat to backtest it:

Backtest a strategy on BTC that uses Swing trend with its default settings