Auto Channel [SciQua]Auto Channel
Purpose
Auto Channel finds the single best parallel price channel from recent price action and keeps it updated in real time. It uses ZigZag pivots to build candidate channels, scores each candidate for quality, then plots the winner. When price closes outside the channel, the script flags a breakout and can fire alerts.
How it works
1. ZigZag pivots
The script uses TradingView’s TradingView/ZigZag/7 library to generate a stream of swing highs and lows based on a percentage reversal threshold and a leg depth. These pivots are the only points the channel logic evaluates, which keeps the search fast and focused on structure rather than noise.
2. Channel candidates
From the most recent pivots, the script forms all combinations of two swing highs and two swing lows.
It computes a slope for the high line and a slope for the low line and requires that they be nearly parallel within a user-defined tolerance.
3. Quality scoring and selection
For every valid candidate, the script checks the recent pivot segments against the trial channel and computes:
Inside ratio: fraction of tested pivots that sit fully inside the channel after applying the tolerance buffer.
Violation sum: total magnitude of the breaches for any pivots outside the channel.
Current width: distance between upper and lower lines at the current bar.
The “best” channel is chosen by:
1. highest inside ratio
2. then widest current width
3. then smallest violation sum
4. Plot and projection
The upper and lower lines are anchored to the chosen pivot pairs and extend to the left. The script also projects each line to the current bar to compute the live upper and lower channel prices. Those levels drive the breakout checks and alerts.
5. Breakouts and alerts
A breakout is detected when the bar closes above the projected upper line or closes below the projected lower line, after applying the tolerance buffer. Triangle markers highlight fresh breakouts, and you can enable alert conditions to automate notification or strategy handoff.
Inputs:
ZigZag
Price deviation for reversals (%)
Default 0.2. Larger values produce fewer, larger swings. Smaller values produce more, smaller swings.
Pivot legs
Default 2. Controls the lookback depth ZigZag uses to confirm pivots.
ZigZag Color
Visual only.
Tip: If you are not seeing a stable channel, increase the ZigZag percentage to reduce minor swings.
Channel search
Number of recent pivots to consider
Default 12. Higher values search more history and try more channel combinations. Lower values make the search faster and more reactive.
Max slope difference for parallel
Default 0.0005. Maximum allowed difference between the upper and lower line slopes. Smaller values enforce stricter parallelism.
Max price tolerance outside channel
Default 0.0. A buffer added to the channel boundaries during validation and breakout checks. Use this to ignore tiny wicks that poke the lines.
Minimum inside to outside pivots ratio for valid channel (0.00–1.00)
Default 1.00. Require that at least this fraction of checked pivots lie inside the channel. For a more permissive fit, try 0.60 to 0.85.
Styling
Upper Line Color
Lower Line Color
Breakout Above Color
Breakout Below Color
Plots and visuals
Upper channel line
Lower channel line
Triangle markers on the bar that first confirms a close outside the channel, above or below.
Lines extend left from their pivot anchors. Projection to the current bar is used internally to test for breakouts and to set alerts.
Alerts
The script defines two alert conditions:
Close Above Channel
Triggers when the bar closes above the projected upper line plus tolerance.
Close Below Channel
Triggers when the bar closes below the projected lower line minus tolerance.
Practical usage
Trend channels
In a steady trend, a high inside ratio with a moderate width often highlights the dominant channel. Consider trend entries near the lower line in an uptrend or near the upper line in a downtrend, with exits or stops beyond the opposite boundary.
Breakout trades
Combine the channel breakout alert with volume or a separate momentum filter. The tolerance input helps avoid false triggers from small wicks.
Tuning for timeframe and symbol
• Faster markets or lower timeframes usually benefit from a larger ZigZag percentage and a smaller pivot count.
• Slower markets or higher timeframes can use more pivots and a tighter slope difference to enforce cleaner geometry.
Notes and limitations
Channels are derived from ZigZag pivots. If your ZigZag settings change, the detected channel will also change.
The script plots only the single best channel at any time to keep the chart clean.
Breakout markers appear on confirmed bars. For historical bars, markers appear only where a breakout would have been confirmed at that time.
Lines extend left from their anchors. The script projects the lines internally to the current bar for checks and alerts.
License and attribution
License
Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).
Open source for educational and personal use only. Commercial use requires written permission.
Attribution
© 2025 SciQua — Joshua Danford
Libraries
Uses TradingView/ZigZag/7.
Changelog
v1.0
Initial release. Automatic parallel channel detection from ZigZag pivots, quality scoring, live plotting, and close-based breakout alerts.
FAQ
Why do I not see any channel sometimes?
There may not be a valid pair of highs and lows that pass the slope, inside ratio, and tolerance checks. Loosen the constraints by increasing Max slope difference, lowering Minimum inside ratio, or increasing the ZigZag percentage.
The channel looks too narrow or too wide?
Adjust Number of recent pivots and Minimum inside ratio. A higher inside ratio tends to favor cleaner, sometimes wider channels. A lower ratio may admit narrower, more reactive channels.
How can I reduce false breakout alerts?
Increase Max price tolerance outside channel to ignore small wicks. Add a volume or momentum confirmation in your personal alert workflow.
Thank you for using Auto Channel . Feedback and improvements are welcome.