trend fits diagonal rising support and falling resistance trendlines across recent fractal pivots, rejecting any candidate line violated by a candle close beyond tolerance.
Parameters
| Parameter | Default | Range | Type | Timeframe overrides |
|---|---|---|---|---|
window |
500 |
60..2000 |
integer | — |
pivotSpan |
3 |
2..10 |
integer | 4 on <= 5m, 2 on >= 1d |
tolAtr |
0.25 |
0.05..1.5 |
number | — |
maxPivots |
24 |
4..40 |
integer | — |
minTouches |
3 |
2..10 |
integer | — |
max |
2 |
1..5 |
integer (per side) | — |
Algorithm & Nuances
- Directional pivot pairs: Evaluates pairs
(a, b)among the most recentmaxPivotsswing lows (slope > 0, rising support) and swing highs (slope < 0, falling resistance). - Anti-degenerate guards: Rejects pairs closer than
4bars (b - a < 4) or steeper than1.5 * atr[b]per bar. - Zero close violations: Walks every bar
kfromaton - 1. If any candle closes past the line by more thanatr[k] * tolAtr, the candidate is discarded (closesBeyondis always0). - Touch deduplication: Counts touches where
|price[k] - line(k)| <= atr[k] * tolAtr, enforcing at leastTOUCH_GAP = 3bars between touches so a tight sideways cluster cannot inflate touch counts. - Composite score:
tightness = max(0, 1 - min(1, (errSum / touches) / max(tolAtr, 1e-6))) spanRatio = min(1, (lastTouch - a) / max(1, 0.4 * n)) score = touches + 0.8 * (lastTouch / (n - 1)) + 0.6 * spanRatio + 0.4 * tightness - 0.35 * min(maxWickAtr, 2) - Two-touch fallback: If a side produces zero lines meeting
minTouches(whenminTouches > 2), the engine retries withminTouches = 2and flagsfacts.relaxed = true. - Deduplication: Keeps up to
maxlines per side, rejecting candidates that share anchoraorbor project within0.5 * atr[n - 1]of an already selected line at barn - 1.
Drawings & Facts
- Drawings: Up to
2 * maxextendedtrendlinerays (extend: true) labeledRising · N touches('up') orFalling · N touches('down'). - Facts (
TrendFacts):up[],down[], andrelaxedboolean. Each line reportsdir,from,to,slope,touches,touchTimes,closesBeyond,maxWickAtr,tightness,atEnd, andscore.
Activation
- Studies menu:
Trendlines(Trend) - Slash command:
/trend - Chat phrases:
trend,trendline,trendlines,tl,tls