OPEN-SOURCE SCRIPT
Close Outside BB Without Touching

//version=5
indicator("Close Outside BB Without Touching", overlay=true)
// Input parameters
length = input.int(20, title="BB Length")
mult = input.float(2.0, title="BB Standard Deviation")
src = input(close, title="Source")
// Calculate Bollinger Bands
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
// Check if candle closed outside BB
closedAbove = close > upper
closedBelow = close < lower
// Check if candle didn't touch the BB during its formation
// For a candle closing above: low must be greater than upper band
// For a candle closing below: high must be less than lower band
noTouchAbove = low > upper
noTouchBelow = high < lower
// Final conditions
validAbove = closedAbove and noTouchAbove
validBelow = closedBelow and noTouchBelow
// Plot Bollinger Bands
plot(basis, "Basis", color=color.orange)
u = plot(upper, "Upper", color=color.blue)
l = plot(lower, "Lower", color=color.blue)
// Fill between Bollinger Bands
fill(u, l, color=color.new(color.blue, 95), title="Background")
// Highlight valid candles
barcolor(validAbove ? color.green : validBelow ? color.red : na)
// Plot markers for valid signals
plotshape(validAbove, title="Valid Above BB", color=color.green,
style=shape.triangleup, location=location.belowbar, size=size.small)
plotshape(validBelow, title="Valid Below BB", color=color.red,
style=shape.triangledown, location=location.abovebar, size=size.small)
// Alert conditions
alertcondition(validAbove, title="Valid Close Above BB",
message="Candle closed above BB without touching")
alertcondition(validBelow, title="Valid Close Below BB",
message="Candle closed below BB without touching")
indicator("Close Outside BB Without Touching", overlay=true)
// Input parameters
length = input.int(20, title="BB Length")
mult = input.float(2.0, title="BB Standard Deviation")
src = input(close, title="Source")
// Calculate Bollinger Bands
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
// Check if candle closed outside BB
closedAbove = close > upper
closedBelow = close < lower
// Check if candle didn't touch the BB during its formation
// For a candle closing above: low must be greater than upper band
// For a candle closing below: high must be less than lower band
noTouchAbove = low > upper
noTouchBelow = high < lower
// Final conditions
validAbove = closedAbove and noTouchAbove
validBelow = closedBelow and noTouchBelow
// Plot Bollinger Bands
plot(basis, "Basis", color=color.orange)
u = plot(upper, "Upper", color=color.blue)
l = plot(lower, "Lower", color=color.blue)
// Fill between Bollinger Bands
fill(u, l, color=color.new(color.blue, 95), title="Background")
// Highlight valid candles
barcolor(validAbove ? color.green : validBelow ? color.red : na)
// Plot markers for valid signals
plotshape(validAbove, title="Valid Above BB", color=color.green,
style=shape.triangleup, location=location.belowbar, size=size.small)
plotshape(validBelow, title="Valid Below BB", color=color.red,
style=shape.triangledown, location=location.abovebar, size=size.small)
// Alert conditions
alertcondition(validAbove, title="Valid Close Above BB",
message="Candle closed above BB without touching")
alertcondition(validBelow, title="Valid Close Below BB",
message="Candle closed below BB without touching")
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.