The Auto Triangles indicator finds triangles on its own: it pairs recent swing highs and swing lows, keeps only the converging pairs that contain every close since the pattern began, names them ascending, descending or symmetrical, and marks the candle that closes outside with its measured target. On one chart that is easy to follow. Across a list of hundreds of stocks, it is not.
This screener runs the same engine over every stock in a list and returns the ones where a triangle has just been broken, as long as the move is still in play: the target has not been reached and the break has not failed.
Break up (+1): a candle closes above the upper line of the active triangle.
Break down (-1): a candle closes below the lower line.
The triangle is the one the indicator draws, built with the same rules:
The target is the measured move: the height of the triangle at its widest point, projected from the broken line. A break fails when price closes beyond the opposite side of the triangle.
Measured on the current S&P 500 members with daily data since January 2019: a triangle break with its target still pending shows up on 1.4% of the bars. With the three-bar window the screener returns a median of 6 stocks a day (1.2% of the list), 13 or fewer on nine days out of ten and up to 36 on the busiest day. The list is empty on about 3% of the days.
Use the same values as on the indicator: if they differ, the screener and the chart describe different triangles.
//---------------------------------------------------------------
// PRC_Auto Triangles Scr
// version = 0
// 01.12.2026
// Iván González @ www.prorealcode.com
// Author: ITA Trading Tools (Auto Triangles indicator)
// Sharing ProRealTime knowledge
//--------------------------------------------------------------------//
// Lists the stocks where a candle has just closed outside a triangle
// detected by the Auto Triangles indicator: above the upper line (break up,
// +1) or below the lower line (break down, -1), while the measured target
// has not been reached and the break has not failed yet.
// Same engine and defaults as the indicator. Every bar of a screener is a
// closed candle, so the engine processes the last bar itself: on a chart
// whose last bar is still forming (or shows the pre-market price) the
// indicator processes the candle before it, which is the same candle.
//--------------------------------------------------------------------//
pivLen = 5 // bars on each side of a swing high or low (2 to 30)
minSpan = 15 // shortest triangle in bars
maxSpan = 150 // longest triangle in bars
flatPct = 20 // a line that moves less than this % of the height is flat
minHgtAtr = 1.5 // smallest height in ATRs
showTypes = 0 // 0 = all, 1 = ascending, 2 = descending, 3 = symmetrical
maxAge = 3 // bars in which a break is still listed (1 = only today)
//--------------------------------------------------------------------//
// Engine state
//--------------------------------------------------------------------//
ONCE nH = 0
ONCE nL = 0
ONCE act = 0
ONCE lastEnd = -1
ONCE hasTgt = 0
ONCE tgtDir = 0
ONCE tgtHit = 0
ONCE tgtFail = 0
ONCE brkBar = -1
ONCE brkKind = 0
atrV = averagetruerange[14](close)
// Closes stored per bar: the containment loop reads them by bar number
$cA[barindex] = close
IF barindex > 2 * pivLen + 1 THEN
bi = barindex
aNow = atrV
cNow = close
hNow = high
lNow = low
// --- pivots (pivot candle = bi - pivLen; strict with the bars after,
// >= with the bars before)
newPivot = 0
IF high[pivLen] > highest[pivLen](high) AND high[pivLen] >= highest[pivLen](high)[pivLen + 1] THEN
$hXa[nH] = bi - pivLen
$hYa[nH] = high[pivLen]
nH = nH + 1
newPivot = 1
ENDIF
IF low[pivLen] < lowest[pivLen](low) AND low[pivLen] <= lowest[pivLen](low)[pivLen + 1] THEN
$lXa[nL] = bi - pivLen
$lYa[nL] = low[pivLen]
nL = nL + 1
newPivot = 1
ENDIF
// --- detection: on every new pivot, every pairing of the last four swing
// highs with the last four swing lows (out of the last six kept). When
// several pairings pass, the longest one wins.
IF newPivot = 1 AND nH >= 2 AND nL >= 2 THEN
nhC = min(nH, 6)
nlC = min(nL, 6)
hBase = nH - nhC
lBase = nL - nlC
hFrom = max(0, nhC - 4)
lFrom = max(0, nlC - 4)
found = 0
FOR iHa = hFrom TO nhC - 2 DO
FOR iHb = iHa + 1 TO nhC - 1 DO
FOR iLc = lFrom TO nlC - 2 DO
FOR iLd = iLc + 1 TO nlC - 1 DO
cux1 = $hXa[hBase + iHa]
cuy1 = $hYa[hBase + iHa]
cux2 = $hXa[hBase + iHb]
cuy2 = $hYa[hBase + iHb]
clx1 = $lXa[lBase + iLc]
cly1 = $lYa[lBase + iLc]
clx2 = $lXa[lBase + iLd]
cly2 = $lYa[lBase + iLd]
cx0 = min(cux1, clx1)
ok = 0
// highs and lows take turns; both lines start at about the same time
IF cux1 < clx2 AND clx1 < cux2 AND cx0 > lastEnd THEN
IF bi - cx0 >= minSpan AND bi - cx0 <= maxSpan THEN
IF found = 0 OR cx0 < bx0 THEN
IF abs(cux1 - clx1) <= 0.3 * (bi - cx0) THEN
ok = 1
ENDIF
ENDIF
ENDIF
ENDIF
IF ok = 1 THEN
xs = max(cux1, clx1)
su = (cuy2 - cuy1) / (cux2 - cux1)
sl = (cly2 - cly1) / (clx2 - clx1)
cH0 = (cuy1 + su * (xs - cux1)) - (cly1 + sl * (xs - clx1))
dw = su - sl
ok = 0
IF cH0 >= minHgtAtr * aNow AND dw < 0 THEN
cApex = xs + floor(cH0 / (0 - dw))
wNow = (cuy1 + su * (bi - cux1)) - (cly1 + sl * (bi - clx1))
// apex still ahead, and not so far that the lines are nearly parallel
IF cApex > bi + 1 AND cApex - bi <= (bi - cx0) * 1.5 AND cApex - bi <= 450 AND wNow <= cH0 * 0.85 THEN
ok = 1
ENDIF
ENDIF
ENDIF
IF ok = 1 THEN
// the type, from how far each line moves over the life of the pattern
life = cApex - xs
dU = su * life
dL = sl * life
tol = cH0 * flatPct / 100
cKind = 0
IF abs(dU) <= tol AND dL > tol THEN
cKind = 1
ELSIF abs(dL) <= tol AND dU < 0 - tol THEN
cKind = 2
ELSIF dU < 0 - tol AND dL > tol THEN
cKind = 3
ENDIF
ok = 0
IF cKind > 0 AND (showTypes = 0 OR showTypes = cKind) THEN
ok = 1
ENDIF
ENDIF
IF ok = 1 THEN
// containment: every close since the first pivot sits between the lines
FOR k = 0 TO bi - cx0 DO
xk = bi - k
cK = $cA[xk]
IF cK > cuy1 + su * (xk - cux1) OR cK < cly1 + sl * (xk - clx1) THEN
ok = 0
BREAK
ENDIF
NEXT
ENDIF
IF ok = 1 THEN
found = 1
bux1 = cux1
buy1 = cuy1
bux2 = cux2
buy2 = cuy2
blx1 = clx1
bly1 = cly1
blx2 = clx2
bly2 = cly2
bx0 = cx0
bApex = cApex
bH0 = cH0
bKind = cKind
ENDIF
NEXT
NEXT
NEXT
NEXT
// a refinement of the active triangle replaces it; a shorter one inside it does not
IF found = 1 AND (act = 0 OR bx0 >= x0) THEN
act = 1
ux1 = bux1
uy1 = buy1
ux2 = bux2
uy2 = buy2
lx1 = blx1
ly1 = bly1
lx2 = blx2
ly2 = bly2
x0 = bx0
apexX = bApex
hgt0 = bH0
triKind = bKind
ENDIF
ENDIF
// --- following the active triangle
IF act = 1 THEN
su = (uy2 - uy1) / (ux2 - ux1)
sl = (ly2 - ly1) / (lx2 - lx1)
uNow = uy1 + su * (bi - ux1)
lwNow = ly1 + sl * (bi - lx1)
ended = 0
IF cNow > uNow OR cNow < lwNow THEN
// the measured move: the height at the widest point, from the broken line
IF cNow > uNow THEN
tgtDir = 1
tgt = uNow + hgt0
failLvl = lwNow
ELSE
tgtDir = -1
tgt = lwNow - hgt0
failLvl = uNow
ENDIF
hasTgt = 1
tgtHit = 0
tgtFail = 0
brkBar = bi
brkKind = triKind
ended = 1
ELSIF bi >= apexX - 1 THEN
// ran into its own apex without a close outside
ended = 1
ENDIF
IF ended = 1 THEN
act = 0
lastEnd = bi
ENDIF
ENDIF
// --- the target of the most recent break
IF hasTgt = 1 AND tgtHit = 0 AND tgtFail = 0 THEN
IF (tgtDir = 1 AND cNow < failLvl) OR (tgtDir = -1 AND cNow > failLvl) THEN
// failed once price closes beyond the far side of the triangle
tgtFail = 1
ELSIF (tgtDir = 1 AND hNow >= tgt) OR (tgtDir = -1 AND lNow <= tgt) THEN
tgtHit = 1
ENDIF
ENDIF
ENDIF
//--------------------------------------------------------------------//
// Capture window: a break up to maxAge - 1 bars ago is still listed while
// its target is pending (not reached, break not failed).
//--------------------------------------------------------------------//
sig = 0
colDir = 0
colKind = 0
colTgt = 0
barsAgo = 0
IF hasTgt = 1 AND tgtHit = 0 AND tgtFail = 0 AND brkBar >= 0 THEN
IF barindex - brkBar < maxAge THEN
sig = 1
colDir = tgtDir
colKind = brkKind
colTgt = round((tgt - close) / close * 1000) / 10
barsAgo = barindex - brkBar
ENDIF
ENDIF
SCREENER[sig = 1](colDir AS "1 up -1 down", colKind AS "1 asc 2 desc 3 sym", colTgt AS "To target %", barsAgo AS "Bars ago")
Based on the Auto Triangles indicator by ITA Trading Tools (itamardrori_), published open source; this screener is shared on the same terms.