Auto Chart Pattern Indicators in Pine Script: How They Detect Patterns and Where They Mislead (2026 Guide)

Auto Chart Pattern Indicators in Pine Script: How They Detect Patterns and Where They Mislead (2026 Guide)

How TradingView's built-in pattern tools and open-source Pine scripts find triangles and double tops, why every flag arrives late, and how to test one.

An auto chart pattern indicator in Pine Script finds swing highs and lows with a pivot function, joins them into a zigzag, and checks whether trend lines through the last five or six swings form a recognisable shape. TradingView ships its own set of these tools, and the open-source community publishes many more. Every one of them works from pivots, and a pivot only exists after a fixed number of bars have closed past it, so the flag always lands late. This guide covers where the tools live, how the detection logic works line by line, a short script you can read and adapt, the settings that change what gets flagged, and how to test one before you let it near an order.

Where auto chart pattern indicators live on TradingView

TradingView's own tools sit in the Indicators menu: click "Technicals" and open the "Patterns" tab. "All Chart Patterns" sits at the top of that list, with separate entries for individual shapes and for Elliott Waves. According to TradingView's help page on auto chart patterns, the platform "searches for patterns within the most recent 600 bars/candles/price points displayed." To look further back, the same page points you to Bar Replay.

The built-in set left open beta on March 23, 2023. The end-of-beta announcement said that "new Chart Patterns will be available only for Premium subscription holders" and that "there are currently 15 indicators available that define different patterns." Check your own plan before you build a workflow around them, because TradingView changes plan contents more often than it changes the indicators.

The help page also carries a warning worth taking at face value. It says indicators "can also be misleading by adding unnecessary barriers and making you overly reliant on automation," and suggests "studying the chart yourself" first. In other words, the vendor itself treats the tool as a second opinion.

If you are not on Premium, the public script library is the other route. Search "auto chart patterns" in the Indicators dialog and you will find dozens of community scripts. Quality varies a lot. Open-source scripts let you read the logic; invite-only and closed scripts ask you to trust the author's description. For the comparison of paid scanners outside TradingView (TrendSpider, thinkorswim, Finviz and others), see our roundup of the best apps for stock patterns.

How an auto chart pattern indicator in Pine Script finds a pattern

Every pattern detector you will meet on TradingView runs the same four steps, with different tuning. It finds pivots, links them into a zigzag, fits lines through the zigzag points, and names the shape the lines make.

A candlestick chart with small dots marking each swing high and swing low, a thin zigzag line joining the dots, and two straight trend lines drawn through the last five dots forming a narrowing triangle
Pattern indicators never see candles as shapes; they see a handful of pivot dots and test which lines fit through them.

Step 1, pivots. Pine Script has two built-in functions for this, ta.pivothigh() and ta.pivotlow(). Each takes a left-bars and a right-bars count. A bar is a pivot high when its high is above the highs of the left-bars before it and the right-bars after it. The function returns na on every other bar. The example script on TradingView's Pine Script fills page uses 15 left bars and 5 right bars, with the comment "The number bars to the right for pivot confirmation," and then places its drawing at bar_index - RIGHT_BARS so the point lands on the actual peak.

TradingView's built-in set uses five and five. Its announcement says "patterns are built on pivot points, analyzing 5 candles before and 5 candles after each specific candle."

Step 2, the zigzag. The pivots are joined in order, alternating high and low. Many scripts run several zigzags at once with different lengths, so a small swing pattern and a large one can both be found on the same chart.

Step 3, trend lines. The detector takes the last five or six zigzag points and tries to draw one line through the highs and one through the lows. The open-source Auto Chart Patterns script by Trendoscope, an Editors' Pick, spells out its rules: the upper line must touch all the pivot highs, the lower line must touch all the pivot lows, the two lines must not cross between the first and last pivot, and "none of the candles from starting pivot to ending pivot should fall outside the trend lines." An error threshold decides how close "touch" has to be.

