Skip to Main Content

Detect Symmetrical Triangles on Charts Automatically

This demonstrates how to identify chart patterns consisting of two lines in relation to one another. Here we detect symmetrical triangles. Other examples for other types of triangles are in the system for you to explore.

Detect Symmetrical Triangles on Charts Automatically
describe_indicator('Triangle, Symmetrical', 'price', { decimals: 'by_symbol_+1', shortName: 'Triangle.Sym' });
 
const timeSpan = input('Time span', 'Short term', ['Short term', 'Long term']);
const showBands = input('Bands', 'No', ['No', 'Yes']);
const bandType = input('Band type', 'ATR', constants.band_types);
const bandLength = input('Band length', 10, { min: 2, max: 50 });
 
const multiplier = input('Band value', 0.33, { min: 0.01, max: 10 });
 
const timeSpanParameter = timeSpan == 'Short term' ? 'short' : 'long';
 
const { top, bottom } = find_triangle(timeSpanParameter, 'symmetrical');
 
paint(top, { name: 'Top', color: '#1e5879', thickness: 3 });
paint(bottom, { name: 'Bottom', color: '#1e5879', thickness: 3 });
 
const { upper: topUpper, lower: topLower } = showBands == 'Yes'
	? compute_band(top, bandType, multiplier, bandLength)
	: { upper: [], lower: [] };
 
fill(
	paint(topUpper, { name: 'Top/U', color: '#4289b3' }),
	paint(topLower, { name: 'Top/L', color: '#4289b3' }),
	'#1e5879'
);
 
const { upper: bottomUpper, lower: bottomLower } = showBands == 'Yes'
	? compute_band(bottom, bandType, multiplier, bandLength)
	: { upper: [], lower: [] };
 
fill(
	paint(bottomUpper, { name: 'Bot/U', color: '#4289b3' }),
	paint(bottomLower, { name: 'Bot/L', color: '#4289b3' }),
	'#1e5879'
);
Complexity rating: 4 out of 5