OPEN-SOURCE SCRIPT
업데이트됨

Trendline Breakout - [NotLazyBear]

4 111
Overextension Trendline Breakout
A multi-pivot trendline detection and breakout system that automatically draws validated support and resistance lines from looped zigzag pivots, confirms trendline integrity through clean-line scanning, and projects Fibonacci extension targets upon breakout. Uses ATR-normalized angle validation and touch-density scoring to distinguish meaningful trendlines from noise.
What It Does
OETB scans price action across a configurable range of pivot lengths (default 5–30 bars) to build a pool of swing highs and lows. It then attempts to fit trendlines through these pivots using three validation layers:
  • Angle Validation: Trendlines must fall within a specified angular range (default 15°–60°) relative to ATR-scaled horizontal distance, preventing flat or near-vertical lines.
  • Touch Density: Lines must connect at least 3 (configurable) pivot points within ATR tolerance, ensuring the trendline is genuinely respected by price.
  • Clean-Line Scan: No intermediate bar may violate the trendline by more than ATR tolerance — confirming the line acted as active support/resistance between its defining pivots.

When a validated trendline is broken by price (with optional ATR buffer and close confirmation), the system plots breakout markers and projects four Fibonacci targets based on the swing amplitude of the broken trendline.
Core Components
  • Looped Pivot Detection: Iterates through minPivLen to maxPivLen simultaneously, collecting highs and lows across multiple time scales. Duplicate bars are resolved by keeping the largest pivot length (most significant swing).
  • ATR-Scaled Angle Calculation: Uses a custom arctangent implementation with ATR normalization to measure trendline steepness in degrees. The X-axis is scaled by (dx/10) × ATR, making angle measurement consistent across volatile and calm markets.
  • Touch Scoring with Tiebreaking: When multiple candidate lines exist, selects the one with most touches; ties broken by longer span (more significant trendline).
  • Forming vs Confirmed Lines: Lines with 2+ touches but below minTouches are tracked as "forming" (dashed, faded) until they gather enough evidence to become confirmed.
  • Breakout with Fibonacci Projection: Upon break, draws 0.618, 1.0, 1.618, and 2.618 extension targets from the breakout point, colored by aggressiveness (green conservative to pink aggressive).
  • Age-Based Expiration: Lines older than maxAge bars (default 200) are marked expired (dotted grey) if unbroken, preventing stale trendlines from cluttering the chart.

Inputs & Parameters
Zigzag Pivots
  • Minimum/Maximum Pivot Length: Range of bar lengths for pivot detection (2–1000, default 5/30).
  • ATR Length: Volatility measurement for normalization (default 14).
  • ATR Deviation Filter: Toggle requiring minimum ATR distance between consecutive same-type pivots to prevent clustering.
  • Minimum Pivots to Connect: Touch threshold for confirmed trendlines (2–10, default 3).

Trendline Validation
  • Minimum/Maximum Angle: Steepness bounds in degrees (0°–89°/1°–90°, default 15°/60°). Filters out horizontal noise and near-vertical spikes.
  • Max Pivot-to-Pivot Span: Maximum bar distance between connected pivots (10–200, default 100).
  • Clean-Line Tolerance: ATR multiplier for how far price may deviate from the line between pivots (default 0.06× ATR).
  • Validate Through Current Bar: Extends clean-line check from last pivot to present bar, ensuring ongoing respect.

Breakout Logic
  • Break Requires Close Beyond Line: If true, breakout requires close; if false, wick penetration suffices (faster, more false positives).
  • Break Buffer: ATR multiplier added beyond the line before break registers (default 0.08× ATR).
  • Max Line Age: Bars before unbroken lines expire (default 200).

Fibonacci Targets
  • Target ratios: 0.618 (conservative), 1.0 (equal move), 1.618 (golden), 2.618 (aggressive) — all configurable.
  • Target Extension: Bars forward to draw target lines (default 5).
  • Individual color selection per target level.

Display
  • Toggle confirmed lines, forming lines, and breakout markers.
  • Color selectors for ascending support (cyan), descending resistance (orange), forming variants (faded), broken (grey), and expired (light grey).
  • Line width adjustment (1–4).

How to Read It
  • Solid Cyan Lines: Confirmed ascending support — at least 3 lows touched the line within tolerance. Price expected to bounce; break signals bearish acceleration.
  • Solid Orange Lines: Confirmed descending resistance — at least 3 highs touched the line. Price expected to reject; break signals bullish breakout.
  • Dashed Faded Lines: Forming trendlines with 2 touches but not yet confirmed. Monitor for additional touches that would validate.
  • Dashed Grey Lines: Broken trendlines — price has crossed through with buffer confirmation. Fib targets are active.
  • Dotted Light Grey Lines: Expired trendlines — exceeded maxAge without breakout, no longer relevant.
  • Breakout Markers:
    • Green ▲ below bar: Descending resistance broken upward — bullish breakout.
    • Red ▼ above bar: Ascending support broken downward — bearish breakdown.
  • Fibonacci Target Labels: "T1 (0.618)" in green, "T2 (1.000)" in blue, "T3 (1.618)" in orange, "T4 (2.618)" in pink — projected horizontally from breakout point.

Practical Usage Guidelines
Trend Continuation Trading
  • Enter long when price bounces off a confirmed cyan support line with rising volume.
  • Enter short when price rejects a confirmed orange resistance line with rising volume.
  • Stop-loss placed beyond the trendline by 1× ATR.

Breakout Trading
  • Wait for close beyond the trendline plus buffer (not just wick).
  • Confirm with volume expansion if available.
  • Target T1 (0.618) for conservative profit; scale out at T2 (1.0); trail remaining to T3/T4.
  • If price reverses back through the broken trendline within 3 bars, the break is likely false — exit immediately.

Forming Line Anticipation
  • When a dashed forming line appears, watch for the next touch. A third touch that holds validates the line and often provides a high-probability entry.
  • If price violates a forming line before it reaches minTouches, the line is invalidated and removed.

Important Notes
  • Custom Arctangent Implementation: The script includes a manual f_atan function using Taylor series expansion (12 terms) to avoid dependency on built-in math.atan, with f_atan2 handling all quadrants. This ensures consistent angle calculation across Pine versions.
  • Angle Normalization: The X-axis in angle calculation is normalized by (dx/10) × ATR, meaning a 10-bar move equal to 1 ATR produces a 45° angle reference. This makes angle thresholds market-adaptive.
  • Duplicate Resolution: When the same bar is detected as a pivot across multiple lengths, the system keeps the longest length (most significant swing) rather than creating duplicate entries.
  • Clean-Line Scan Performance: The validation iterates every bar between pivots and optionally to current bar. On very long spans (>100 bars) this is computationally intensive; reduce maxSpan or disable checkToNow for faster performance.
  • Forming Line Cleanup: Forming lines are not automatically removed when their underlying pivots age out — they expire via maxAge only. Confirmed lines are removed immediately on break or expiration.
  • Break Buffer Purpose: The 0.08× ATR buffer prevents false breaks from single-tick wicks. In high-volatility markets, increase buffer; in low-volatility, decrease or set to 0 for tighter triggers.
  • No Repainting: Pivots use standard ta.pivothigh/ta.pivotlow with symmetric right bars (pLen). Breakout detection uses confirmed close when breakOnClose is enabled. All line objects are historical and do not shift retrospectively.
  • Target Line Persistence: Fib target lines extend only fibExtBars forward (default 5) and are not automatically extended. They persist as static historical objects.
릴리즈 노트
updated image
릴리즈 노트
Updated title

면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.