//@version=6
// Bollinger Band Breakout Strategy — github.com/trugurpala/pinescriptv6
// Author: Ugur Pala · mail@ugurpala.com
strategy("BB Breakout [trugurpala]",
overlay=true, initial_capital=10000,
default_qty_type=strategy.percent_of_equity, default_qty_value=10,
commission_type=strategy.commission.percent, commission_value=0.1)
// ── Inputs ───────────────────────────────────────────────────────────────────
int bbLen = input.int(20, "BB Length", minval=1)
float bbMult = input.float(2.0, "BB Mult", step=0.1)
int atrLen = input.int(14, "ATR Length", minval=1)
float slMult = input.float(1.5, "SL Mult", step=0.1)
float tpMult = input.float(2.0, "TP Mult", step=0.1)
bool longOnly = input.bool(false, "Long Only")
// ── Calculations ─────────────────────────────────────────────────────────────
[upper, basis, lower] = ta.bb(close, bbLen, bbMult)
float atrVal = ta.atr(atrLen)
bool longEntry = ta.crossover(close, upper) and strategy.position_size == 0
bool shortEntry = ta.crossunder(close, lower) and strategy.position_size == 0
// ── Entries ──────────────────────────────────────────────────────────────────
if longEntry
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long", stop=close - slMult * atrVal, limit=close + tpMult * atrVal)
if shortEntry and not longOnly
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short", stop=close + slMult * atrVal, limit=close - tpMult * atrVal)
// ── Visuals ──────────────────────────────────────────────────────────────────
p1 = plot(upper, "Upper", color.new(color.blue, 30))
p2 = plot(lower, "Lower", color.new(color.blue, 30))
plot(basis, "Basis", color.orange, linewidth=2)
fill(p1, p2, color.new(color.blue, 90))
plotshape(longEntry, "Long", shape.triangleup, location.belowbar, color.green, size=size.normal)
plotshape(shortEntry, "Short", shape.triangledown, location.abovebar, color.red, size=size.normal)