OPEN-SOURCE SCRIPT

Pivot Channel Breakouts

2 120
█ OVERVIEW
Pivot Channel Breakouts is an adaptive market-structure indicator. It automatically builds a sloped channel from confirmed High and Low pivots, checks the geometry of the formation, and marks a breakout only when the close moves beyond the channel by a minimum ATR margin.
After a breakout the channel is moved into history, and an optional TP/SL module draws Entry, Stop Loss and up to three Risk:Reward targets. The indicator can be used both to read structure and to plan a potential trade after the breakout.

█ CONCEPTS
The indicator automatically detects pivots and builds the widest possible price channel that still contains all remaining points and candle closes. The goal is to recognize channel formations quickly without drawing the lines by hand.

Pivot-Based Channel Structure
The channel has two independent boundaries:
- Resistance — the upper line from High pivots.
- Support — the lower line from Low pivots.

The channel is drawn only when both sides of the buffer hold the required number of pivots. With the default setting that means at least two High pivots and two Low pivots. Until one side is incomplete, no formation is created.

Each boundary needs at least two pivots. With more points the indicator does not require collinearity. It searches pairs and keeps the pair with the greatest span, provided the remaining pivots and the candle closes stay on the correct side of the line. The first two pivots of the formation must be opposite — one High and one Low — so the channel starts from an alternating structure rather than two extremes of the same side. Envelope fit describes the price structure, not a perfect straight line through every point.

Pivot Detection
Pivot Left is the number of bars before the extreme, Pivot Right is the number of bars after it required for confirmation. Smaller values detect more local turns, larger values produce fewer and usually more significant pivots. A pivot is confirmed only after Pivot Right bars, so detection has a built-in delay.

Pivot Count
This parameter sets how many of the most recent High and Low pivots are kept in the buffer. A value of 2 builds a segment through two points on each side. Higher values increase selectivity: a line is created only when a pair meeting the structural rules can be found. The channel does not appear until both sides have collected the same required number of pivots.

Pivot Age and Channel Width
Max Pivot Age removes old points so a fresh pivot is not paired with a stale extreme. Minimum Channel Width rejects formations that are too short and accidental.

Dynamic Channel Adjustment
Until a confirmed breakout, a wick can bend the active boundary toward the new extreme. A temporary wick pierce does not end the channel. A breakout still requires a close beyond the line with an ATR margin.

ATR-Based Breakout and Close-Based Confirmation
A breakout is valid on the close only:
- above resistance + ATR × multiplier — long,
- below support − ATR × multiplier — short.

A wick alone does not generate a signal. The threshold scales with volatility: a higher multiplier cuts false breakouts, a lower one produces more signals.

Channel History and Pivot Reset
After a breakout the active channel is cut at the breakout bar and moved into history. Max Channels Shown limits how many old formations remain on the chart.
Reset Pivots on Breakout off: the next channel can form immediately from a mix of old and new pivots. On: both buffers are cleared and a completely new set of points must be collected.

TP/SL Framework
Each new breakout can draw:
- Entry — the close of the breakout candle,
- SL — ATR × multiplier or a fixed percent from entry,
- TP1 / TP2 / TP3 — targets as multiples of the Entry–SL distance (RR).

The layout moves with the chart and is closed when price hits SL or the farthest enabled TP.

█ FEATURES
General
- Max channels shown (history) — how many completed channels stay on the chart. Older ones are removed after the limit is exceeded.

Pivots
- Pivot Left / Pivot Right — sensitivity and confirmation delay of pivot detection.
- Pivots required to define a line — number of points in the buffer (2–6) on each side. The channel appears only after that many High pivots and that many Low pivots have been collected.
- Max pivot age (bars) — maximum age of a point.
- Minimum channel width (bars) — minimum length of the formation.
- Line extension to the right (bars) — visual extension of the lines to the right only; it does not affect detection.

Breakout
- ATR Period — ATR length used for the minimum breakout size.
- Minimum breakout size (x ATR), close only — required distance beyond the line on the close.
- Reset pivots on breakout — clears the buffers after a signal.

Appearance
- Resistance / Support Color — boundary colors.
- Trend line transparency — transparency of the channel lines.
- Channel fill color + Fill transparency — fill between the boundaries.
- Show breakout signals — triangles below/above the bar.
- Show dots on pivots — markers on every newly confirmed pivot.
- Dot color — resistance / support pivots.

TP/SL
- Show TP/SL Levels — enables the full layout.
- SL = ATR — SL from ATR or from a percentage.
- ATR Period (TP/SL) — separate ATR for the targets.
- ATR Multiplier for SL / SL % from Entry.
- RR for TP1 / TP2 / TP3.

TP/SL Display
- Show SL / TP1 / TP2 / TP3 Level — independent display of each level and its label.

█ APPLICATIONS
Channel Structure Analysis
Automatic drawing of sloped boundaries instead of connecting pivots by hand. Useful in trends, pullbacks and periods when price respects two parallel or near-parallel edges.

Breakout Confirmation
A triangle marks a close outside the channel with an ATR filter, not a mere line pierce. It is a starting point for further analysis of direction, momentum and context — not a standalone entry signal.

Risk/Reward Planning
After a breakout, Entry, SL and three targets are visible at once. SL can be based on volatility (ATR) or on a fixed percentage.

█ NOTES
- Larger Pivot Left/Right values mean slower, more selective detection.
- The signal is close-only; a wick can only bend the line.
- The breakout threshold scales with ATR.
- After a breakout the channel is archived; the pivot reset setting decides whether the next formation starts from scratch.
- TP/SL is visual R:R planning, not an assessment of trade quality.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.