OPEN-SOURCE SCRIPT

Auto Triangle Patterns [HexaTrades]

9 839
Auto Triangle Patterns finds triangle chart patterns for you, draws them on the chart, and marks the candle where price breaks out. It works on any symbol (stocks, crypto, forex, indices) and any timeframe.

What is a triangle pattern?

A triangle forms when price moves in a smaller and smaller range. The highs and the lows squeeze closer together, like a funnel. You can draw one line along the tops and one line along the bottoms. When the two lines get close, price usually breaks out of the triangle with a bigger move.

This indicator finds three types of triangle:

✏️Ascending triangle: flat top line, rising bottom line. Buyers keep pushing the lows higher while sellers hold the same price at the top.

✏️Descending triangle: falling top line, flat bottom line. Sellers keep pushing the highs lower while buyers hold the same price at the bottom.

✏️Symmetrical triangle: falling top line and rising bottom line at similar angles. Neither side is in control yet.


Ascending triangle example

snapshot
The top line stays nearly flat while the bottom line keeps rising, so price gets squeezed into a smaller and smaller range. Then a strong candle closes above the top line, and the indicator prints a small green ▲ under that candle. That is the breakout signal.
In this example the entry is taken only after the breakout candle closes, and the stop-loss sits below the triangle's rising support line. The entry, stop and target boxes are drawn with TradingView's Long Position tool for illustration; the indicator itself only draws the triangle and the ▲ / ▼ marks.


Descending triangle example

snapshot
The top line keeps falling (each bounce makes a lower high) while the bottom line stays close to flat (buyers defend roughly the same support area). The range tightens until a candle closes below the support line, and the indicator prints a small red ▼ above that candle. That is the breakdown signal.

In this example the short entry is taken only after the breakdown candle closes, and the stop-loss sits above the last swing high inside the triangle. The entry, stop and target boxes are drawn with TradingView's Short Position tool for illustration; the indicator itself only draws the triangle and the ▲ / ▼ marks.

Symmetrical triangle example

snapshot
The top line falls (lower highs) and the bottom line rises (higher lows) at a similar angle, so price is squeezed from both sides and neither buyers nor sellers are in control. A symmetrical triangle can break either way, so the indicator waits for a candle to close outside the pattern. Here a candle closed below the rising support line, and a small red ▼ was printed above it. That is the breakdown signal.

In this example the short entry is taken after the breakdown candle closes, and the stop-loss sits above the last swing high (previous resistance) inside the triangle. Notice that price bounced back up close to the stop before the main move down. That's why the stop belongs beyond a real swing point and not right at the line. The entry, stop and target boxes are drawn with TradingView's Short Position tool for illustration; the indicator itself only draws the triangle and the ▲ / ▼ marks.

How to read the chart

- Two coloured lines with a light fill: the triangle. Teal = ascending, red = descending, blue = symmetrical (you can change the colours).
- Label at the start of the pattern: the pattern type, for example "Ascending Triangle".
- Small green ▲ under a candle: breakout. The candle closed above the top line.
- Small red ▼ above a candle: breakdown. The candle closed below the bottom line.
- Dashed lines and "(expired)": price reached the end of the triangle without breaking out, so the pattern failed.
- Dashed lines and "(no breakout)": a newer triangle appeared before this one broke out, so the indicator stopped following the old one.

How it works:

- Step 1: find swing points. A swing high is a candle whose high is higher than the candles around it. A swing low is the opposite.
- Step 2: draw the lines. The top line connects the latest swing highs. The bottom line connects the latest swing lows.
- Step 3: check the shape. The lines must squeeze together, price must stay inside them, and the pattern must not be too short or too long. Shapes that are not real triangles (wedges, rectangles, lopsided shapes) are skipped.
- Step 4: name the triangle. A line counts as "flat" if it moves less than 25% of the triangle's height. This only looks at the shape, so it works the same on every timeframe.
- Step 5: watch for the breakout. When a candle closes outside the triangle, a ▲ or ▼ is printed and an alert can fire.


Settings explained:

- Swing strength (bars before): how many candles before a point it must beat to count as a swing high or low. Bigger number = bigger, fewer patterns.
- Swing confirmation (bars after): how many candles must close after a swing point to confirm it. Bigger number = more reliable but later.
- Touches per side: how many swing points each line must touch. 2 = more patterns, 3 = cleaner textbook patterns.
- Flat line tolerance (% of height): how flat a line must be to count as flat. Lower = stricter ascending and descending triangles.
- Symmetry ratio: how balanced a symmetrical triangle must be. Lower = more even angles.
- Touch / containment tolerance: how far price may poke outside the lines and still count. Measured in ATR (average candle size).
- Min / Max pattern length: shortest and longest triangle, in candles.
- Pattern types: switch each triangle type on or off.
- Style: colours, line width and fill.
- Breakout requires a close beyond the line: on = the candle must close outside (safer). Off = a wick outside is enough (earlier, more false signals).


Alerts
You can get a notification when:
- a new triangle is found ("Triangle detected")
- price breaks out upwards ("Triangle bullish breakout")
- price breaks down ("Triangle bearish breakdown")
- How to set it up: click the Alert (clock) button, choose this indicator under "Condition", then pick the alert you want. Choose "Any alert() function call" to get one alert that also tells you the triangle type and the price.

Tips for beginners
- Start on higher timeframes (4-hour, daily). Patterns there are usually cleaner than on 1-minute charts.
- Too few patterns? Lower "Swing strength" or raise the tolerances.
- Too many weak patterns? Set "Touches per side" to 3 or raise "Min pattern length".
- Wait for the candle to close. A breakout mark only appears on a closed candle.
- Use it together with your own analysis (trend, support and resistance, volume) and your own risk management.

This indicator is for educational and analytical purposes only. It is not financial advice. Trading involves risk. Always use proper risk management and combine this indicator with your own analysis before taking any trade.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.