Breakout wd
//@version=5
indicator("Confirmed Breakout v2 [Swing]", overlay=true, max_labels_count=500, max_lines_count=200)
// ─ INPUTS ─
grp1 = "Pivot S/R"
pivotLen = input.int(10, "Pivot Length", minval=3)
srBuffer = input.float(0.002, "Buffer", step=0.001)
srExpiry = input.int(50, "Expiry")
grp2 = "Bollinger Bands"
bbLen = input.int(20)
bbMult = input.float(2.0)
grp3 = "Volume"
volLen = input.int(20)
volMult = input.float(1.5)
grp4 = "EMA"
useEMA = input.bool(true)
emaLen = input.int(50)
grp5 = "RSI"
useRSI = input.bool(true)
rsiLen = input.int(14)
rsiOB = input.int(75)
rsiOS = input.int(25)
grp6 = "Filters"
useSR = input.bool(true)
useBB = input.bool(true)
useVol = input.bool(true)
cooldown = input.int(5)
grp7 = "ATR"
showLevels = input.bool(true)
atrLen = input.int(14)
atrStopMult = input.float(1.5)
atrTgtMult = input.float(3.0)
grp8 = "Display"
showPanel = input.bool(true)
// ─ CALCULATIONS ─
atr = ta.atr(atrLen)
// BB
bbBasis = ta.sma(close, bbLen)
bbDev = ta.stdev(close, bbLen)
bbUpper = bbBasis + bbMult * bbDev
bbLower = bbBasis - bbMult * bbDev
bbBullBreak = close > bbUpper
bbBearBreak = close < bbLower
// EMA
ema = ta.ema(close, emaLen)
emaBull = close > ema
emaBear = close < ema
// RSI
rsi = ta.rsi(close, rsiLen)
rsiOkBull = not useRSI or rsi < rsiOB
rsiOkBear = not useRSI or rsi > rsiOS
// Volume
volMA = ta.sma(volume, volLen)
volSurge = volume > volMA * volMult
// Pivot
ph = ta.pivothigh(high, pivotLen, pivotLen)
pl = ta.pivotlow(low, pivotLen, pivotLen)
var float lastPH = na
var float lastPL = na
var int lastPH_bar = na
var int lastPL_bar = na
if not na(ph)
lastPH := ph
lastPH_bar := bar_index
if not na(pl)
lastPL := pl
lastPL_bar := bar_index
phValid = not na(lastPH) and (bar_index - lastPH_bar) <= srExpiry
plValid = not na(lastPL) and (bar_index - lastPL_bar) <= srExpiry
phBuf = lastPH * (1 + srBuffer)
plBuf = lastPL * (1 - srBuffer)
srBullBreak = phValid and close > phBuf and open < phBuf
srBearBreak = plValid and close < plBuf and open > plBuf
// Signals
var int lastSignalBar = -999
cooldownOk = (bar_index - lastSignalBar) > cooldown
bullSignal = useSR and srBullBreak and useBB and bbBullBreak and useVol and volSurge and emaBull and rsiOkBull and cooldownOk
bearSignal = useSR and srBearBreak and useBB and bbBearBreak and useVol and volSurge and emaBear and rsiOkBear and cooldownOk
if bullSignal or bearSignal
lastSignalBar := bar_index
// Targets
bullStop = close - atr * atrStopMult
bullTarget = close + atr * atrTgtMult
bearStop = close + atr * atrStopMult
bearTarget = close - atr * atrTgtMult
// ─ SIGNALS ─
plotshape(bullSignal, style=shape.triangleup, location=location.belowbar, color=color.lime)
plotshape(bearSignal, style=shape.triangledown, location=location.abovebar, color=color.red)
// ─ PANEL ─
var table panel = table.new(position.top_right, 2, 8)
f_cell(col, row, txt, c) =>
table.cell(panel, col, row, txt, text_color=c)
if barstate.islast and showPanel
srTxt = srBullBreak ? "Bull" : srBearBreak ? "Bear" : "None"
bbTxt = bbBullBreak ? "Above" : bbBearBreak ? "Below" : "Inside"
volTxt = volSurge ? "High" : "Normal"
emaTxt = emaBull ? "Up" : "Down"
rsiTxt = str.tostring(rsi)
f_cell(0, 0, "BREAKOUT", color.white)
f_cell(1, 0, syminfo.ticker, color.white)
f_cell(0, 1, "S/R", color.gray)
f_cell(1, 1, srTxt, color.white)
f_cell(0, 2, "BB", color.gray)
f_cell(1, 2, bbTxt, color.white)
f_cell(0, 3, "Volume", color.gray)
f_cell(1, 3, volTxt, color.white)
f_cell(0, 4, "Trend", color.gray)
f_cell(1, 4, emaTxt, color.white)
f_cell(0, 5, "RSI", color.gray)
f_cell(1, 5, rsiTxt, color.white)
f_cell(0, 6, "ATR", color.gray)
f_cell(1, 6, str.tostring(atr), color.white)
sigTxt = bullSignal ? "BUY" : bearSignal ? "SELL" : "WAIT"
f_cell(0, 7, "Signal", color.white)
f_cell(1, 7, sigTxt, color.white)
// ─ ALERTS ─
alertcondition(bullSignal, "Bull Breakout", "BUY SIGNAL")
alertcondition(bearSignal, "Bear Breakout", "SELL SIGNAL")
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by GoCharting. Read more in the Terms of Use.
↗ Related Analyses
Comments (0)
Loading comments …

