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
| Setting | Default | Range | What it does |
|---|---|---|---|
| atr_period | 14 | 1 to 500 | ATR length (Wilder) for every buffer. |
| swing_k | 2 | 0.1 to 20 | Swing reversal in ATRs: a pivot is confirmed when a close moves this far back. |
| swing_min_pct | 0.1 | 0 to 10 | Smallest swing reversal, % of the close. |
| floor_pct | 0.02 | 0 to 10 | Smallest buffer of this detector, % of the close (each buffer is the larger of this and its ATR multiple). |
| touches | 3 | 2 to 10 | Swing points a line must touch (the first and the newest included). |
| tol_k | 0.25 | 0 to 5 | A swing point within this many ATRs of the line touches it. |
| min_spacing | 5 | 1 to 500 | Fewest candles between two counted touches. |
| min_length | 10 | 2 to 2000 | Shortest line, in candles from its first to its newest touch. |
| max_length | 300 | 3 to 2000 | Longest line, in candles from its first touch to now (an older line ends). |
| max_through | 0 | 0 to 50 | Closes allowed beyond the line (by more than tol_k ATRs) while it formed. |
| break_k | 0 | 0 to 5 | A break is a close beyond the line by this many ATRs. |
| retest_bars | 20 | 1 to 500 | Candles after the break in which the retest must come. |
What it gives
| Output | What it is |
|---|---|
| Resistance line break | True on the close that breaks above the resistance line. |
| Support line break | True on the close that breaks below the support line. |
| Resistance line retest | True when a broken resistance line is retested from above and holds. |
| Support line retest | True when a broken support line is retested from below and holds. |
| Resistance line | The resistance line's price now (a broken line while it waits for its retest). |
| Support line | The 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 touches | Swing highs the resistance line touches. |
| Support line touches | Swing 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