Step 4, the name. Once two valid lines exist, the shape is a matter of slope. Both lines rising and converging is a rising wedge. A flat top and a rising bottom is an ascending triangle. Two parallel lines is a channel. Trendoscope's script classifies 13 shapes this way, from ascending and descending channels to expanding and contracting wedges and triangles. When several patterns overlap, TradingView's built-in tools keep the one with the highest priority.

Two things follow from this design. The detector knows nothing about volume, the trend before the pattern, news, or where the pattern sits relative to a weekly level. And it can only find shapes that are defined as lines through pivots. A cup and handle, a rounded bottom, or a bull flag with a messy pole may be missed or misnamed, depending on how the script defines it. The shapes themselves are covered in our guide to stock chart patterns; the detector only knows their geometry.

The confirmation delay: why every flag shows up late

A pivot high with five right bars cannot be confirmed until five more bars have closed below it. A pattern built from five or six pivots therefore cannot be flagged until the last pivot is confirmed, which is at least the right-bars count after the last swing point. On a 5-minute chart with the default five right bars, that is 25 minutes after the swing that completes the shape. On a daily chart it is a full trading week.

Confirmation delay on a 5-minute chart is the right-bars setting times five minutes; the pattern cannot be flagged before its last pivot exists.

The delay is the price of reliability. A smaller right-bars count flags sooner, but it also calls a pivot on every two-bar wiggle, so the zigzag gets noisy and the detector finds triangles in what is really chop. A larger count gives cleaner swings and later flags. No setting gets you both.

What the delay means in practice: by the time the indicator draws an ascending triangle, price has usually already moved off the last swing low toward the flat top. Some of the room between the low and the breakout level is gone. If your plan was to buy near the rising trend line, the flag arrived too late for that entry, and the only entry left is the breakout itself. Treat a fresh flag as a prompt to look at the chart and decide whether a trade is still available. It does not tell you a trade exists.

This is also why scripts that draw on the pivot bar look so accurate on history. The label sits on the exact high, but on the live chart that label did not exist until several bars later. A chart screenshot of a pattern indicator shows where the flag was drawn, never when it appeared.

"In Progress" patterns and repainting

TradingView's built-in tools have an "In Progress" mode. With it on, the indicator also shows unfinished patterns whose "last two points have not yet been found and may not be reversal points," in the words of the announcement. Turn it off and you only see formed patterns, which sit further back from the last candle. An In Progress pattern can change shape or vanish as new bars print. That is by design, and it is the behaviour most traders mean when they say a pattern indicator "repaints."

A split chart: on the left a neat triangle drawn on clean historical candles, on the right a live chart where the same triangle outline is faded and redrawn twice as new candles appear
An unfinished pattern is a guess that updates with every bar; history only shows the version that survived.

TradingView's own Pine Script page on repainting defines it as "script behavior causing historical vs realtime calculations or plots to behave differently," and estimates that "more than 95% of indicators in existence exhibit some form of repainting behavior." It sorts repainting into four groups and puts "most scripts based on pivots" in the "potentially misleading" group. The mechanism it describes is the one above: "Scripts detecting pivots after 5 bars have elapsed will often go back in the past to plot pivot levels or values on the actual pivot." The page's advice is to plot without an offset by default and let the user switch on past-plotting through an input.

Pattern scripts can repaint in a second way. Some keep updating a detected pattern as new pivots arrive, swapping its anchor points for a better fit. Trendoscope's script added an option for this in January 2024 and left it off by default, noting that repainting "often carries a negative connotation." With the option off, a drawn pattern stays as first drawn. With it on, the history looks cleaner and the live behaviour gets harder to judge.

The fix for alerts is the same in every case. A condition gated by barstate.isconfirmed only evaluates when the bar closes. The repainting page calls this "a simple way to avoid repainting" and is blunt about the trade-off: confirmed signals "will also trigger signals later than repainting scripts." If you set alerts on a pattern indicator, set them to fire once per bar close, never on every tick of a forming bar. We go deeper on the general problem in our guide to free technical analysis software with buy sell signals, which covers repainting arrows.

