Chart Pattern Triangle

A triangle is an indefinite pattern that can mean both a continuation and a reversal of the trend after a consolidation area.


The indicator analyzes the last 600 bars in search of patterns. The DTW (Dynamic Time Warping) algorithm is used for the primary recognition. This algorithm allows you to find compressed and time-stretched sequences of values of the specified source that match a given template of 5 points. The points in the patterns found using DTW are tied to pivots. Once the points are found, the indicator checks the pattern rules and the specified maximum permissible deviation.


In the interval between points 1 and 5 from the bottom and points 2 and 5 from the top, the price is allowed to cross the triangle lines with ‘high’ and ‘low’, but not with ‘close’ or ‘open’. Of all the found patterns that fit the conditions, the largest non-overlapping triangles are drawn on the chart.


Inputs:


Invert Pattern - Changes the sequence of high and low pivots in the triangle.


Source - Source for the primary search. The indicator searches for the pattern in the source data using the DTW algorithm.


Permissible Deviation - The maximum allowable deviation of the midpoint from the triangle line. The deviation is determined by the formula:

Deviation = ((x - x2) * 100) / (x1 - x2), where: