PROTECTED SOURCE SCRIPT

Charts Bubbles OrderFlow

95
//version=5
indicator("DeepCharts-Style Market Order Bubbles (Modified)", overlay=true, max_labels_count=500)

// === Inputs ===
lookback = input.int(50, "Volume SMA Lookback", minval=1)
multiplier = input.float(4.0, "Bubble Size Multiplier", step=0.1) // Increased default
threshold = input.float(1.5, "Min Volume/SMA Ratio", step=0.1)
showSmall = input.bool(true, "Show Smaller Bubbles")
mode = input.string("Bar Direction (simple)", "Aggressor Mode",
options=["Bar Direction (simple)", "Close v PrevClose", "Estimated Tick Delta"])
showLabels = input.bool(false, "Show Volume Labels")

// === Volume baseline ===
smaVol = ta.sma(volume, lookback)
volRatio = (smaVol == 0.0) ? 0.0 : (volume / smaVol)

// === Aggressor heuristic ===
aggSign = switch mode
"Bar Direction (simple)" => close > open ? 1 : close < open ? -1 : 0
"Close v PrevClose" => close > nz(close[1]) ? 1 : close < nz(close[1]) ? -1 : 0
"Estimated Tick Delta" =>
rng = high - low
pos = rng > 0 ? (close - low) / rng : 0.5
bias = close > open ? 0.1 : close < open ? -0.1 : 0
(pos + bias) > 0.5 ? 1 : -1
=> 0

isBuy = aggSign == 1
isSell = aggSign == -1
showBubble = (volRatio >= threshold) or (showSmall and volRatio >= 0.5)

// === Enhanced Bubble sizes (made bigger) ===
baseSize = math.max(1.5, math.min(8.0, volRatio * multiplier)) // Increased range
largeBubble = showBubble and baseSize > 6 // Raised threshold
mediumBubble = showBubble and baseSize > 4 and baseSize <= 6 // Raised threshold
smallBubble = showBubble and baseSize <= 4 // Adjusted threshold

// === Reversed positioning: Buy BELOW candle, Sell ABOVE candle ===
// Use body bottom for buy bubbles (below), body top for sell bubbles (above)
bodyTop = math.max(open, close)
bodyBottom = math.min(open, close)

// Add small offset to avoid overlap with candle body
bodyHeight = bodyTop - bodyBottom
offset = bodyHeight * 0.05 // 5% of body height offset

buyPos = bodyBottom - offset // Buy bubbles below candle
sellPos = bodyTop + offset // Sell bubbles above candle

// === Plot BIGGER bubbles with reversed positioning ===
plotshape(largeBubble and isBuy ? buyPos : na, title="Buy Large", style=shape.circle,
color=color.new(color.green, 50), size=size.huge, location=location.absolute)
plotshape(mediumBubble and isBuy ? buyPos : na, title="Buy Medium", style=shape.circle,
color=color.new(color.green, 65), size=size.large, location=location.absolute)
plotshape(smallBubble and isBuy ? buyPos : na, title="Buy Small", style=shape.circle,
color=color.new(color.green, 75), size=size.normal, location=location.absolute)

plotshape(largeBubble and isSell ? sellPos : na, title="Sell Large", style=shape.circle,
color=color.new(color.red, 50), size=size.huge, location=location.absolute)
plotshape(mediumBubble and isSell ? sellPos : na, title="Sell Medium", style=shape.circle,
color=color.new(color.red, 65), size=size.large, location=location.absolute)
plotshape(smallBubble and isSell ? sellPos : na, title="Sell Small", style=shape.circle,
color=color.new(color.red, 75), size=size.normal, location=location.absolute)

// === Optional volume labels (adjusted positioning) ===
if showLabels and showBubble
labelY = isBuy ? buyPos : sellPos
labelColor = isBuy ? color.new(color.green, 85) : color.new(color.red, 85)
txt = "Vol: " + str.tostring(volume) + "\nRatio: " + str.tostring(math.round(volRatio, 2))
label.new(bar_index, labelY, txt, yloc=yloc.price, style=label.style_label_left,
color=labelColor, textcolor=color.white, size=size.small)

// === Info table ===
var table t = table.new(position.top_left, 1, 1)
if barstate.islast
infoText = "Vol Ratio: " + str.tostring(math.round(volRatio, 2))
table.cell(t, 0, 0, infoText, text_color=color.white, bgcolor=color.new(color.black, 80))

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.