A minimal pattern detector you can read

The fastest way to understand what a pattern indicator can and cannot know is to read a small one. The script below is a sketch for learning, not a tested trading tool. It looks for two pivot highs within a percentage tolerance of each other, which is the raw ingredient of a double top, and it does nothing else.

//@version=6
indicator("Double top candidates (pivot-based)", overlay = true)

leftBars  = input.int(5, "Left bars", minval = 1)
rightBars = input.int(5, "Right bars", minval = 1)
tolPct    = input.float(1.0, "Peak match tolerance (%)", minval = 0.1)
minGap    = input.int(10, "Minimum bars between peaks", minval = 1)
drawPast  = input.bool(false, "Draw label on the pivot bar (looks earlier than it was)")

ph = ta.pivothigh(high, leftBars, rightBars)

var float lastPeak    = na
var int   lastPeakBar = na

if not na(ph)
    int peakBar = bar_index - rightBars
    if not na(lastPeak) and peakBar - lastPeakBar >= minGap and math.abs(ph - lastPeak) / lastPeak * 100 <= tolPct
        int drawBar = drawPast ? peakBar : bar_index
        label.new(drawBar, ph, "Double top?", style = label.style_label_down, color = color.orange, textcolor = color.black)
        alert("Double top candidate: peaks " + str.tostring(lastPeak) + " and " + str.tostring(ph), alert.freq_once_per_bar_close)
    lastPeak    := ph
    lastPeakBar := peakBar

Read it with the earlier sections in mind:

  1. ta.pivothigh(high, leftBars, rightBars) only returns a value rightBars bars after the peak, so the label appears on the bar where the pivot was confirmed unless you switch drawPast on.
  2. With drawPast on, the label moves back to the peak. History will look sharper and the alert will still have fired late. This is the "plotting in the past" case from TradingView's repainting page, made into a visible choice.
  3. The alert uses alert.freq_once_per_bar_close, so it waits for the bar to close and cannot fire on a pivot that a later tick removes.
  4. There is no neckline, no volume check, no prior uptrend check, and no break confirmation. A double top is only confirmed when price closes below the low between the two peaks. This script finds two similar highs and stops there, which is roughly where many free pattern scripts stop too.

Paste it into the Pine Editor on a chart you know well and compare its labels to what you would have drawn by hand. If the compiler reports an error after a Pine update, the Pine Script v6 reference manual, linked from the editor, has the current function signatures. Adding a neckline break is a good exercise: track the lowest low between the two peaks and fire a second alert when a bar closes below it. That second alert is the one a double top trader actually acts on, and you will see how much later it comes than the first. Our guide to double top and double bottom patterns covers the manual read of the neckline.

Settings that change what gets flagged

Most community pattern indicators expose the same handful of inputs under different names. Each one trades early flags against false ones.

  • Zigzag length or pivot length. The left-bars and right-bars counts. Small values find small, fast patterns and many false ones; large values find fewer, larger patterns that are confirmed later.
  • Zigzag depth or levels. Some scripts build a second zigzag from the pivots of the first, so a pattern made of larger swings can be found. More levels means more patterns on screen at once.
  • Number of pivots. Trendoscope's script lets you choose five or six. Six pivots demands one more touch, so it flags fewer, cleaner shapes and confirms one swing later.
  • Error threshold. How far a pivot may sit from the trend line and still count as a touch. A loose threshold finds more triangles; many of them would not survive a hand-drawn check.
  • Flat threshold. How close to horizontal a line must be to count as flat, which decides whether a shape is called an ascending triangle or a rising wedge. Change it and the same pivots can get a different name.
  • Avoid overlap and pattern limits. Options that hide a new pattern starting inside an existing one, or cap the number drawn. They tidy the chart without changing what was detected.

