OPEN-SOURCE SCRIPT
Pattern Scanner AI AlgoCode

Automatic chart pattern detection with a complete, ready-to-trade level map.
Pattern Scanner AI AlgoCode is a pivot-based structure engine that finds classic reversal and continuation patterns in real time and turns each of them into a clean trade plan: entry, retest, stop-loss and two targets with a live R:R readout.
What it detects
Entry Engine
A pattern alone is not a signal. The Entry Engine confirms the actual breakout of the neckline / wedge boundary:
ATR breakout buffer — price must clear the level by a volatility-scaled margin, filtering micro-fakeouts.
Body close confirmation — optional requirement that the candle body, not just the wick, closes beyond the level.
Volume filter — optional requirement of volume above its 20-period average by a chosen multiplier.
Retest level — an additional, better-priced entry line for traders who wait for the pullback into the broken level.
Cooldown — a minimum bar distance between signals to avoid clusters of duplicates.
Trade levels on every setup
E (Entry) — breakout level projected forward as a solid ray.
Retest — dotted alternative entry.
SL — stop beyond the pattern extreme with an ATR safety buffer.
TP1 — classic measured move (pattern height).
TP2 — extended target (default 1.618 × pattern height).
R:R — real risk/reward, calculated with the buffered stop, printed on the setup label.
Risk and reward zones are shaded so the trade structure is readable at a glance.
Visualization
Pattern skeleton drawn through the actual pivot points, with marked vertices.
Compact price labels for every level, placed to the right of the signal bar.
Full setup history: the last N setups stay on the chart (configurable up to 40), older drawings are pruned automatically to keep performance high.
Optional pivot markers for a quick health check of your settings.
Bullish / bearish signal triangles on the breakout bar.
Alerts
Built-in alert() calls and separate bullish / bearish alertcondition streams, including the pattern name, ticker and timeframe — ready for TradingView notifications, webhooks and bots.
Settings overview
Pivots & accuracy — pivot left/right, tolerance mode (ATR / percent), min height, min/max width, min R:R, cooldown.
Entry engine — breakout buffer, body-close requirement, volume filter, retest offset, stop buffer, TP2 multiplier.
Patterns — enable or disable each family independently.
Display — levels, pattern outline, pivot points, risk/reward zones, projection length, history depth, alerts.
How to use
Add the indicator to any symbol and timeframe.
Increase Pivot left / right on lower timeframes for cleaner structure, decrease for more signals.
Keep the body close confirmation on for stricter entries; add the volume filter on liquid instruments.
Trade the E level on the breakout candle, or wait for the Retest line for a better price.
Manage the position with SL, take partials at TP1, run the rest to TP2.
Notes
Works on all markets and timeframes (crypto, forex, indices, stocks). Non-repainting on confirmed breakouts: signals fire on bar close conditions, while pivots require their right-side confirmation window by design.
This script is a technical analysis tool, not financial advice. Always test settings on your instrument and manage risk.
AI AlgoCode
Pattern Scanner AI AlgoCode is a pivot-based structure engine that finds classic reversal and continuation patterns in real time and turns each of them into a clean trade plan: entry, retest, stop-loss and two targets with a live R:R readout.
What it detects
- Double Top / Double Bottom
- Triple Top / Triple Bottom
- Head & Shoulders / Inverse Head & Shoulders
- Rising Wedge / Falling Wedge
- Every pattern is validated by geometry, not by guesswork: swing highs and lows are confirmed with configurable pivot windows, peak equality is measured with an ATR- or percent-based tolerance, and each candidate must pass minimum height, minimum/maximum width and minimum R:R filters before it is plotted.
Entry Engine
A pattern alone is not a signal. The Entry Engine confirms the actual breakout of the neckline / wedge boundary:
ATR breakout buffer — price must clear the level by a volatility-scaled margin, filtering micro-fakeouts.
Body close confirmation — optional requirement that the candle body, not just the wick, closes beyond the level.
Volume filter — optional requirement of volume above its 20-period average by a chosen multiplier.
Retest level — an additional, better-priced entry line for traders who wait for the pullback into the broken level.
Cooldown — a minimum bar distance between signals to avoid clusters of duplicates.
Trade levels on every setup
E (Entry) — breakout level projected forward as a solid ray.
Retest — dotted alternative entry.
SL — stop beyond the pattern extreme with an ATR safety buffer.
TP1 — classic measured move (pattern height).
TP2 — extended target (default 1.618 × pattern height).
R:R — real risk/reward, calculated with the buffered stop, printed on the setup label.
Risk and reward zones are shaded so the trade structure is readable at a glance.
Visualization
Pattern skeleton drawn through the actual pivot points, with marked vertices.
Compact price labels for every level, placed to the right of the signal bar.
Full setup history: the last N setups stay on the chart (configurable up to 40), older drawings are pruned automatically to keep performance high.
Optional pivot markers for a quick health check of your settings.
Bullish / bearish signal triangles on the breakout bar.
Alerts
Built-in alert() calls and separate bullish / bearish alertcondition streams, including the pattern name, ticker and timeframe — ready for TradingView notifications, webhooks and bots.
Settings overview
Pivots & accuracy — pivot left/right, tolerance mode (ATR / percent), min height, min/max width, min R:R, cooldown.
Entry engine — breakout buffer, body-close requirement, volume filter, retest offset, stop buffer, TP2 multiplier.
Patterns — enable or disable each family independently.
Display — levels, pattern outline, pivot points, risk/reward zones, projection length, history depth, alerts.
How to use
Add the indicator to any symbol and timeframe.
Increase Pivot left / right on lower timeframes for cleaner structure, decrease for more signals.
Keep the body close confirmation on for stricter entries; add the volume filter on liquid instruments.
Trade the E level on the breakout candle, or wait for the Retest line for a better price.
Manage the position with SL, take partials at TP1, run the rest to TP2.
Notes
Works on all markets and timeframes (crypto, forex, indices, stocks). Non-repainting on confirmed breakouts: signals fire on bar close conditions, while pivots require their right-side confirmation window by design.
This script is a technical analysis tool, not financial advice. Always test settings on your instrument and manage risk.
AI AlgoCode
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.