Band-Channel Trends - Ms Brown folder
Band-Channel Trends - Ms Brown folder is an adaptive trend-following indicator that combines smoothed price analysis, volatility bands, historical channels, and directional persistence. It is designed to track established trends through ordinary pullbacks and identify changes when price meets defined reversal conditions.
Screenshot 1 of 1 · Open image to view full size
About this script
Band-Channel Trends - Ms Brown folder is an adaptive trend-following indicator that combines smoothed price analysis, volatility bands, historical channels, and directional persistence. It is designed to track established trends through ordinary pullbacks and identify changes when price meets defined reversal conditions. The indicator maintains a bullish or bearish state, supported by a trailing boundary that acts as the active trend defense. This provides a consistent reference for monitoring the current direction and assessing when that direction may be losing support. Smoothed Trend Foundation A two-pole Ehlers SuperSmoother establishes the central reference used throughout the indicator. Its filtering reduces short-term price noise while retaining responsiveness to developing movement. This center supports both the volatility calculations and the assessment of how consistently price holds on one side of the trend. Volatility-Adaptive Bands Upper and lower bands are calculated from the root mean square deviation of the selected price source from the smoothed center. Their distance adjusts as price dispersion changes. An ATR-based minimum width prevents the envelope from becoming excessively narrow during quiet periods. Together, these calculations create a reference that adapts to market conditions without requiring a fixed price distance or percentage. Historical Channel Integration Historical channel highs and lows add structural context to the volatility envelope. The lower channel boundary contributes to the bullish defense, while the upper channel boundary contributes to the bearish defense. Blending these references allows the indicator to account for both recent price variability and the surrounding trading range. Directional Persistence Measurement Directional residence measures the proportion of recent closes above the smoothed center, with a complementary reading used for bearish residence. As bullish residence increases, the historical lower channel receives greater weight in the bullish boundary. Increasing bearish residence raises the influence of the upper channel on the bearish boundary. This creates a changing balance between volatility-based and channel-based references as directional behavior becomes more or less established. Persistent Trailing Defense Within an active bullish regime, the defense can advance upward without moving lower to accommodate a pullback. Within a bearish regime, it can move downward without retreating upward. This behavior provides a persistent threshold against which price can be evaluated. The active defense remains in place until the reversal rules establish a transition, at which point the indicator initializes the defense for the new direction. Two Paths to Reversal Confirmation A reversal first requires a closing-price breach of the active defense. The indicator then accepts either a decisive structural break or a sustained breach. A decisive break occurs when the close also moves beyond the relevant recent, completed price structure. This can confirm a reversal on the same closing bar. Otherwise, price must produce the configured number of consecutive closes beyond the defense. The breach count resets when a close no longer satisfies that condition. The logic operates in both directions. Reversal markers appear only after candle-close confirmation, and the initial assignment of a bullish or bearish regime does not produce a LONG or SHORT signal. Visual Trend Feedback Neon green identifies the bullish regime and its active defense, while purple identifies the bearish regime and its defense. LONG and SHORT triangles mark confirmed directional transitions. Optional displays include the adaptive envelope, historical price channel, and candle coloring that follows the persistent trend state. Adjustable Sensitivity and Display Controls cover smoothing, band width, the ATR minimum, channel length, directional residence, reversal structure, and consecutive-close confirmation. These settings determine how the indicator balances responsiveness with persistence. Wider boundaries and stricter confirmation generally allow more room for price fluctuation while delaying some transitions. Defense lines, bands, channels, markers, and candle coloring can be shown or hidden independently. The indicator can support directional filtering, trend monitoring, and the study of confirmed regime changes within a broader trading method. Its calculations respond to observed price behavior. Sideways markets can still generate repeated reversals, and confirmation introduces delay. Signals describe the indicator’s current assessment; they do not guarantee continuation, profitable trades, or exact turning points.
Source code
Read and review the complete source before using it in your account.
script("Band-Channel Trends - Ms Brown folder", kind="indicator")
input sourceChoice = 0
input filterLength = 12
input bandLength = 20
input bandMultiplier = 1.9
input atrLength = 14
input atrFloor = 0.75
input channelLength = 22
input residenceLength = 12
input structureLength = 5
input confirmBars = 2
input minTick = 0.01
input showDefense = 1
input showBands = 1
input showChannel = 1
input showSignals = 1
input colorBars = 1
input longColor = "#39FF14"
input shortColor = "#8A2BE2"
filterPeriod = math.clamp(math.floor(filterLength), 3, 500)
bandPeriod = math.clamp(math.floor(bandLength), 2, 500)
atrPeriod = math.clamp(math.floor(atrLength), 1, 500)
channelPeriod = math.clamp(math.floor(channelLength), 2, 500)
residencePeriod = math.clamp(math.floor(residenceLength), 2, 500)
structurePeriod = math.clamp(math.floor(structureLength), 2, 500)
confirmation = math.clamp(math.floor(confirmBars), 1, 4)
tick = math.max(minTick, 0.000000000001)
source = sourceChoice == 1 ? close : sourceChoice == 2 ? open : sourceChoice == 3 ? high : sourceChoice == 4 ? low : sourceChoice == 5 ? (high + low) / 2 : sourceChoice == 6 ? (open + high + low + close) / 4 : sourceChoice == 7 ? (high + low + close + close) / 4 : sourceChoice == 8 ? volume : (high + low + close) / 3
a1 = math.exp(-1.414 * 3.141592653589793 / filterPeriod)
b1 = 2 * a1 * math.cos(1.414 * 3.141592653589793 / filterPeriod)
c2 = b1
c3 = -a1 * a1
c1 = 1 - c2 - c3
center = na(center[1]) or na(center[2]) ? source : c1 * (source + source[1]) * 0.5 + c2 * center[1] + c3 * center[2]
// Pine ta.atr seeds Wilder RMA with an SMA, unlike the legacy StScript ta.atr seed.
trueRange = ta.tr()
atrSeed = ta.sma(trueRange, atrPeriod)
atrValue = na(atrValue[1]) ? atrSeed : (atrValue[1] * (atrPeriod - 1) + trueRange) / atrPeriod
residual = source - center
residualSquared = residual * residual
meanSquare = ta.sma(residualSquared, bandPeriod)
rms = na(meanSquare) ? na : math.sqrt(meanSquare)
bandDistance = na(rms) or na(atrValue) ? na : math.max(rms * math.max(0.1, bandMultiplier), atrValue * math.max(0.1, atrFloor))
upperBand = na(bandDistance) ? na : center + bandDistance
lowerBand = na(bandDistance) ? na : center - bandDistance
// Pine highest/lowest ignore unavailable early history. Exclude the current candle.
var channelHighValue = na
var channelLowValue = na
var recentHighValue = na
var recentLowValue = na
lookback = math.max(channelPeriod, structurePeriod)
for j in 1..lookback {
if j <= barIndex {
if j <= channelPeriod {
channelHighValue = na(channelHighValue) ? high[j] : math.max(channelHighValue, high[j])
channelLowValue = na(channelLowValue) ? low[j] : math.min(channelLowValue, low[j])
}
if j <= structurePeriod {
recentHighValue = na(recentHighValue) ? high[j] : math.max(recentHighValue, high[j])
recentLowValue = na(recentLowValue) ? low[j] : math.min(recentLowValue, low[j])
}
}
}
channelHigh = channelHighValue
channelLow = channelLowValue
recentHigh = recentHighValue
recentLow = recentLowValue
bullishClose = close > center ? 1 : 0
bullishResidence = ta.sma(bullishClose, residencePeriod)
bearishResidence = na(bullishResidence) ? na : 1 - bullishResidence
longWeight = na(bullishResidence) ? na : 0.15 + 0.60 * bullishResidence
shortWeight = na(bearishResidence) ? na : 0.15 + 0.60 * bearishResidence
longBoundary = lowerBand * (1 - longWeight) + channelLow * longWeight
shortBoundary = upperBand * (1 - shortWeight) + channelHigh * shortWeight
ready = not na(bandDistance) and not na(channelHigh) and not na(channelLow) and not na(recentHigh) and not na(recentLow) and not na(bullishResidence) and not na(atrValue)
trend = nz(trend[1], 0)
defense = nz(defense[1], na)
breachCount = nz(breachCount[1], 0)
longSignal = 0
shortSignal = 0
if isClosed and ready {
if trend == 0 {
trend = close >= center ? 1 : -1
breachCount = 0
defense = trend == 1 ? math.min(longBoundary, close - atrValue * 0.75) : math.max(shortBoundary, close + atrValue * 0.75)
} else {
if trend == 1 {
breached = close < defense
breachCount = breached ? breachCount + 1 : 0
decisiveBreak = breached and close < recentLow
confirmedBreak = breached and breachCount >= confirmation
if decisiveBreak or confirmedBreak {
trend = -1
defense = math.max(shortBoundary, close + atrValue * 0.75)
breachCount = 0
shortSignal = 1
} else {
if not breached {
defense = math.max(defense, math.min(longBoundary, close - tick))
}
}
} else {
breached = close > defense
breachCount = breached ? breachCount + 1 : 0
decisiveBreak = breached and close > recentHigh
confirmedBreak = breached and breachCount >= confirmation
if decisiveBreak or confirmedBreak {
trend = 1
defense = math.min(longBoundary, close - atrValue * 0.75)
breachCount = 0
longSignal = 1
} else {
if not breached {
defense = math.min(defense, math.max(shortBoundary, close + tick))
}
}
}
}
}
longDefense = showDefense == 1 and trend == 1 ? defense : na
shortDefense = showDefense == 1 and trend == -1 ? defense : na
visibleUpper = showBands == 1 ? upperBand : na
visibleLower = showBands == 1 ? lowerBand : na
visibleChannelHigh = showChannel == 1 ? channelHigh : na
visibleChannelLow = showChannel == 1 ? channelLow : na
plot(longDefense, title="LONG Defense", color=longColor, width=3)
plot(shortDefense, title="SHORT Defense", color=shortColor, width=3)
plot(visibleUpper, title="Upper Band", color=shortColor, width=1, opacity=0.22)
plot(visibleLower, title="Lower Band", color=longColor, width=1, opacity=0.22)
fill(visibleUpper, visibleLower, color="#808080", opacity=0.06)
plot(visibleChannelHigh, title="Channel High", color=shortColor, width=1, opacity=0.17)
plot(visibleChannelLow, title="Channel Low", color=longColor, width=1, opacity=0.17)
plotShape(low, when=showSignals == 1 and longSignal == 1, shape="triangleUp", position="below", color=longColor, size=6)
plotShape(high, when=showSignals == 1 and shortSignal == 1, shape="triangleDown", position="above", color=shortColor, size=6)
plotText(low, when=showSignals == 1 and longSignal == 1, text="LONG", position="below", color=longColor, fontSize=10)
plotText(high, when=showSignals == 1 and shortSignal == 1, text="SHORT", position="above", color=shortColor, fontSize=10)
barcolor(colorBars == 1 and trend == 1, color=longColor)
barcolor(colorBars == 1 and trend == -1, color=shortColor)
alertcondition(longSignal, title="LONG Signal", message="SchizoQuant Band-Channel Persistence Trend: LONG")
alertcondition(shortSignal, title="SHORT Signal", message="SchizoQuant Band-Channel Persistence Trend: SHORT")
Version history
- Version 1View this version →
Discussion · 0
Support this script and join the discussion from your broker’s trading terminal using your author profile.
No comments yet.