Two settings sit outside the script. The first is timeframe. A five-bar pivot on a 1-minute chart is a five-minute swing; on a daily chart it is a week. The same script finds different patterns on different timeframes, and they often disagree. The second is the chart type. TradingView's help page says its tools work on candlestick, line, and other chart types, but a pattern found on Heikin Ashi candles is built on averaged prices that never traded. Run detection on standard candles if you plan to trade the levels.

If a detected trend line is the main thing you care about, our guide on how to draw trend lines covers the anchor choices (wicks or bodies, log or linear scale) that auto trendline tools make silently.

Worked example: reading a flagged ascending triangle

Here is how a flag turns into a decision, with illustrative numbers rather than a real ticker. A stock on a 15-minute chart has tagged $50.00 three times over two sessions. Its swing lows are rising: $47.20, then $48.10, then $48.90. Your pattern indicator uses five right bars, so the $48.90 low is confirmed 75 minutes after it printed. When the "Ascending Triangle" label appears, price is at $49.60.

Illustrative numbers. By the time the triangle is flagged, the cheap entry near the rising line is gone; what is left is the breakout, with a stop under the last low.

Now do the work the indicator did not do.

Is there still an entry near the rising line? Buying at $49.60 with a stop under $48.90 risks $0.70 or more for a first target at $50.00, which is $0.40 away. The reward is smaller than the risk before the breakout has even happened. That entry is gone.

What does the breakout trade look like? A common plan buys a close above the flat top, say $50.10, with a stop just under the last swing low at $48.80, for $1.30 of risk per share. The usual measured-move target adds the pattern's height ($50.00 minus $47.20, so $2.80) to the breakout level, giving roughly $52.90, or $2.80 of reward. The measured move is a convention traders use to size the target, and price often stops short of it.

How big is the position? If you risk 1% of a $20,000 account, that is $200. At $1.30 per share, the position is 153 shares, about $7,665 of stock. Slippage on a breakout fill will push the real risk above $1.30, so round down.

What would cancel it? A close back below $50.00 after the breakout is the first warning. A close below $48.80 ends the pattern. Light volume on the breakout bar, a gap into the level at the open, or a market-wide sell-off can each turn a clean triangle into a failed one.

None of those four answers came from the indicator. It drew two lines and printed a name. Everything that decides whether you lose $200 or make money is the read you do after the flag. Breakout entries and failed-breakout handling are covered in our breakout trading strategy guide.

How to test an auto pattern indicator before trusting it

A pattern indicator's history is the worst place to judge it. Old flags sit on the exact pivots, pattern names were chosen with every bar already known, and failed In Progress patterns have vanished. The test has to happen forward, or in a replay that hides the future.

A trader at a desk with a laptop showing a chart in replay mode and a paper notebook beside it, sketching each flagged pattern into a ruled notebook by hand
A pattern indicator earns trust in a notebook: every flag logged when it appears, at the price you could actually have traded.

A workable process looks like this:

  1. Pick one market and one timeframe. The same script behaves differently on a 5-minute chart and a daily chart, so results from one do not transfer.
  2. Use Bar Replay or live charts only. Start replay a few months back, step forward bar by bar, and log a flag only on the bar it actually appears.
  3. Log the price at the flag, not at the pivot. Record the time, the pattern name, the price when the label appeared, and the level your plan would trade.
  4. Write the trade rule before you look. Entry, stop, and target from the section above, applied the same way to every flag. Then record what happened.
  5. Count everything. Flags that completed, flags that failed, and flags that vanished or changed name. The vanished ones are the ones history hides.
  6. Compare against random entries. The open-source casoon Pine Script collection on GitHub builds every strategy with "a confirmed-bar gate" and "a random-entry baseline for comparison," which is the right standard: if your pattern trades do no better than random entries with the same stop and target, the pattern was not doing the work.
  7. Include costs. The same repo lists Strategy Tester traps that inflate results, among them "costs left out" and "history cut to 500 bars," and warns about "filters tuned and judged on the same data." Its README also says Pine "cannot show that a signal beats chance" on its own.

