AutoTrianglePatterns
- Indicatori
-
Shi Yuan Wang
Sviluppo indicatori personalizzati, Expert Advisor (EA), script e strumenti di trading per MetaTrader 4 e MetaTrader 5, nonché indicatori per TradingView (Pine Script).
Cosa posso fare per te: - Versione: 1.10
Auto Triangle Patterns
Overview
Auto Triangle Patterns is a chart indicator for MetaTrader 5. It scans the price history of the current chart and looks for three classical triangle formations: ascending, descending and symmetrical. When a formation is found, the indicator draws its two boundary lines, fills the area between them and adds a text label with the name of the formation. The pattern stays on the chart and is extended to the right with every new bar.
When price leaves the formation in either direction, or when the formation reaches its apex without a breakout, the indicator marks the result and stops updating that pattern. Resolved patterns remain on the chart so that past formations can be reviewed.
The indicator does not open or manage positions, does not place orders and does not generate trading signals. It is a technical analysis and chart visualization tool. All markings are interpretations of past price data.
How it works
The search is performed in several steps.
Swing points. The indicator finds swing highs and swing lows. A swing high is a bar whose high is not exceeded by the highs of the bars to its left and to its right; a swing low is found in the same way. The number of bars checked on each side is set by InpPivotLeft and InpPivotRight. Because the bars on the right side have to close first, a swing point is confirmed only after InpPivotRight bars have appeared after it.
Boundary lines. The upper line is drawn through the most recent InpTouches swing highs, and the lower line through the most recent InpTouches swing lows. Every swing point used for a line has to stay within a distance of InpFitTol multiplied by the Average True Range of the chart, where the ATR period is set by InpAtrLen. This tolerance is what makes the lines follow real price touches instead of an exact mathematical fit.
Classification. The two slopes decide the name of the formation. A line is treated as horizontal when the total change of its value over the length of the pattern is not more than InpFlatPct percent of the height of the pattern. An upper horizontal line with a rising lower line is an ascending triangle. A falling upper line with a horizontal lower line is a descending triangle. When both lines converge and the ratio between the faster and the slower slope is not more than InpSymRatio, the formation is symmetrical.
Validation. A candidate is accepted only when several conditions are met at the same time. The swing points of the two lines have to overlap in time. The length of the pattern has to be between InpMinBars and InpMaxBars. The point where the two lines meet has to be located to the right of the current bar. The upper line has to stay above the lower line. Finally, every bar between the start of the pattern and the current bar has to stay inside the channel, with the same ATR based tolerance that is used for the lines.
Drawing and updating. An accepted formation is drawn from its starting bar to the current bar. The lines of the active formation are extended to the right with every new bar, so the formation always reflects the latest price.
Result of a pattern. There are three possible outcomes. A breakout above the upper line marks a bullish breakout; a break below the lower line marks a bearish breakdown. In both cases an arrow is placed on the bar and the lines keep their solid style. If the price reaches the apex of the formation, or if the formation becomes longer than InpMaxBars, the pattern is closed without a breakout and is drawn with dashed lines and the note "expired". If a new formation starts while the previous one is still active, the previous one is closed in the same dashed style with the note "no breakout".
Only one formation is kept active at a time. Formations that are already resolved remain on the chart as static objects and are no longer changed.
How to use
Attach the indicator to any chart. It works on any symbol and any timeframe, and the default settings are a reasonable starting point for most charts.
Adjust the swing strength first. The pair InpPivotLeft and InpPivotRight defines how large a swing has to be before it is counted. Smaller values produce more swing points and more patterns; larger values produce fewer, larger patterns. Suitable values depend on the symbol and on personal chart reading habits.
Recommended starting values for the swing strength:
M5 to M15: InpPivotLeft 3, InpPivotRight 3
M30 to H1: InpPivotLeft 5, InpPivotRight 5
H4 to D1: InpPivotLeft 7, InpPivotRight 7
The number of touches per side is the second main control. InpTouches set to 2 finds patterns earlier and more often. Values of 3 or 4 require more confirmed touches on each line, so fewer patterns are found, and those that are found are based on more price evidence.
The tolerance InpFitTol is measured in ATR units and defines how strictly the swing points and the price inside the pattern have to follow the two lines. A value between 0.3 and 0.8 suits most charts. Lower values give tighter, more selective patterns; higher values accept looser ones.
The breakout mode is controlled by InpUseClose. With the default value of true, a breakout is counted only when a bar closes beyond a boundary line, so a wick that pierces a line without closing beyond it is not marked. With the value of false, the high and the low of the bar are used instead.
Alerts are shown by the terminal when a new formation is detected and when a breakout or a breakdown occurs. Alerts are produced on closed bars only. No alert is produced while the indicator scans past history during its first calculation.
Load enough chart history before drawing conclusions. The indicator scans up to InpHistoryBars bars of history on load; a chart with more bars loaded gives a more complete picture.
Input parameters
Pattern detection
InpPivotLeft. Number of bars to the left of a swing point that must not exceed it. Default 5.
InpPivotRight. Number of bars to the right of a swing point that must not exceed it. Default 5.
InpTouches. Number of swing points required on each boundary line. Values from 2 to 4. Default 2.
InpFlatPct. Maximum change of a boundary line over the length of the pattern, expressed as a percentage of the pattern height, for the line to be treated as horizontal. Default 25.0.
InpSymRatio. Maximum ratio between the two slopes for a symmetrical triangle. Default 3.0.
InpFitTol. Tolerance for the swing points and for the price inside the pattern, in ATR units. Default 0.5.
InpAtrLen. Period of the Average True Range used to convert the tolerance into price units. Default 14.
Pattern size and history
InpMinBars. Minimum length of a pattern in bars. Default 15.
InpMaxBars. Maximum length of a pattern in bars, counted from the start of the pattern to its apex. Default 200.
InpHistoryBars. Number of historical bars scanned when the indicator is loaded. The value 0 scans all available history. Default 3000.
Pattern types
InpShowAsc. Enable the search for ascending triangles. Default true.
InpShowDesc. Enable the search for descending triangles. Default true.
InpShowSym. Enable the search for symmetrical triangles. Default true.
Appearance
InpColAsc. Line color for ascending triangles. Default clrTeal.
InpColDesc. Line color for descending triangles. Default clrRed.
InpColSym. Line color for symmetrical triangles. Default clrBlue.
InpLineWidth. Width of the boundary lines. Default 2.
InpShowFill. Fill the area between the two boundary lines. Default true.
Breakout and alerts
InpUseClose. Require a bar to close beyond a boundary line before a breakout is counted. With the value false, the high and the low of the bar are used. Default true.
InpShowBreakout. Draw an arrow on the bar of a breakout or a breakdown. Default true.
InpColBull. Color of the arrow for a breakout above the upper line. Default clrGreen.
InpColBear. Color of the arrow for a break below the lower line. Default clrRed.
Notes and limitations
Swing points are confirmed only after InpPivotRight bars have closed on the right side of a swing. This delay is part of swing detection and is not a defect. Confirmed swing points do not move or disappear afterwards.
The active formation is refitted while new swing points appear, so its lines, its length and its label can change until the formation is resolved. Resolved formations are not changed afterwards.
Breakouts are evaluated on closed bars. With InpUseClose enabled, a wick that pierces a boundary line without closing beyond it is not marked as a breakout.
The lines of the active formation are drawn up to the current bar, including the bar that is still forming. The breakout evaluation itself uses closed bars only.
Only one formation is active at a time. Earlier formations stay on the chart as static objects.
All markings are chart objects. They belong to the chart window and are removed together with the indicator.
The indicator does not use indicator buffers. It displays nothing in the Data Window, and its values cannot be read by other programs.
The indicator needs a sufficient amount of history on the chart and a filled ATR buffer before it starts drawing.
Availability
The indicator is currently distributed free of charge through the MQL5 Market. After the number of downloads exceeds 100, it will be converted to a paid subscription product. Users who obtained the free version before the conversion can continue to use the copy they received, in accordance with the MQL5 Market rules.
Demo version
In accordance with the MQL5 Market rules, the demo version of an indicator cannot be run on a live chart. Its behaviour can be observed in the visual testing mode of the Strategy Tester built into the client terminal.
Risk disclaimer
This indicator is a technical analysis and chart visualization tool. It does not provide trading signals, does not open or manage positions, and does not guarantee or promise any profit. Triangle formations and breakout markings are interpretations of past price data only. Trading in financial markets involves substantial risk. Any use of this indicator, and any trading decision taken with or without it, remains the sole responsibility of the user.
Support
Support is provided through the comments section of the product page and through the MQL5.com messaging system.
