INDICATOR MANUAL
Automatic trendline indicatorAuto Trendlines [AFD] · full manual · published to TradingView
Draw and maintain a small set of confirmed-pivot trendlines only after every candidate passes the published four-part validity rule.
Start here
What the indicator does, the questions it can help answer, and its fresh-install defaults.
Two confirmed pivot highs define a descending candidate and two confirmed pivot lows define an ascending candidate. A pair must be same-side, progressive, unpierced between its anchors, and still unviolated through the current bar before it can be drawn.
The default three-length mode independently searches 10-, 20-, and 40-bar pivots on each side, for at most six live lines. Each tier refuses an anchor pair already held by another tier on that side, and among all qualifying pairs it selects the line nearest the current close.
Live lines are maintained rather than silently replaced. Touches are descriptive counts inside an ATR-scaled band. A confirmed violation or age limit retires a line and preserves selected history; only violations create alerts.
Fresh-install defaults8 documented defaults
Swipe or scroll horizontally to see every column.
| Area | Default | Result |
|---|---|---|
| Swing search | Strength 10 · 10 pivots | Searches recent confirmed pivot pairs; every base pivot appears at least 10 bars after its origin. |
| Three lengths per side | On · ×2 · ×4 | Uses pivot strengths 10, 20, and 40—not 5, 10, and 20—with up to three independent lines per side. |
| Candidate validity | 0.25 ATR pierce · 0 minimum span · 0 minimum touches | Allows a limited between-anchor pierce but adds no span or pre-draw touch requirement. |
| Lifecycle | Wick through · 0 violation tolerance · 0.25 ATR touch band | Any trade beyond a live line retires it; touches count only inside the symmetric tolerance band. |
| Age and history | 300 bars · 5 retired lines | Ages out anchors older than 300 bars and keeps up to five retired line objects visible. |
| Live lines | Both sides · width 3 · extend right | Draws short/medium/long tiers at effective widths 2/3/4, so longer tiers are thicker. |
| Labels and emphasis | Touch color · glow · labels · fill on | Shows touch counts, a halo, and optional shading between the shortest and longest live line on each side. |
| Empty and retired states | Empty note on · gray 45% · width 1 · dotted | Explains when no pair qualifies and visibly distinguishes retired history. |
How it works
How the indicator turns chart data into the states and drawings you see.
Confirmed same-side pivots
Detection always uses wick-based ta.pivothigh() and ta.pivotlow() with equal left and right strength. Anchor Price can move the drawn point to the pivot bar’s body, but it does not change which pivot was detected.
Four-part validity rule
Both anchors must come from the same side; the second must be lower for descending or higher for ascending; no between-anchor bar may pierce beyond the configured tolerance; and no bar since the second anchor may already have violated the candidate.
Independent tier selection
Short, medium, and long tiers keep separate pivot pools. Each scans every usable pair, excludes a pair held by another tier on the same side, applies minimum span and touch requirements, then selects the qualifying line nearest the current close.
ATR-scaled tolerances
Pierce, violation, and touch tolerances multiply a simple mean of true range over ATR Length. This is not Wilder’s ta.atr(). Touch is a two-sided band: a bar far through the line is not counted merely because it crossed the band on the way.
Confirmed lifecycle
On a confirmed bar, a live line can be violated, aged out, switched off, or increment its touch count. Violation and age both freeze and restyle the line; switching a tier off removes it without adding a misleading retired record.
Maintained drawings
The line’s right endpoint follows the current bar when Extend to the right is on. Longer tiers are thicker, glow is a second line object, labels state tier, touches, and tolerance, and the optional fill only spans two already-drawn lines.
Screener and alert surfaces
Ten Data Window plots report nearest line prices, ATR distances, touch counts, presence, and live counts by side. Two fixed confirmed-bar alerts report a descending or ascending line violation; age retirement does not fire them.
Output and state reference9 documented states
Swipe or scroll horizontally to see every column.
| Output or state | When it appears | Meaning |
|---|---|---|
| DESCENDING LINE | Valid pair of confirmed pivot highs | Nearest qualifying falling line for one enabled swing tier. |
| ASCENDING LINE | Valid pair of confirmed pivot lows | Nearest qualifying rising line for one enabled swing tier. |
| SHORT / MID / LONG | Three-length mode on | Independent 10/20/40 default pivot searches, drawn progressively thicker. |
| TOUCH COUNT | Bar lands inside the selected two-sided band | Historical count shown with its ATR tolerance; not a strength rating. |
| RETIRED LINE | Confirmed violation or anchor age | Frozen historical drawing using the broken-line style. |
| NO VALID LINE | No live qualifying pair on an enabled side | On-chart explanation instead of a forced invalid drawing. |
| SHADED GAP | Shortest and longest line both live on a side | Fill between two line objects; not a level, zone, or signal. |
| DISTANCE / PRESENCE | Data Window or Screener | Nearest line price, ATR distance, touches, presence flag, and live count per side. |
| VIOLATION ALERT | Confirmed bar retires one or more lines by price | Side-specific historical event; age retirement is excluded. |
Settings
The 30 rows below match the published Pine input surface across Detection, Lifecycle, and Display. Conditional multiplier and label controls remain dimmed until their parent feature is enabled.
📐 Detection11 inputs
Swipe or scroll horizontally to see every column.
| Setting | Control | Default | Choices, limits & availability |
|---|---|---|---|
| Swing StrengthswingInput | Whole number | 10 | Min 1 · Max 50 |
| Pivots SearchedpoolInput | Whole number | 10 | Min 2 · Max 12 |
| Pierce Tolerance (× ATR)pierceInput | Decimal | 0.25 | Min 0.0 · Max 3.0 · Step 0.05 |
| ATR LengthatrLenInput | Whole number | 14 | Min 1 · Max 200 |
| Bars to ApplyhorizonInput | Whole number | 300 | Min 0 · Max 5000 |
| Minimum Anchor SpanspanInput | Whole number | 0 | Min 0 · Max 200 |
| Anchor PriceanchorInput | Choice / text | Wick | Wick · Body |
| Minimum TouchesminTouchInput | Whole number | 0 | Min 0 · Max 10 |
| Three lengths per sidetiersInput | Toggle | On | — |
| Medium length multiplemidMultInput | Whole number | 2 | Min 2 · Max 10 | Conditional |
| Long length multiplelongMultInput | Whole number | 4 | Min 2 · Max 20 | Conditional |
📊 Lifecycle4 inputs
Swipe or scroll horizontally to see every column.
| Setting | Control | Default | Choices, limits & availability |
|---|---|---|---|
| Violated BybasisInput | Choice / text | Wick through | Wick through · Close through |
| Violation Tolerance (× ATR)violateInput | Decimal | 0.0 | Min 0.0 · Max 3.0 · Step 0.05 |
| Touch Tolerance (× ATR)touchInput | Decimal | 0.25 | Min 0.0 · Max 3.0 · Step 0.05 |
| Retired Lines KeptretireInput | Whole number | 5 | Min 0 · Max 10 |
🎨 Display15 inputs
Swipe or scroll horizontally to see every column.
| Setting | Control | Default | Choices, limits & availability |
|---|---|---|---|
| Descending linesshowFallingInput | Toggle | On | — |
| Ascending linesshowRisingInput | Toggle | On | — |
| DescendingfallingColorInput | Color | #FF1744 · 0% transparent | Conditional |
| AscendingrisingColorInput | Color | #00E676 · 0% transparent | Conditional |
| Line widthwidthInput | Whole number | 3 | Min 1 · Max 5 |
| Extend to the rightextendInput | Toggle | On | — |
| Colour by touch countrampInput | Toggle | On | — |
| GlowglowInput | Toggle | On | — |
| Show touch countshowLabelInput | Toggle | On | — |
| Label positionlabelPosInput | Choice / text | Right of line | Right of line · Below, centered | Conditional |
| Shade between the lengthsfillInput | Toggle | On | — |
| Note when no valid lineshowEmptyNoteInput | Toggle | On | — |
| Broken linebrokenColorInput | Color | Gray · 45% transparent | — |
| WidthbrokenWidthInput | Whole number | 1 | Min 1 · Max 5 |
| StylebrokenStyleInput | Choice / text | Dotted | Solid · Dashed · Dotted |
Alerts and limitations
What can notify you, what can change the output, and what the indicator cannot establish.
2 fixed alert conditions
A confirmed bar violated and retired at least one live descending line.
A confirmed bar violated and retired at least one live ascending line.
Limits to keep visible
- Confirmed pivots are delayed by their right-side strength. At the default three lengths, candidate anchors confirm 10, 20, or 40 bars after origin.
- Whether the published script repaints has not been established by the repository’s replay checklist, so this manual makes no blanket repaint claim.
- Log-scale rendering and maximum-load drawing performance were not established by the published-build evidence record.
- Bars to Apply bounds pivot pools and ages live lines. A lower value can leave longer tiers with too few confirmed pivots to draw.
- Minimum Touches delays the same qualifying line until more history exists; it is not a quality, strength, or probability filter.
- Pierce, touch, and violation tolerances use a simple mean of true range, not Wilder’s ATR, and therefore can differ from other ATR-scaled tools.
- A drawn line reaches no more than 9,500 bars into the past even when its logical anchor is older, avoiding the platform’s past-coordinate limit.
- The script reads only the active chart’s OHLC series and makes no request.*() calls. Different symbols, timeframes, sessions, and loaded history can produce different pivots and lines.
- Lines, counts, shades, and alerts describe past chart geometry. They do not predict a reaction, breakout, target, entry, or outcome.
Troubleshooting
Start with what you see on the chart. Each answer explains the likely cause and the first setting, timeframe, or data condition to check.
Why is no trendline showing on one side?
Either that side is turned off or no recent pair of confirmed highs or lows passed all four line checks. Turn on Note when no valid line to confirm that the script is deliberately refusing the available pairs, then review the side switch and candidate filters.
Why did a trendline appear long after its anchor?
The line cannot use a pivot until enough bars form to confirm it. With the default three lengths, short, medium, and long anchors confirm after 10, 20, and 40 bars. Lower strengths appear sooner but also accept smaller turns.
Why are the default swing lengths 10, 20, and 40?
They are three confirmation speeds built from a base Swing Strength of 10 and multipliers of 2 and 4. Short, Mid, and Long describe the pivot horizon—not the line’s quality or chance of holding.
Why is the longer-term trendline thicker?
Thickness identifies the tier at a glance. With base width 3, Short draws at 2, Mid at 3, and Long at 4. A thicker line is a longer pivot horizon, not a stronger setup.
Why is the touch count higher than the touches I saw after the line appeared?
The script also counts valid touches between the second anchor and the later bar that confirmed the line. Those touches happened before the drawing became visible, so the first label can start above zero.
Why did a trendline retire without an alert?
The line may have reached the Bars to Apply age limit rather than being broken by price. Age retirement keeps the historical drawing but does not fire a violation alert. Increase Bars to Apply if you want eligible lines kept longer.
Why did Minimum Touches make a line appear later and farther away?
The script waits until the candidate has the required number of touches before adopting it. By then, price and the projected line may be farther apart. Lower Minimum Touches if you want earlier adoption; the setting is not a strength score.
Why doesn’t the alert message show my tolerance value?
TradingView requires this fixed alert message to be written before your input values are known, so it cannot insert the number. Check the saved alert’s Violated By and Violation Tolerance settings when reviewing the event.