Trendlines

Sloped support and resistance lines through swing points, with breaks and retests.

Trendlines from confirmed swing pivots (swing params as swing), fitted only on the candle a pivot confirms. Resistance: the line through the newest swing high and an earlier one that touches at least touches swing highs (each within tol_k ATRs, min_spacing candles apart, none above the line by more than tol_k ATRs), min_length to max_length candles long, with at most max_through closes above it (by more than tol_k ATRs) since its first touch; the most touches win, then the longest. Support is the mirror under the swing lows. A new fit replaces the line; a line older than max_length candles ends. resistance_break = a close above the line by max(floor_pct % × close, break_k × ATR); the broken line then waits retest_bars candles: resistance_retest = a later candle reaches the line (low ≤ line + tol_k ATRs) and closes above it (it holds); a close below the line by tol_k ATRs ends the wait. resistance / slope_pct / touches describe the active line, else the broken line while it waits and on its break and retest candles. slope_pct = the line's change per candle, % of its value now. Every buffer has the floor_pct % floor.

Trendlines 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.
floor_pct0.020 to 10Smallest buffer of this detector, % of the close (each buffer is the larger of this and its ATR multiple).
touches32 to 10Swing points a line must touch (the first and the newest included).
tol_k0.250 to 5A swing point within this many ATRs of the line touches it.
min_spacing51 to 500Fewest candles between two counted touches.
min_length102 to 2000Shortest line, in candles from its first to its newest touch.
max_length3003 to 2000Longest line, in candles from its first touch to now (an older line ends).
max_through00 to 50Closes allowed beyond the line (by more than tol_k ATRs) while it formed.
break_k00 to 5A break is a close beyond the line by this many ATRs.
retest_bars201 to 500Candles after the break in which the retest must come.

What it gives

OutputWhat it is
Resistance line breakTrue on the close that breaks above the resistance line.
Support line breakTrue on the close that breaks below the support line.
Resistance line retestTrue when a broken resistance line is retested from above and holds.
Support line retestTrue when a broken support line is retested from below and holds.
Resistance lineThe resistance line's price now (a broken line while it waits for its retest).
Support lineThe support line's price now (a broken line while it waits for its retest).
Resistance line slope %Change of the resistance line per candle, % of its value now (below 0 = falling).
Support line slope %Change of the support line per candle, % of its value now (above 0 = rising).
Resistance line touchesSwing highs the resistance line touches.
Support line touchesSwing lows the support line touches.

What it reads

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

Warm-up

With its default settings, Trendlines needs 541 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 Trendlines with its default settings