Thirty to fifty logged flags on one market is a small sample. It will not prove an edge. It will tell you how late the flags arrive, how many disappear, and whether the trade left after the flag is worth taking, which is most of what you need to decide whether the indicator stays on your chart. Our walkthrough of how to backtest a trading strategy covers the bookkeeping in more detail.

Common mistakes

  • Trading the label on sight. The label means "these pivots fit a shape," and that is all. Check the entry, stop, and room to target before acting, as in the worked example.
  • Judging the indicator on history. Flags drawn on the pivot bar and In Progress patterns that later vanished make history look far better than live use. Replay or forward-test instead.
  • Alerts on every tick. An alert that fires inside a forming bar can trigger on a pivot that the bar's close removes. Use once-per-bar-close alerts.
  • Too many patterns at once. Running three zigzag lengths with every pattern type enabled paints the chart with overlapping shapes. Turn off the shapes you never trade.
  • Ignoring the timeframe above. An ascending triangle on a 15-minute chart directly under daily resistance is a weaker setup than the same shape in open space. The detector only sees the chart it runs on.
  • Trusting a closed script's description. If you cannot read the code, you cannot know whether it repaints or how it defines a pattern. Prefer open-source scripts, and forward-test closed ones twice as hard.

FAQ

Is TradingView's Auto Chart Patterns free?

The built-in set moved behind Premium when its open beta ended in March 2023, according to TradingView's announcement. Plans change, so check the current plan page. Many community-built pattern scripts in the public library are free and open source, including Trendoscope's Auto Chart Patterns.

How many bars does TradingView's pattern detection scan?

Its help page says it searches the most recent 600 bars displayed. To find patterns further back, it suggests using Bar Replay to move the chart's end point.

Does an auto chart pattern indicator repaint?

Most do in some way. TradingView's own Pine documentation puts pivot-based scripts in its "potentially misleading" repainting group, because a pivot is only confirmed after the right-side bars close and many scripts then draw it back on the original bar. In Progress patterns can also change or disappear as new bars print. Alerts that fire once per bar close avoid the worst of it.

Why did a pattern disappear from my chart?

Usually it was an unfinished pattern. With In Progress mode on, TradingView shows shapes whose last points are not yet confirmed. If the next bars break the shape, it is removed. Some community scripts also replace a pattern when a better fit appears.

Can Pine Script detect head and shoulders patterns?

Yes. TradingView includes a dedicated Head and Shoulders indicator in its Patterns tab, and several community scripts detect it from pivots. Detection finds the three-peak shape; it does not check the neckline break, the volume pattern, or the prior trend, which decide whether the pattern is tradable. Our guide on how to trade the head and shoulders pattern covers those checks.

What pivot length should I use?

Match it to the swings you trade. Five left and five right bars is what TradingView's built-in set uses, and a reasonable start on intraday charts. Lower values flag sooner with more false patterns; higher values flag later with fewer. Test any change forward, because a setting tuned on history tends to look better than it trades.

Can AI detect chart patterns better than an indicator?

It does a different job. An indicator applies fixed geometry to pivots on the chart it runs on. An AI chart reader works from the image and can describe context the geometry ignores, such as the trend before the pattern or a nearby level. Both can be wrong, and neither replaces a stop. Our guide to detecting chart patterns from a screenshot compares the two approaches.

Where Quant AI fits

A pattern indicator answers one narrow question: do the last few pivots fit a shape? The questions after that (is there still a trade, where does the stop go, is the level strong, what does the higher timeframe say) are the ones that decide the result, and you now know how to work through them by hand. Quant AI reads a chart screenshot and marks the levels, the pattern, and the invalidation point it finds, which helps with that second read. It works from the same chart you do, so it can misread a shape, it cannot see the next bar, and position size and the decision to trade stay with you.