Karlos Alpha V12 Quantum Neural Dr Pnum
Karlos Alpha V12 Quantum Neural Dr Pnum
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=6
indicator("Karlos Alpha V12 Quantum Neural | Dr Pnum", shorttitle="Karlos Alpha V12 | Dr Pnum", overlay=true, max_lines_count=500, max_labels_count=500)
//====================================================================
// INPUTS
//====================================================================
grp_model = "Regression Model"
length = input.int(50, "Regression Length", group=grp_model)
devMult = input.float(2.0, "Deviation Multiplier", group=grp_model)
grp_sqz = "Contraction Metrics"
sqzLen = input.int(100, "Lookback Period", group=grp_sqz)
sqzPct = input.float(20.0, "Contraction Threshold %", group=grp_sqz)
grp_risk = "Target Architecture"
tp1Mult = input.float(1.0, "TP1 Multiplier (x Bandwidth)", group=grp_risk)
tp2Mult = input.float(2.0, "TP2 Multiplier (x Bandwidth)", group=grp_risk)
tp3Mult = input.float(3.0, "TP3 Multiplier (x Bandwidth)", group=grp_risk)
grp_trend = "Holographic Trendlines Overlay"
showTrend = input.bool(true, "Show Holographic Trendlines", group=grp_trend)
pivLen = input.int(10, "Pivot Length", group=grp_trend)
grp_ui = "Advanced UI"
signalBubbleSize = input.string("Large", "Signal Bubble Size", options=["Normal", "Large", "Huge"], group=grp_ui)
showChannel = input.bool(false, "Show Regression Channel", group=grp_ui)
showLevels = input.bool(true, "Show Trade Levels", group=grp_ui)
showTradeInfo = input.bool(true, "Show Active Trade Panel", group=grp_ui)
showPrices = input.bool(true, "Show TP/SL Prices", group=grp_ui)
levelBars = input.int(12, "Level Projection Bars", minval=3, maxval=50, group=grp_ui)
//====================================================================
// REGRESSION MODEL — UNCHANGED
//====================================================================
regBasis = ta.linreg(close, length, 0)
stdDev = ta.stdev(close, length)
upperBand = regBasis + (stdDev * devMult)
lowerBand = regBasis - (stdDev * devMult)
bandWidth = upperBand - lowerBand
minWidth = ta.lowest(bandWidth, sqzLen)
maxWidth = ta.highest(bandWidth, sqzLen)
widthPct = (bandWidth - minWidth) / math.max(maxWidth - minWidth, 0.000001) * 100
isSqueeze = widthPct <= sqzPct
//====================================================================
// HOLOGRAPHIC TRENDLINES — SAME LOGIC
//====================================================================
var float ph1_y = na
var int ph1_x = na
var float ph2_y = na
var int ph2_x = na
var float pl1_y = na
var int pl1_x = na
var float pl2_y = na
var int pl2_x = na
var line line_ph_core = line.new(na, na, na, na, color=color.new(#00FFFF, 0), style=line.style_solid, width=1)
var line line_ph_glow1 = line.new(na, na, na, na, color=color.new(#00FFFF, 60), style=line.style_solid, width=3)
var line line_ph_glow2 = line.new(na, na, na, na, color=color.new(#00FFFF, 85), style=line.style_solid, width=6)
var line line_pl_core = line.new(na, na, na, na, color=color.new(#FF00FF, 0), style=line.style_solid, width=1)
var line line_pl_glow1 = line.new(na, na, na, na, color=color.new(#FF00FF, 60), style=line.style_solid, width=3)
var line line_pl_glow2 = line.new(na, na, na, na, color=color.new(#FF00FF, 85), style=line.style_solid, width=6)
ph = ta.pivothigh(high, pivLen, pivLen)
pl = ta.pivotlow(low, pivLen, pivLen)
if not na(ph)
ph2_y := ph1_y
ph2_x := ph1_x
ph1_y := ph
ph1_x := bar_index - pivLen
if showTrend and not na(ph2_x)
line.set_xy1(line_ph_core, ph2_x, ph2_y)
line.set_xy2(line_ph_core, ph1_x, ph1_y)
line.set_extend(line_ph_core, extend.right)
line.set_xy1(line_ph_glow1, ph2_x, ph2_y)
line.set_xy2(line_ph_glow1, ph1_x, ph1_y)
line.set_extend(line_ph_glow1, extend.right)
line.set_xy1(line_ph_glow2, ph2_x, ph2_y)
line.set_xy2(line_ph_glow2, ph1_x, ph1_y)
line.set_extend(line_ph_glow2, extend.right)
if not na(pl)
pl2_y := pl1_y
pl2_x := pl1_x
pl1_y := pl
pl1_x := bar_index - pivLen
if showTrend and not na(pl2_x)
line.set_xy1(line_pl_core, pl2_x, pl2_y)
line.set_xy2(line_pl_core, pl1_x, pl1_y)
line.set_extend(line_pl_core, extend.right)
line.set_xy1(line_pl_glow1, pl2_x, pl2_y)
line.set_xy2(line_pl_glow1, pl1_x, pl1_y)
line.set_extend(line_pl_glow1, extend.right)
line.set_xy1(line_pl_glow2, pl2_x, pl2_y)
line.set_xy2(line_pl_glow2, pl1_x, pl1_y)
line.set_extend(line_pl_glow2, extend.right)
//====================================================================
// BREAKOUT TRIGGERS — UNCHANGED
//====================================================================
bullTrigger = close > upperBand and close[1] <= upperBand[1] and isSqueeze[1]
bearTrigger = close < lowerBand and close[1] >= lowerBand[1] and isSqueeze[1]
//====================================================================
// TRADE STATE — UNCHANGED
//====================================================================
var int tradeDir = 0
var float entryPx = na
var float slPx = na
var float tp1Px = na
var float tp2Px = na
var float tp3Px = na
var bool tp1Hit = false
var bool tp2Hit = false
var bool tp3Hit = false
var float[] tradeReturns = array.new<float>()
var int totalTrades = 0
var int winTrades = 0
//====================================================================
// ADVANCED UI OBJECTS
//====================================================================
var line lineEp = na
var line lineSl = na
var line lineTp1 = na
var line lineTp2 = na
var line lineTp3 = na
var label lblEntry = na
var label lblSl = na
var label lblTp1 = na
var label lblTp2 = na
var label lblTp3 = na
//====================================================================
// TRADE ENGINE — CORE LOGIC PRESERVED
//====================================================================
if tradeDir == 0
if bullTrigger
tradeDir := 1
entryPx := close
slPx := lowerBand[1]
tp1Px := entryPx + (bandWidth[1] * tp1Mult)
tp2Px := entryPx + (bandWidth[1] * tp2Mult)
tp3Px := entryPx + (bandWidth[1] * tp3Mult)
tp1Hit := false
tp2Hit := false
tp3Hit := false
// Clean BUY bubble
lblEntry := label.new(
bar_index, low,
"BUY",
style=label.style_label_up,
color=color.new(#00FF00, 0),
textcolor=color.white,
size=signalBubbleSize == "Huge" ? size.huge : signalBubbleSize == "Large" ? size.large : size.normal)
else if bearTrigger
tradeDir := -1
entryPx := close
slPx := upperBand[1]
tp1Px := entryPx - (bandWidth[1] * tp1Mult)
tp2Px := entryPx - (bandWidth[1] * tp2Mult)
tp3Px := entryPx - (bandWidth[1] * tp3Mult)
tp1Hit := false
tp2Hit := false
tp3Hit := false
// Clean SELL bubble
lblEntry := label.new(
bar_index, high,
"SELL",
style=label.style_label_down,
color=color.new(#FF0000, 0),
textcolor=color.white,
size=signalBubbleSize == "Huge" ? size.huge : signalBubbleSize == "Large" ? size.large : size.normal)
if tradeDir != 0
// Entry line
lineEp := line.new(
bar_index, entryPx,
bar_index + levelBars, entryPx,
color=color.new(color.white, 25),
style=line.style_dotted,
width=1)
// Stop-loss line
lineSl := line.new(
bar_index, slPx,
bar_index + levelBars, slPx,
color=color.new(#FF0000, 0),
style=line.style_solid,
width=2)
// TP lines
lineTp1 := line.new(
bar_index, tp1Px,
bar_index + levelBars, tp1Px,
color=color.new(#00FF00, 0),
style=line.style_dashed,
width=1)
lineTp2 := line.new(
bar_index, tp2Px,
bar_index + levelBars, tp2Px,
color=color.new(#00FF00, 0),
style=line.style_dashed,
width=1)
lineTp3 := line.new(
bar_index, tp3Px,
bar_index + levelBars, tp3Px,
color=color.new(#00FF00, 0),
style=line.style_solid,
width=2)
// Right-side price labels
lblSl := label.new(
bar_index + levelBars, slPx,
showPrices ? "SL " + str.tostring(slPx, format.mintick) : "SL",
style=label.style_label_left,
color=color.new(#FF0000, 0),
textcolor=color.white,
size=size.small)
lblTp1 := label.new(
bar_index + levelBars, tp1Px,
showPrices ? "TP1 " + str.tostring(tp1Px, format.mintick) : "TP1",
style=label.style_label_left,
color=color.new(#00FF00, 0),
textcolor=color.white,
size=size.small)
lblTp2 := label.new(
bar_index + levelBars, tp2Px,
showPrices ? "TP2 " + str.tostring(tp2Px, format.mintick) : "TP2",
style=label.style_label_left,
color=color.new(#00FF00, 0),
textcolor=color.white,
size=size.small)
lblTp3 := label.new(
bar_index + levelBars, tp3Px,
showPrices ? "TP3 " + str.tostring(tp3Px, format.mintick) : "TP3",
style=label.style_label_left,
color=color.new(#00FF00, 0),
textcolor=color.white,
size=size.small)
//====================================================================
// SIGNAL BUBBLES — REFERENCE-STYLE VISUAL
// Bright green BUY / bright red SELL, enlarged and UI-controlled.
// No signal, entry, SL, TP, or trade-state calculation is changed.
//====================================================================
//====================================================================
// ACTIVE TRADE UI + HIT LOGIC — LOGIC PRESERVED
//====================================================================
if tradeDir != 0
if showLevels
line.set_x2(lineEp, bar_index + levelBars)
line.set_x2(lineSl, bar_index + levelBars)
line.set_x2(lineTp1, bar_index + levelBars)
line.set_x2(lineTp2, bar_index + levelBars)
line.set_x2(lineTp3, bar_index + levelBars)
label.set_x(lblSl, bar_index + levelBars)
label.set_x(lblTp1, bar_index + levelBars)
label.set_x(lblTp2, bar_index + levelBars)
label.set_x(lblTp3, bar_index + levelBars)
label.set_text(lblSl, showPrices ? "SL " + str.tostring(slPx, format.mintick) : "SL")
bool hitSl = (tradeDir == 1 and low <= slPx) or (tradeDir == -1 and high >= slPx)
bool hitTp1 = (tradeDir == 1 and high >= tp1Px) or (tradeDir == -1 and low <= tp1Px)
bool hitTp2 = (tradeDir == 1 and high >= tp2Px) or (tradeDir == -1 and low <= tp2Px)
bool hitTp3 = (tradeDir == 1 and high >= tp3Px) or (tradeDir == -1 and low <= tp3Px)
if hitTp1 and not tp1Hit
tp1Hit := true
slPx := entryPx
line.set_y1(lineSl, slPx)
line.set_y2(lineSl, slPx)
label.set_y(lblSl, slPx)
label.set_text(lblSl, showPrices ? "SL • BE " + str.tostring(slPx, format.mintick) : "SL • BE")
label.new(
bar_index,
tradeDir == 1 ? high : low,
"TP1 HIT • SET TRAIL STOP",
style=tradeDir == 1 ? label.style_label_down : label.style_label_up,
color=color.new(#00FF00, 0),
textcolor=color.white,
size=size.small)
if hitTp2 and not tp2Hit
tp2Hit := true
slPx := tp1Px
line.set_y1(lineSl, slPx)
line.set_y2(lineSl, slPx)
label.set_y(lblSl, slPx)
label.set_text(lblSl, showPrices ? "SL • TP1 " + str.tostring(slPx, format.mintick) : "SL • TP1")
label.new(
bar_index,
tradeDir == 1 ? high : low,
"TP2 HIT • TRAIL AT TP1",
style=tradeDir == 1 ? label.style_label_down : label.style_label_up,
color=color.new(#00FF00, 0),
textcolor=color.white,
size=size.small)
if hitTp3
tradeReturn = ((tp3Px - entryPx) / entryPx) * tradeDir * 100
array.push(tradeReturns, tradeReturn)
totalTrades += 1
winTrades += 1
tradeDir := 0
label.new(
bar_index,
tradeDir == 1 ? high : low,
"TP3 HIT • CLOSED",
style=tradeDir == 1 ? label.style_label_down : label.style_label_up,
color=color.new(#00FF00, 0),
textcolor=color.white,
size=size.small)
else if hitSl
tradeReturn = ((slPx - entryPx) / entryPx) * tradeDir * 100
array.push(tradeReturns, tradeReturn)
totalTrades += 1
if tp1Hit
winTrades += 1
tradeDir := 0
else
label.new(
bar_index,
tradeDir == 1 ? low : high,
"STOP LOSS HIT • CLOSED",
style=tradeDir == 1 ? label.style_label_up : label.style_label_down,
color=color.new(#FF0000, 0),
textcolor=color.white,
size=size.small)
tradeDir := 0
//====================================================================
// CLEAN REGRESSION CHANNEL
//====================================================================
channelColor = isSqueeze ? color.new(color.gray, 55) : color.new(#25324A, 72)
pUpper = plot(showChannel ? upperBand : na, color=channelColor, title="Upper Deviation")
pLower = plot(showChannel ? lowerBand : na, color=channelColor, title="Lower Deviation")
fill(pUpper, pLower, color=showChannel ? color.new(#25324A, 92) : na, title="Regression Channel")
//====================================================================
// FINAL ACTIVE TRADE + PERFORMANCE PANEL
//====================================================================
if barstate.islast
var table tbl = table.new(
position.top_right,
2, 10,
bgcolor=color.new(#0B1020, 8),
border_color=color.new(color.white, 85),
border_width=1,
frame_color=color.new(color.white, 85),
frame_width=1)
float avgRet = array.size(tradeReturns) > 0 ? array.avg(tradeReturns) : 0.0
float stdevRet = array.size(tradeReturns) > 1 ? array.stdev(tradeReturns) : 0.0
float sharpe = stdevRet > 0 ? (avgRet / stdevRet) : 0.0
float winRate = totalTrades > 0 ? (winTrades / totalTrades) * 100 : 0.0
if showTradeInfo
table.cell(tbl, 0, 0, "ARBM • TRADE MAP", text_halign=text.align_center, text_color=color.white, bgcolor=color.new(#111A30, 0))
table.merge_cells(tbl, 0, 0, 1, 0)
string directionText = tradeDir == 1 ? "BUY" : tradeDir == -1 ? "SELL" : "WAIT"
color directionColor = tradeDir == 1 ? #00FF00 : tradeDir == -1 ? #FF0000 : color.gray
string stateText = tradeDir != 0 ? "ACTIVE" : "CLOSED / WAITING"
color stateColor = tradeDir != 0 ? color.orange : color.gray
table.cell(tbl, 0, 1, "STATUS", text_color=color.new(color.white, 35), text_halign=text.align_left)
table.cell(tbl, 1, 1, stateText, text_color=stateColor, text_halign=text.align_right)
table.cell(tbl, 0, 2, "SIGNAL", text_color=color.new(color.white, 35), text_halign=text.align_left)
table.cell(tbl, 1, 2, directionText, text_color=directionColor, text_halign=text.align_right)
table.cell(tbl, 0, 3, "ENTRY", text_color=color.new(color.white, 35), text_halign=text.align_left)
table.cell(tbl, 1, 3, tradeDir != 0 ? str.tostring(entryPx, format.mintick) : "—", text_color=color.white, text_halign=text.align_right)
table.cell(tbl, 0, 4, "TP1 / TP2", text_color=color.new(color.white, 35), text_halign=text.align_left)
table.cell(tbl, 1, 4, tradeDir != 0 ? str.tostring(tp1Px, format.mintick) + " / " + str.tostring(tp2Px, format.mintick) : "—", text_color=#00FF00, text_halign=text.align_right)
table.cell(tbl, 0, 5, "TP3", text_color=color.new(color.white, 35), text_halign=text.align_left)
table.cell(tbl, 1, 5, tradeDir != 0 ? str.tostring(tp3Px, format.mintick) : "—", text_color=#00FF00, text_halign=text.align_right)
table.cell(tbl, 0, 6, "SL / TRAIL", text_color=color.new(color.white, 35), text_halign=text.align_left)
table.cell(tbl, 1, 6, tradeDir != 0 ? str.tostring(slPx, format.mintick) : "—", text_color=#FF0000, text_halign=text.align_right)
table.cell(tbl, 0, 7, "TOTAL TRADES", text_color=color.new(color.white, 35), text_halign=text.align_left)
table.cell(tbl, 1, 7, str.tostring(totalTrades), text_color=color.white, text_halign=text.align_right)
table.cell(tbl, 0, 8, "WIN RATE", text_color=color.new(color.white, 35), text_halign=text.align_left)
table.cell(tbl, 1, 8, str.tostring(winRate, "#.##") + "%", text_color=winRate >= 50 ? #00FF00 : #FF0000, text_halign=text.align_right)
table.cell(tbl, 0, 9, "CLOSED WINS", text_color=color.new(color.white, 35), text_halign=text.align_left)
table.cell(tbl, 1, 9, str.tostring(winTrades), text_color=#00FF00, text_halign=text.align_right)
else
table.clear(tbl, 0, 0, 1, 9)

Comments
Post a Comment