Before buying a stock for a swing trade, an experienced trader checks the same handful of things: is the trend healthy, is the stock building a tight base near its highs, has volatility dried up, is volume showing accumulation, is it close to breaking out. The Institutional Swing Setup Score turns that checklist into one number from 0 to 100, plotted in its own panel, with the detail of every part in a small dashboard.
It is a reading of the chart, not a trading system: it does not give entries, stops or targets. It tells you which charts deserve a closer look and when a setup is improving or falling apart.
The score is a weighted average of five engines, each scored from 0 to 100.
Trend (weight 15). The trend-template check: close above the 50, 150 and 200 moving averages in that order (30 points), the 200 rising over the last 20 bars (25), close above the 200 (15), close at least 30% above the 52-week low (15) and within 25% of the 52-week high (15).
Price structure (weight 10). How tight the base of the last 50 bars is (range as a percentage of its high), how close the close is to the top of the base, and how many higher swing lows in a row the stock has made (counted up to 3).
Volatility contraction (weight 10). ATR as a percentage of price below its own average, Bollinger Band width below its average, and the percent rank of ATR% over the last 126 bars: the lower the rank, the more contracted volatility is compared with its own history.
Volume and accumulation (weight 30, the highest by design). Five checks worth 20 points each: volume drying up (short volume average below 75% of the long one), more volume on up days than on down days over 20 bars (ratio above 1.3), the accumulation/distribution line above its 21-bar average, light volume on down days, and a recent up day with at least 1.5 times the average volume.
Breakout readiness (weight 20). A blend of the other engines, plus points for being near the top of the base and for a tight base whose resistance has been tested at least twice. A confirmed breakout adds a 20-point bonus: a new high of the base made with volume participation and the moving averages aligned. Without that bonus, the volatility and range expansion that comes with every breakout would pull the score down exactly when the setup triggers.
//---------------------------------------------------------------
// PRC_Swing Setup Score
// version = 0
// 30.11.2026
// Iván González @ www.prorealcode.com
// Author: AzeezF
// Sharing ProRealTime knowledge
//--------------------------------------------------------------------//
defparam drawonlastbaronly = true
//--------------------------------------------------------------------//
// Inputs
//--------------------------------------------------------------------//
tightnessRef = 1.0 // global tightness sensitivity (higher = stricter)
// Trend engine
smaFastLen = 50
smaMidLen = 150
smaSlowLen = 200
slopeLookback = 20 // long-term MA slope lookback (bars)
yearLookback = 252 // 52-week lookback (bars)
// Price structure engine
structLookback = 50 // base / consolidation lookback (bars)
structPivotBars = 5 // pivot low left/right bars (higher-low detection)
tightRangeRefPct = 25.0 // reference base width in % (at or below = tight)
// Volatility contraction engine
atrLen = 14
volContractLookback = 20
volPercentileLookback = 126
bbLen = 20
bbMult = 2.0
// Volume / accumulation engine
volShortLen = 10
volLongLen = 50
volDryUpFactor = 0.75 // dry-up: short volume MA below this x long volume MA
volRatioLookback = 20 // up/down volume ratio lookback (bars)
volUDThreshold = 1.3 // strong demand up/down volume ratio
adlSmoothLen = 21 // accumulation/distribution line smoothing
volExpansionMult = 1.5 // breakout participation: volume >= this x long average
participationLookback = 5 // bars a volume-thrust day stays active
// Breakout readiness engine
breakoutLookback = 50
breakoutProximityPct = 8.0
breakoutMinTests = 2
breakoutConfirmBonus = 20
// Composite weights
wTrend = 15
wStruct = 10
wVolat = 10
wVolume = 30
wBreakout = 20
// Dashboard, background and markers
showDashboard = 1
alertScoreThreshold = 80 // background highlight from this score
alertImprovementPts = 15 // "significant improvement" over 5 bars
testMarkersOn = 1 // calibration markers (not trade signals)
testEntryScore = 60
testExitScore = 40
dashX = 0 - 250 // dashboard: pixels from the right edge of the panel
dashY = 0 - 16 // dashboard: pixels from the top edge of the panel
dashCol = 120 // dashboard: distance between label and value columns
//--------------------------------------------------------------------//
// Engine 1: trend (MA alignment, long MA slope, 52-week range)
//--------------------------------------------------------------------//
smaFast = average[smaFastLen](close)
smaMid = average[smaMidLen](close)
smaSlow = average[smaSlowLen](close)
aligned = close > smaFast AND smaFast > smaMid AND smaMid > smaSlow
slowRising = smaSlow > smaSlow[slopeLookback]
hi52 = highest[yearLookback](high)
lo52 = lowest[yearLookback](low)
trendScore = 30 * aligned + 25 * slowRising + 15 * (close > smaSlow) + 15 * (close > lo52 * 1.30) + 15 * (close > hi52 * 0.75)
trendScore = max(0, min(100, trendScore))
//--------------------------------------------------------------------//
// Engine 3: price structure (base tightness, distance to the base high,
// consecutive higher pivot lows)
//--------------------------------------------------------------------//
ONCE higherLowCount = 0
ONCE nPivL = 0
llP = lowest[structPivotBars](low)
IF barindex >= 2 * structPivotBars THEN
IF low[structPivotBars] < llP AND low[structPivotBars] <= llP[structPivotBars + 1] THEN
prevPivotLow = lastPivotLow
lastPivotLow = low[structPivotBars]
nPivL = nPivL + 1
IF nPivL > 1 THEN
IF lastPivotLow > prevPivotLow THEN
higherLowCount = higherLowCount + 1
ELSE
higherLowCount = 0
ENDIF
ENDIF
ENDIF
ENDIF
baseHigh = highest[structLookback](high)
baseLow = lowest[structLookback](low)
rangePct = 0
distFromHighPct = 0
IF baseHigh <> 0 THEN
rangePct = (baseHigh - baseLow) / baseHigh * 100
distFromHighPct = (baseHigh - close) / baseHigh * 100
ENDIF
effTightRef = tightRangeRefPct / tightnessRef
tightnessScore = max(0, min(100, 100 - (rangePct / effTightRef) * 100))
compressionScore = max(0, min(100, 100 - (distFromHighPct / (effTightRef * 0.6)) * 100))
higherLowScore = min(higherLowCount, 3) / 3 * 100
structScore = max(0, min(100, tightnessScore * 0.40 + compressionScore * 0.30 + higherLowScore * 0.30))
//--------------------------------------------------------------------//
// Engine 4: volatility contraction (ATR% vs its average and its percent
// rank, Bollinger width vs its average)
//--------------------------------------------------------------------//
atrVal = averagetruerange[atrLen](close)
atrPct = 0
IF close <> 0 THEN
atrPct = atrVal / close * 100
ENDIF
$atrP[barindex] = atrPct
atrContracting = atrPct < average[volContractLookback](atrPct)
// percent rank: share of the previous N values that are <= the current one
rankCnt = 0
IF barindex >= volPercentileLookback THEN
FOR k = 1 TO volPercentileLookback DO
IF $atrP[barindex - k] <= atrPct THEN
rankCnt = rankCnt + 1
ENDIF
NEXT
ENDIF
atrPercentRank = rankCnt * 100 / volPercentileLookback
bbBasis = average[bbLen](close)
bbDev = std[bbLen](close) * bbMult
bbWidthPct = 0
IF bbBasis <> 0 THEN
bbWidthPct = (2 * bbDev) / bbBasis * 100
ENDIF
bbContracting = bbWidthPct < average[volContractLookback](bbWidthPct)
volatScore = max(0, min(100, 30 * atrContracting + 30 * bbContracting + (100 - atrPercentRank) * 0.40))
//--------------------------------------------------------------------//
// Engine 5: volume / accumulation (dry-up, up/down volume, A/D line,
// light pullbacks, breakout participation)
//--------------------------------------------------------------------//
volSmaShort = average[volShortLen](volume)
volSmaLong = average[volLongLen](volume)
dryUp = volSmaShort < volSmaLong * volDryUpFactor
upVolSum = summation[volRatioLookback]((close > close[1]) * volume)
downVolSum = summation[volRatioLookback]((close < close[1]) * volume)
IF downVolSum > 0 THEN
udRatio = upVolSum / downVolSum
ELSIF upVolSum > 0 THEN
udRatio = volUDThreshold * 2
ELSE
udRatio = 1
ENDIF
strongDemand = udRatio > volUDThreshold
hlRange = high - low
mfm = 0
IF hlRange <> 0 THEN
mfm = ((close - low) - (high - close)) / hlRange
ENDIF
ONCE adl = 0
adl = adl + mfm * volume
adlRising = adl > average[adlSmoothLen](adl)
pullbackLight = close < close[1] AND volume < volSmaLong
relVol = 1
IF volSmaLong > 0 THEN
relVol = volume / volSmaLong
ENDIF
bpToday = close > close[1] AND relVol >= volExpansionMult
breakoutParticipation = highest[participationLookback](bpToday) >= 1
volumeScore = 20 * dryUp + 20 * strongDemand + 20 * adlRising + 20 * pullbackLight + 20 * breakoutParticipation
//--------------------------------------------------------------------//
// Engine 6: breakout readiness (blend of the other engines, proximity to
// the base high, tests of resistance, confirmed breakout bonus)
//--------------------------------------------------------------------//
$hA[barindex] = high
nearHigh = distFromHighPct < breakoutProximityPct
tight = rangePct < tightRangeRefPct
newBaseHigh = high >= baseHigh * 0.999
testCount = 0
testFloor = baseHigh * (1 - breakoutProximityPct / 100)
FOR i = 0 TO min(breakoutLookback - 1, barindex) DO
hi = $hA[barindex - i]
IF hi >= testFloor AND hi < baseHigh THEN
testCount = testCount + 1
ENDIF
NEXT
testedResistance = testCount >= breakoutMinTests
// the four engine weights (0.20 / 0.25 / 0.15 / 0.10) are rescaled to add up to 0.90
brkScore = (trendScore * 0.20 + volumeScore * 0.25 + structScore * 0.15 + volatScore * 0.10) * 0.90 / 0.70
brkScore = brkScore + 5 * nearHigh + 5 * (tight AND testedResistance)
brkConfirmed = newBaseHigh AND breakoutParticipation AND aligned
brkScore = brkScore + breakoutConfirmBonus * brkConfirmed
breakoutScore = max(0, min(100, brkScore))
//--------------------------------------------------------------------//
// Composite setup score
//--------------------------------------------------------------------//
weightSum = wTrend + wStruct + wVolat + wVolume + wBreakout
IF weightSum = 0 THEN
weightSum = 1
ENDIF
composite = (trendScore * wTrend + structScore * wStruct + volatScore * wVolat + volumeScore * wVolume + breakoutScore * wBreakout) / weightSum
composite = max(0, min(100, composite))
//--------------------------------------------------------------------//
// Colours by quality band
//--------------------------------------------------------------------//
ONCE warm = max(max(smaSlowLen + slopeLookback, yearLookback), max(volPercentileLookback + atrLen, max(structLookback, breakoutLookback)))
IF composite >= 80 THEN
cR = 76
cG = 175
cB = 80
ELSIF composite >= 60 THEN
cR = 0
cG = 230
cB = 118
ELSIF composite >= 40 THEN
cR = 253
cG = 216
cB = 53
ELSIF composite >= 20 THEN
cR = 255
cG = 152
cB = 0
ELSE
cR = 242
cG = 54
cB = 69
ENDIF
IF barindex >= warm THEN
lineA = 255
IF composite >= alertScoreThreshold THEN
BACKGROUNDCOLOR(76, 175, 80, 25)
ENDIF
ELSE
lineA = 0
ENDIF
//--------------------------------------------------------------------//
// Calibration markers (score crossings and confirmed breakouts), kept
// in a list and redrawn on the last bar
//--------------------------------------------------------------------//
ONCE nMk = 0
IF barindex > warm AND testMarkersOn THEN
IF composite crosses over testEntryScore THEN
$mkB[nMk] = barindex
$mkT[nMk] = 1
$mkY[nMk] = composite - 6
nMk = nMk + 1
ENDIF
IF composite crosses under testExitScore THEN
$mkB[nMk] = barindex
$mkT[nMk] = 2
$mkY[nMk] = composite + 6
nMk = nMk + 1
ENDIF
IF brkConfirmed AND NOT brkConfirmed[1] THEN
$mkB[nMk] = barindex
$mkT[nMk] = 3
$mkY[nMk] = composite - 12
nMk = nMk + 1
ENDIF
ENDIF
//--------------------------------------------------------------------//
// Alert series (invisible): set alerts on them in the indicator window
//--------------------------------------------------------------------//
improvement = composite - composite[5] > alertImprovementPts
accumulation = adlRising AND NOT adlRising[1]
newConfirmed = brkConfirmed AND NOT brkConfirmed[1]
//--------------------------------------------------------------------//
// Drawing on the last bar: markers and dashboard
//--------------------------------------------------------------------//
IF islastbarupdate THEN
IF nMk > 0 THEN
FOR m = 0 TO nMk - 1 DO
mx = $mkB[m]
my = $mkY[m]
IF $mkT[m] = 1 THEN
DRAWTEXT("▲", mx, my) COLOURED(0, 230, 118)
ELSIF $mkT[m] = 2 THEN
DRAWTEXT("▼", mx, my) COLOURED(242, 54, 69)
ELSE
DRAWTEXT("B", mx, my, sansserif, bold, 11) COLOURED(255, 152, 0)
ENDIF
NEXT
ENDIF
IF showDashboard THEN
vComp = round(composite)
vTrend = round(trendScore)
vStruct = round(structScore)
vVolat = round(volatScore)
vVol = round(volumeScore)
vBrk = round(breakoutScore)
DRAWTEXT("Institutional Setup Score", dashX, dashY, sansserif, bold, 11) COLOURED(40, 40, 40) ANCHOR(topright, xshift, yshift)
DRAWTEXT("#vComp#", dashX + dashCol, dashY, sansserif, bold, 11) COLOURED(cR, cG, cB) ANCHOR(topright, xshift, yshift)
DRAWTEXT("Trend Quality", dashX, dashY - 18, sansserif, standard, 10) COLOURED(90, 90, 90) ANCHOR(topright, xshift, yshift)
DRAWTEXT("#vTrend#", dashX + dashCol, dashY - 18, sansserif, bold, 10) COLOURED(60, 60, 60) ANCHOR(topright, xshift, yshift)
DRAWTEXT("Price Structure", dashX, dashY - 36, sansserif, standard, 10) COLOURED(90, 90, 90) ANCHOR(topright, xshift, yshift)
DRAWTEXT("#vStruct#", dashX + dashCol, dashY - 36, sansserif, bold, 10) COLOURED(60, 60, 60) ANCHOR(topright, xshift, yshift)
DRAWTEXT("Volatility Contraction", dashX, dashY - 54, sansserif, standard, 10) COLOURED(90, 90, 90) ANCHOR(topright, xshift, yshift)
DRAWTEXT("#vVolat#", dashX + dashCol, dashY - 54, sansserif, bold, 10) COLOURED(60, 60, 60) ANCHOR(topright, xshift, yshift)
DRAWTEXT("Volume Quality", dashX, dashY - 72, sansserif, standard, 10) COLOURED(90, 90, 90) ANCHOR(topright, xshift, yshift)
DRAWTEXT("#vVol#", dashX + dashCol, dashY - 72, sansserif, bold, 10) COLOURED(60, 60, 60) ANCHOR(topright, xshift, yshift)
DRAWTEXT("Institutional Accumulation", dashX, dashY - 90, sansserif, standard, 10) COLOURED(90, 90, 90) ANCHOR(topright, xshift, yshift)
IF adlRising THEN
DRAWTEXT("Yes", dashX + dashCol, dashY - 90, sansserif, bold, 10) COLOURED(76, 175, 80) ANCHOR(topright, xshift, yshift)
ELSE
DRAWTEXT("No", dashX + dashCol, dashY - 90, sansserif, bold, 10) COLOURED(242, 54, 69) ANCHOR(topright, xshift, yshift)
ENDIF
DRAWTEXT("Breakout Readiness", dashX, dashY - 108, sansserif, standard, 10) COLOURED(90, 90, 90) ANCHOR(topright, xshift, yshift)
DRAWTEXT("#vBrk#", dashX + dashCol, dashY - 108, sansserif, bold, 10) COLOURED(60, 60, 60) ANCHOR(topright, xshift, yshift)
DRAWTEXT("Higher-Low Count", dashX, dashY - 126, sansserif, standard, 10) COLOURED(90, 90, 90) ANCHOR(topright, xshift, yshift)
DRAWTEXT("#higherLowCount#", dashX + dashCol, dashY - 126, sansserif, bold, 10) COLOURED(60, 60, 60) ANCHOR(topright, xshift, yshift)
DRAWTEXT("Breakout Confirmed", dashX, dashY - 144, sansserif, standard, 10) COLOURED(90, 90, 90) ANCHOR(topright, xshift, yshift)
IF brkConfirmed THEN
DRAWTEXT("Yes", dashX + dashCol, dashY - 144, sansserif, bold, 10) COLOURED(76, 175, 80) ANCHOR(topright, xshift, yshift)
ELSE
DRAWTEXT("No", dashX + dashCol, dashY - 144, sansserif, bold, 10) COLOURED(242, 54, 69) ANCHOR(topright, xshift, yshift)
ENDIF
ENDIF
ENDIF
RETURN composite COLOURED(cR, cG, cB, lineA) STYLE(line, 2) AS "Composite Setup Score", 80 COLOURED(76, 175, 80, 100) STYLE(dottedline, 1) AS "Exceptional (80)", 60 COLOURED(0, 230, 118, 100) STYLE(dottedline, 1) AS "Good (60)", 40 COLOURED(253, 216, 53, 100) STYLE(dottedline, 1) AS "Average (40)", 20 COLOURED(242, 54, 69, 100) STYLE(dottedline, 1) AS "Weak (20)", volumeScore COLOURED(0, 0, 0, 0) AS "Volume Score", breakoutScore COLOURED(0, 0, 0, 0) AS "Breakout Readiness", improvement COLOURED(0, 0, 0, 0) AS "Significant Improvement", accumulation COLOURED(0, 0, 0, 0) AS "New Accumulation Phase", newConfirmed COLOURED(0, 0, 0, 0) AS "Breakout Confirmed"
Original author: AzeezF, published open source.