OPEN-SOURCE SCRIPT
Biller Project

//version=6
indicator("Hoon Fib Project", shorttitle ="Hoon Fib", overlay = true, max_bars_back = 5000)
// -----------------------------------------------------------------------------
// ~~ Tooltips & Constants
// -----------------------------------------------------------------------------
var string t1 = "Period:\nNumber of bars used to detect swing highs and swing lows."
var string t2 = "Projection Level:\nFibonacci ratio used to calculate the projected future targets."
var string t2_b = "Trend Projection Ratio:\nThe secondary Fibonacci ratio for extensions."
var string t15 = "Fib Volume Profile:\nEnable volume profile drawn between the last swing high and low."
var string t20 = "Fib Volume Delta:\nEnable volume delta profile between Fibonacci price bands."
// -----------------------------------------------------------------------------
// ~~ Inputs
// -----------------------------------------------------------------------------
// Group: General Settings
prd = input.int(100, "Period", group = "Fib Settings", tooltip = t1)
lvl = input.float(0.618, "Projection Level", options = [0.236, 0.382, 0.5, 0.618, 0.786], group = "Fib Settings", tooltip = t2)
trendFibbRatio = input.float(1.272, "Trend Projection Ratio", step = 0.001, group = "Fib Settings", tooltip = t2_b)
// Group: Fib Levels Style
fibLvl1 = input.float(0.236, "Level 1", group = "Fib Levels Style", inline = "f1")
fibColor236 = input.color(#f23645, "", group = "Fib Levels Style", inline = "f1")
fibLvl2 = input.float(0.382, "Level 2", group = "Fib Levels Style", inline = "f2")
fibColor382 = input.color(#81c784, "", group = "Fib Levels Style", inline = "f2")
fibLvl3 = input.float(0.500, "Level 3", group = "Fib Levels Style", inline = "f3")
fibColor500 = input.color(#4caf50, "", group = "Fib Levels Style", inline = "f3")
fibLvl4 = input.float(0.618, "Level 4", group = "Fib Levels Style", inline = "f4")
fibColor618 = input.color(#089981, "", group = "Fib Levels Style", inline = "f4")
fibLvl5 = input.float(0.786, "Level 5", group = "Fib Levels Style", inline = "f5")
fibColor786 = input.color(#64b5f6, "", group = "Fib Levels Style", inline = "f5")
// Golden Pocket - FIXED COLOR HERE
showGP = input.bool(true, "Show Golden Pocket (0.65)", group = "Fib Levels Style")
gpColor = input.color(color.new(#FFD700, 85), "GP Color", group = "Fib Levels Style")
fibLineWidth = input.int(2, "Fib Line Width", minval = 1, maxval = 5, group = "Fib Levels Style")
showlab = input.bool(true, "Show Labels", group = "Fib Levels Style", inline = "fiblab")
fibLabelColor = input.color(color.white, "Text Color", group = "Fib Levels Style", inline = "fiblab")
fibLabelSizeStr = input.string("Small", "Size", options = ["Tiny","Small","Normal","Large"], group = "Fib Levels Style", inline = "fiblab")
fibLabelSize = switch fibLabelSizeStr
"Tiny" => size.tiny
"Small" => size.small
"Large" => size.large
=> size.normal
// Group: Swing High/Low Lines
loLineColor = input.color(color.new(color.green, 0), "Low Line", group = "Swing High/Low Lines Style", inline = "hi")
hiLineColor = input.color(color.new(color.red, 0), "High Line", group = "Swing High/Low Lines Style", inline = "hi")
hiloLineWidth = input.int(2, "Width", 1, 5, group = "Swing High/Low Lines Style", inline = "hi")
// Group: Fib Volume Profile
showFibProfile = input.bool(true, "Show Volume Profile", group = "Fib Volume Profile", tooltip = t15)
rows = input.int(24, "Rows", 2, 100, group = "Fib Volume Profile")
flipOrder = input.bool(false, "Flip Bull/Bear", group = "Fib Volume Profile")
bull_color = input.color(color.new(color.teal, 30), "Bull Vol", group = "Fib Volume Profile", inline = "volColor")
bear_color = input.color(color.new(color.orange, 30), "Bear Vol", group = "Fib Volume Profile", inline = "volColor")
showVolText = input.bool(true, "Show Values", group = "Fib Volume Profile", inline = "vtxt")
// Point of Control (POC)
showPOC = input.bool(true, "Show POC Line", group = "Fib Volume Profile")
pocColor = input.color(color.yellow, "POC Color", group = "Fib Volume Profile")
// Group: Fib Volume Delta
showFibDelta = input.bool(false, "Show Volume Delta", group = "Fib Volume Delta Profile", tooltip = t20)
deltaMaxWidth = input.int(30, "Max Width (Bars)", minval = 5, maxval = 200, group = "Fib Volume Delta Profile")
deltaBullColor = input.color(color.new(color.lime, 80), "Bull Delta", group = "Fib Volume Delta Profile", inline = "dc")
deltaBearColor = input.color(color.new(color.red, 80), "Bear Delta", group = "Fib Volume Delta Profile", inline = "dc")
// Group: Projection Style
projLineBullColor = input.color(color.new(color.green, 0), "Proj Bull", group = "Projection Style", inline = "plc")
projLineBearColor = input.color(color.new(color.red, 0), "Proj Bear", group = "Projection Style", inline = "plc")
projLineWidth = input.int(2, "Width", 1, 5, group = "Projection Style", inline = "plc")
projLineStyleStr = input.string("Arrow Right", "Style", options = ["Solid", "Dashed", "Dotted", "Arrow Right"], group = "Projection Style")
projLineStyle = switch projLineStyleStr
"Solid" => line.style_solid
"Dashed" => line.style_dashed
"Dotted" => line.style_dotted
=> line.style_arrow_right
// Group: Projection Box
projBoxBgOn = input.bool(true, "Box Bg", group = "Projection Box Style", inline = "pbg")
projBoxBgColor = input.color(color.new(color.blue, 80), "", group = "Projection Box Style", inline = "pbg")
projBoxTextColor = input.color(color.white, "Text", group = "Projection Box Style", inline = "pbg")
// NEW: Biller's Info Box Inputs
showBillerBox = input.bool(true, "Show Biller's Insight", group = "Biller's Insight")
billerPos = input.string("Top Right", "Position", options = ["Top Right", "Bottom Right", "Bottom Left", "Top Left"], group = "Biller's Insight")
// -----------------------------------------------------------------------------
// ~~ Calculations
// -----------------------------------------------------------------------------
// Swing detection
hi = ta.highest(high, prd)
lo = ta.lowest(low, prd)
isHi = high == hi
isLo = low == lo
HB = ta.barssince(isHi)
LB = ta.barssince(isLo)
hiPrice = ta.valuewhen(isHi, high, 0)
loPrice = ta.valuewhen(isLo, low, 0)
hiBar = ta.valuewhen(isHi, bar_index, 0)
loBar = ta.valuewhen(isLo, bar_index, 0)
// Persistent Drawing Objects
var line hiLine = line.new(na, na, na, na, color = hiLineColor, width = hiloLineWidth)
var line loLine = line.new(na, na, na, na, color = loLineColor, width = hiloLineWidth)
var array<line> fibbLines = array.new_line()
var array<label> fibbLabels = array.new_label()
var array<box> gpBoxes = array.new_box()
var array<line> forecastLines = array.new_line()
var array<box> areas = array.new_box()
var array<label> perc = array.new_label()
var array<box> fibProfileBoxes = array.new_box()
var array<line> pocLines = array.new_line()
var array<box> fibDeltaBoxes = array.new_box()
// Helper Functions
fibbFunc(v, last, h, l) => last ? h - (h - l) * v : l + (h - l) * v
cleaner(a, idx) =>
if idx >= 0 and idx < array.size(a)
el = array.get(a, idx)
if not na(el)
el.delete()
array.remove(a, idx)
// -----------------------------------------------------------------------------
// ~~ Logic Execution
// -----------------------------------------------------------------------------
if not na(HB) and not na(LB) and not na(hiPrice) and not na(loPrice)
// 1. Update Swing High/Low Lines
line.set_xy1(hiLine, hiBar, hiPrice)
line.set_xy2(hiLine, bar_index, hiPrice)
line.set_color(hiLine, hiLineColor)
line.set_xy1(loLine, loBar, loPrice)
line.set_xy2(loLine, bar_index, loPrice)
line.set_color(loLine, loLineColor)
// 2. Clear old drawings
while array.size(fibbLines) > 0
cleaner(fibbLines, 0)
while array.size(fibbLabels) > 0
cleaner(fibbLabels, 0)
while array.size(gpBoxes) > 0
cleaner(gpBoxes, 0)
while array.size(forecastLines) > 0
cleaner(forecastLines, 0)
while array.size(areas) > 0
cleaner(areas, 0)
while array.size(perc) > 0
cleaner(perc, 0)
// 3. Draw Fib Retracements
lvls = array.from(fibLvl1, fibLvl2, fibLvl3, fibLvl4, fibLvl5)
cols = array.from(fibColor236, fibColor382, fibColor500, fibColor618, fibColor786)
baseOffset = HB > LB ? LB : HB
xFibStart = bar_index - baseOffset
// Golden Pocket Logic
if showGP
gp618 = fibbFunc(0.618, HB < LB, hiPrice, loPrice)
gp65 = fibbFunc(0.65, HB < LB, hiPrice, loPrice)
gpBox = box.new(xFibStart, gp618, bar_index + 5, gp65, bgcolor = gpColor, border_color = na)
array.push(gpBoxes, gpBox)
for [i, e] in lvls
f = fibbFunc(e, HB < LB, hiPrice, loPrice)
ln = line.new(xFibStart, f, bar_index, f, color = cols.get(i), width = fibLineWidth)
array.push(fibbLines, ln)
if showlab
lbl = label.new(bar_index + 1, f, str.tostring(e * 100, "#.##") + "%",
textcolor = fibLabelColor, style = label.style_label_left, size = fibLabelSize, color = cols.get(i))
array.push(fibbLabels, lbl)
// 4. Draw Projections
bars = math.abs(HB - LB)
fibb = fibbFunc(lvl, LB > HB, hiPrice, loPrice)
fibb2 = LB < HB ? fibbFunc(lvl, true, fibb, loPrice) : fibbFunc(lvl, false, hiPrice, fibb)
trendfibb = LB > HB ? fibbFunc(trendFibbRatio, true, hiPrice, loPrice) : fibbFunc(trendFibbRatio, false, hiPrice, loPrice)
forecast = array.from(HB < LB ? hiPrice : loPrice, fibb, fibb2, trendfibb)
segment = math.min(bars, math.floor(500.0 / 4.0))
future = bar_index
for i = 0 to forecast.size() - 2
y1 = forecast.get(i)
y2 = forecast.get(i + 1)
x2 = math.min(future + segment, bar_index + 500)
// Draw Projection Line
lnForecast = line.new(future, y1, x2, y2, color = y1 < y2 ? projLineBullColor : projLineBearColor, width = projLineWidth, style = projLineStyle)
array.push(forecastLines, lnForecast)
// Draw Target Box
midBoxLeft = x2 - math.round((future - x2) / 4.0)
txtLevel = i == forecast.size() - 2 ? str.tostring(trendFibbRatio, "#.###") : str.tostring(lvl * 100, "#.##")
boxHeight = math.abs(y1 - y2) / 10.0
bx = box.new(midBoxLeft, y2 + boxHeight, x2 + math.round((future - x2) / 4.0), y2 - boxHeight,
bgcolor = projBoxBgOn ? projBoxBgColor : na, border_width = 1,
text = txtLevel, text_color = projBoxTextColor)
array.push(areas, bx)
future += segment
// 5. Volume Profile Logic
if showFibProfile and hiBar != loBar
while array.size(fibProfileBoxes) > 0
cleaner(fibProfileBoxes, 0)
while array.size(pocLines) > 0
cleaner(pocLines, 0)
top = math.max(hiPrice, loPrice)
bottom = math.min(hiPrice, loPrice)
step = (top - bottom) / rows
// Define bins
volUp = array.new_float(rows, 0.0)
volDn = array.new_float(rows, 0.0)
startBar = math.min(hiBar, loBar)
endBar = math.max(hiBar, loBar)
for bi = startBar to endBar
offset = bar_index - bi
if offset < 4999
p = hlc3[offset]
v = nz(volume[offset])
isBull = close[offset] > open[offset]
// Find correct bin
if p >= bottom and p <= top
idx = int((p - bottom) / step)
idx := math.min(idx, rows - 1)
if isBull
array.set(volUp, idx, array.get(volUp, idx) + v)
else
array.set(volDn, idx, array.get(volDn, idx) + v)
// Draw Volume Boxes and Calc POC
maxTot = 0.0
maxTotIdx = 0 // Track index of max volume
for i = 0 to rows - 1
tot = array.get(volUp, i) + array.get(volDn, i)
if tot > maxTot
maxTot := tot
maxTotIdx := i
span = endBar - startBar + 1
blendTxtColor = color.new(color.white, 30)
minWidthForText = 2
if maxTot > 0
for r = 0 to rows - 1
upV = array.get(volUp, r)
dnV = array.get(volDn, r)
if upV + dnV > 0
normUp = int((upV / maxTot) * span)
normDn = int((dnV / maxTot) * span)
yTop = bottom + step * (r + 1)
yBot = bottom + step * r
// Draw Bull Box
if normUp > 0
txtBull = (showVolText and normUp > minWidthForText) ? str.tostring(upV, format.volume) : ""
bxBull = box.new(startBar + (flipOrder ? 0 : normDn), yTop, startBar + (flipOrder ? normUp : normUp + normDn), yBot,
bgcolor = bull_color, border_style = line.style_dotted, border_color = color.new(bull_color, 50),
text = txtBull, text_color = blendTxtColor, text_size = size.tiny, text_halign = text.align_center, text_valign = text.align_center)
array.push(fibProfileBoxes, bxBull)
// Draw Bear Box
if normDn > 0
txtBear = (showVolText and normDn > minWidthForText) ? str.tostring(dnV, format.volume) : ""
bxBear = box.new(startBar + (flipOrder ? normUp : 0), yTop, startBar + (flipOrder ? normUp + normDn : normDn), yBot,
bgcolor = bear_color, border_style = line.style_dotted, border_color = color.new(bear_color, 50),
text = txtBear, text_color = blendTxtColor, text_size = size.tiny, text_halign = text.align_center, text_valign = text.align_center)
array.push(fibProfileBoxes, bxBear)
// Draw POC Line
if showPOC
pocY = bottom + step * (maxTotIdx + 0.5) // Midpoint of max bin
pocLn = line.new(startBar, pocY, bar_index + 10, pocY, color = pocColor, width = 2, style = line.style_solid)
array.push(pocLines, pocLn)
// 6. Volume Delta Logic
if showFibDelta and hiBar != loBar
while array.size(fibDeltaBoxes) > 0
cleaner(fibDeltaBoxes, 0)
fibPrices = array.new_float()
array.push(fibPrices, hiPrice)
array.push(fibPrices, loPrice)
for e in lvls
array.push(fibPrices, fibbFunc(e, HB < LB, hiPrice, loPrice))
array.sort(fibPrices)
bandsCount = array.size(fibPrices) - 1
bandBull = array.new_float(bandsCount, 0.0)
bandBear = array.new_float(bandsCount, 0.0)
startBar = math.min(hiBar, loBar)
endBar = math.max(hiBar, loBar)
for bi = startBar to endBar
offset = bar_index - bi
if offset < 4999
p = hlc3[offset]
v = nz(volume[offset])
isBull = close[offset] > open[offset]
for b = 0 to bandsCount - 1
bLow = array.get(fibPrices, b)
bHigh = array.get(fibPrices, b + 1)
if p >= bLow and p < bHigh
if isBull
array.set(bandBull, b, array.get(bandBull, b) + v)
else
array.set(bandBear, b, array.get(bandBear, b) + v)
break
maxAbsDelta = 0.0
for b = 0 to bandsCount - 1
maxAbsDelta := math.max(maxAbsDelta, math.abs(array.get(bandBull, b) - array.get(bandBear, b)))
if maxAbsDelta > 0
for b = 0 to bandsCount - 1
delta = array.get(bandBull, b) - array.get(bandBear, b)
if delta != 0
widthBars = int((math.abs(delta) / maxAbsDelta) * deltaMaxWidth)
widthBars := math.max(widthBars, 1)
col = delta >= 0 ? deltaBullColor : deltaBearColor
dBox = box.new(startBar - widthBars, array.get(fibPrices, b+1), startBar, array.get(fibPrices, b),
bgcolor = col, border_color = na,
text = "Δ " + str.tostring(delta, format.volume), text_color = color.new(color.white, 20), text_size = size.small)
array.push(fibDeltaBoxes, dBox)
// -----------------------------------------------------------------------------
// ~~ Biller's Info Box Logic
// -----------------------------------------------------------------------------
var table infoTable = table.new(
position = billerPos == "Top Right" ? position.top_right : billerPos == "Bottom Right" ? position.bottom_right : billerPos == "Bottom Left" ? position.bottom_left : position.top_left,
columns = 1,
rows = 3,
bgcolor = color.new(color.black, 40),
border_width = 1,
border_color = color.new(color.white, 80)
)
if showBillerBox and barstate.islast
// Determine Bias: If the last Pivot was a LOW (LB < HB), market is technically trending UP from that low.
bool isBullish = LB < HB
string biasTitle = isBullish ? "🐂 BULLISH BIAS" : "🐻 BEARISH BIAS"
color biasColor = isBullish ? color.new(color.green, 20) : color.new(color.red, 20)
string biasMsg = isBullish ? "Don't look for shorts, Biller!" : "Don't look for longs, Biller!"
// Array of Quotes
string[] quotes = array.from(
"Biller, you're not gonna pass ur eval looking at the chart all day.",
"Fuck it, go in. I believe in u.",
"Trust JD's Signals.",
"Scared money makes no money, Biller.",
"Evaluation is just a mindset.",
"JD is watching... don't fumble.",
"Are you really gonna take that trade?",
"Wait for the setup, Biller.",
"Don't be a liquidity exit, Biller."
)
int quoteIdx = bar_index % array.size(quotes)
string currentQuote = array.get(quotes, quoteIdx)
// Row 1: Bias Header
table.cell(infoTable, 0, 0, biasTitle, bgcolor = biasColor, text_color = color.white, text_size = size.normal)
// Row 2: Instruction
table.cell(infoTable, 0, 1, biasMsg, text_color = color.white, text_size = size.small)
// Row 3: Motivation/Quote
table.cell(infoTable, 0, 2, "\"" + currentQuote + "\"", text_color = color.yellow, text_size = size.small, text_halign = text.align_center)
indicator("Hoon Fib Project", shorttitle ="Hoon Fib", overlay = true, max_bars_back = 5000)
// -----------------------------------------------------------------------------
// ~~ Tooltips & Constants
// -----------------------------------------------------------------------------
var string t1 = "Period:\nNumber of bars used to detect swing highs and swing lows."
var string t2 = "Projection Level:\nFibonacci ratio used to calculate the projected future targets."
var string t2_b = "Trend Projection Ratio:\nThe secondary Fibonacci ratio for extensions."
var string t15 = "Fib Volume Profile:\nEnable volume profile drawn between the last swing high and low."
var string t20 = "Fib Volume Delta:\nEnable volume delta profile between Fibonacci price bands."
// -----------------------------------------------------------------------------
// ~~ Inputs
// -----------------------------------------------------------------------------
// Group: General Settings
prd = input.int(100, "Period", group = "Fib Settings", tooltip = t1)
lvl = input.float(0.618, "Projection Level", options = [0.236, 0.382, 0.5, 0.618, 0.786], group = "Fib Settings", tooltip = t2)
trendFibbRatio = input.float(1.272, "Trend Projection Ratio", step = 0.001, group = "Fib Settings", tooltip = t2_b)
// Group: Fib Levels Style
fibLvl1 = input.float(0.236, "Level 1", group = "Fib Levels Style", inline = "f1")
fibColor236 = input.color(#f23645, "", group = "Fib Levels Style", inline = "f1")
fibLvl2 = input.float(0.382, "Level 2", group = "Fib Levels Style", inline = "f2")
fibColor382 = input.color(#81c784, "", group = "Fib Levels Style", inline = "f2")
fibLvl3 = input.float(0.500, "Level 3", group = "Fib Levels Style", inline = "f3")
fibColor500 = input.color(#4caf50, "", group = "Fib Levels Style", inline = "f3")
fibLvl4 = input.float(0.618, "Level 4", group = "Fib Levels Style", inline = "f4")
fibColor618 = input.color(#089981, "", group = "Fib Levels Style", inline = "f4")
fibLvl5 = input.float(0.786, "Level 5", group = "Fib Levels Style", inline = "f5")
fibColor786 = input.color(#64b5f6, "", group = "Fib Levels Style", inline = "f5")
// Golden Pocket - FIXED COLOR HERE
showGP = input.bool(true, "Show Golden Pocket (0.65)", group = "Fib Levels Style")
gpColor = input.color(color.new(#FFD700, 85), "GP Color", group = "Fib Levels Style")
fibLineWidth = input.int(2, "Fib Line Width", minval = 1, maxval = 5, group = "Fib Levels Style")
showlab = input.bool(true, "Show Labels", group = "Fib Levels Style", inline = "fiblab")
fibLabelColor = input.color(color.white, "Text Color", group = "Fib Levels Style", inline = "fiblab")
fibLabelSizeStr = input.string("Small", "Size", options = ["Tiny","Small","Normal","Large"], group = "Fib Levels Style", inline = "fiblab")
fibLabelSize = switch fibLabelSizeStr
"Tiny" => size.tiny
"Small" => size.small
"Large" => size.large
=> size.normal
// Group: Swing High/Low Lines
loLineColor = input.color(color.new(color.green, 0), "Low Line", group = "Swing High/Low Lines Style", inline = "hi")
hiLineColor = input.color(color.new(color.red, 0), "High Line", group = "Swing High/Low Lines Style", inline = "hi")
hiloLineWidth = input.int(2, "Width", 1, 5, group = "Swing High/Low Lines Style", inline = "hi")
// Group: Fib Volume Profile
showFibProfile = input.bool(true, "Show Volume Profile", group = "Fib Volume Profile", tooltip = t15)
rows = input.int(24, "Rows", 2, 100, group = "Fib Volume Profile")
flipOrder = input.bool(false, "Flip Bull/Bear", group = "Fib Volume Profile")
bull_color = input.color(color.new(color.teal, 30), "Bull Vol", group = "Fib Volume Profile", inline = "volColor")
bear_color = input.color(color.new(color.orange, 30), "Bear Vol", group = "Fib Volume Profile", inline = "volColor")
showVolText = input.bool(true, "Show Values", group = "Fib Volume Profile", inline = "vtxt")
// Point of Control (POC)
showPOC = input.bool(true, "Show POC Line", group = "Fib Volume Profile")
pocColor = input.color(color.yellow, "POC Color", group = "Fib Volume Profile")
// Group: Fib Volume Delta
showFibDelta = input.bool(false, "Show Volume Delta", group = "Fib Volume Delta Profile", tooltip = t20)
deltaMaxWidth = input.int(30, "Max Width (Bars)", minval = 5, maxval = 200, group = "Fib Volume Delta Profile")
deltaBullColor = input.color(color.new(color.lime, 80), "Bull Delta", group = "Fib Volume Delta Profile", inline = "dc")
deltaBearColor = input.color(color.new(color.red, 80), "Bear Delta", group = "Fib Volume Delta Profile", inline = "dc")
// Group: Projection Style
projLineBullColor = input.color(color.new(color.green, 0), "Proj Bull", group = "Projection Style", inline = "plc")
projLineBearColor = input.color(color.new(color.red, 0), "Proj Bear", group = "Projection Style", inline = "plc")
projLineWidth = input.int(2, "Width", 1, 5, group = "Projection Style", inline = "plc")
projLineStyleStr = input.string("Arrow Right", "Style", options = ["Solid", "Dashed", "Dotted", "Arrow Right"], group = "Projection Style")
projLineStyle = switch projLineStyleStr
"Solid" => line.style_solid
"Dashed" => line.style_dashed
"Dotted" => line.style_dotted
=> line.style_arrow_right
// Group: Projection Box
projBoxBgOn = input.bool(true, "Box Bg", group = "Projection Box Style", inline = "pbg")
projBoxBgColor = input.color(color.new(color.blue, 80), "", group = "Projection Box Style", inline = "pbg")
projBoxTextColor = input.color(color.white, "Text", group = "Projection Box Style", inline = "pbg")
// NEW: Biller's Info Box Inputs
showBillerBox = input.bool(true, "Show Biller's Insight", group = "Biller's Insight")
billerPos = input.string("Top Right", "Position", options = ["Top Right", "Bottom Right", "Bottom Left", "Top Left"], group = "Biller's Insight")
// -----------------------------------------------------------------------------
// ~~ Calculations
// -----------------------------------------------------------------------------
// Swing detection
hi = ta.highest(high, prd)
lo = ta.lowest(low, prd)
isHi = high == hi
isLo = low == lo
HB = ta.barssince(isHi)
LB = ta.barssince(isLo)
hiPrice = ta.valuewhen(isHi, high, 0)
loPrice = ta.valuewhen(isLo, low, 0)
hiBar = ta.valuewhen(isHi, bar_index, 0)
loBar = ta.valuewhen(isLo, bar_index, 0)
// Persistent Drawing Objects
var line hiLine = line.new(na, na, na, na, color = hiLineColor, width = hiloLineWidth)
var line loLine = line.new(na, na, na, na, color = loLineColor, width = hiloLineWidth)
var array<line> fibbLines = array.new_line()
var array<label> fibbLabels = array.new_label()
var array<box> gpBoxes = array.new_box()
var array<line> forecastLines = array.new_line()
var array<box> areas = array.new_box()
var array<label> perc = array.new_label()
var array<box> fibProfileBoxes = array.new_box()
var array<line> pocLines = array.new_line()
var array<box> fibDeltaBoxes = array.new_box()
// Helper Functions
fibbFunc(v, last, h, l) => last ? h - (h - l) * v : l + (h - l) * v
cleaner(a, idx) =>
if idx >= 0 and idx < array.size(a)
el = array.get(a, idx)
if not na(el)
el.delete()
array.remove(a, idx)
// -----------------------------------------------------------------------------
// ~~ Logic Execution
// -----------------------------------------------------------------------------
if not na(HB) and not na(LB) and not na(hiPrice) and not na(loPrice)
// 1. Update Swing High/Low Lines
line.set_xy1(hiLine, hiBar, hiPrice)
line.set_xy2(hiLine, bar_index, hiPrice)
line.set_color(hiLine, hiLineColor)
line.set_xy1(loLine, loBar, loPrice)
line.set_xy2(loLine, bar_index, loPrice)
line.set_color(loLine, loLineColor)
// 2. Clear old drawings
while array.size(fibbLines) > 0
cleaner(fibbLines, 0)
while array.size(fibbLabels) > 0
cleaner(fibbLabels, 0)
while array.size(gpBoxes) > 0
cleaner(gpBoxes, 0)
while array.size(forecastLines) > 0
cleaner(forecastLines, 0)
while array.size(areas) > 0
cleaner(areas, 0)
while array.size(perc) > 0
cleaner(perc, 0)
// 3. Draw Fib Retracements
lvls = array.from(fibLvl1, fibLvl2, fibLvl3, fibLvl4, fibLvl5)
cols = array.from(fibColor236, fibColor382, fibColor500, fibColor618, fibColor786)
baseOffset = HB > LB ? LB : HB
xFibStart = bar_index - baseOffset
// Golden Pocket Logic
if showGP
gp618 = fibbFunc(0.618, HB < LB, hiPrice, loPrice)
gp65 = fibbFunc(0.65, HB < LB, hiPrice, loPrice)
gpBox = box.new(xFibStart, gp618, bar_index + 5, gp65, bgcolor = gpColor, border_color = na)
array.push(gpBoxes, gpBox)
for [i, e] in lvls
f = fibbFunc(e, HB < LB, hiPrice, loPrice)
ln = line.new(xFibStart, f, bar_index, f, color = cols.get(i), width = fibLineWidth)
array.push(fibbLines, ln)
if showlab
lbl = label.new(bar_index + 1, f, str.tostring(e * 100, "#.##") + "%",
textcolor = fibLabelColor, style = label.style_label_left, size = fibLabelSize, color = cols.get(i))
array.push(fibbLabels, lbl)
// 4. Draw Projections
bars = math.abs(HB - LB)
fibb = fibbFunc(lvl, LB > HB, hiPrice, loPrice)
fibb2 = LB < HB ? fibbFunc(lvl, true, fibb, loPrice) : fibbFunc(lvl, false, hiPrice, fibb)
trendfibb = LB > HB ? fibbFunc(trendFibbRatio, true, hiPrice, loPrice) : fibbFunc(trendFibbRatio, false, hiPrice, loPrice)
forecast = array.from(HB < LB ? hiPrice : loPrice, fibb, fibb2, trendfibb)
segment = math.min(bars, math.floor(500.0 / 4.0))
future = bar_index
for i = 0 to forecast.size() - 2
y1 = forecast.get(i)
y2 = forecast.get(i + 1)
x2 = math.min(future + segment, bar_index + 500)
// Draw Projection Line
lnForecast = line.new(future, y1, x2, y2, color = y1 < y2 ? projLineBullColor : projLineBearColor, width = projLineWidth, style = projLineStyle)
array.push(forecastLines, lnForecast)
// Draw Target Box
midBoxLeft = x2 - math.round((future - x2) / 4.0)
txtLevel = i == forecast.size() - 2 ? str.tostring(trendFibbRatio, "#.###") : str.tostring(lvl * 100, "#.##")
boxHeight = math.abs(y1 - y2) / 10.0
bx = box.new(midBoxLeft, y2 + boxHeight, x2 + math.round((future - x2) / 4.0), y2 - boxHeight,
bgcolor = projBoxBgOn ? projBoxBgColor : na, border_width = 1,
text = txtLevel, text_color = projBoxTextColor)
array.push(areas, bx)
future += segment
// 5. Volume Profile Logic
if showFibProfile and hiBar != loBar
while array.size(fibProfileBoxes) > 0
cleaner(fibProfileBoxes, 0)
while array.size(pocLines) > 0
cleaner(pocLines, 0)
top = math.max(hiPrice, loPrice)
bottom = math.min(hiPrice, loPrice)
step = (top - bottom) / rows
// Define bins
volUp = array.new_float(rows, 0.0)
volDn = array.new_float(rows, 0.0)
startBar = math.min(hiBar, loBar)
endBar = math.max(hiBar, loBar)
for bi = startBar to endBar
offset = bar_index - bi
if offset < 4999
p = hlc3[offset]
v = nz(volume[offset])
isBull = close[offset] > open[offset]
// Find correct bin
if p >= bottom and p <= top
idx = int((p - bottom) / step)
idx := math.min(idx, rows - 1)
if isBull
array.set(volUp, idx, array.get(volUp, idx) + v)
else
array.set(volDn, idx, array.get(volDn, idx) + v)
// Draw Volume Boxes and Calc POC
maxTot = 0.0
maxTotIdx = 0 // Track index of max volume
for i = 0 to rows - 1
tot = array.get(volUp, i) + array.get(volDn, i)
if tot > maxTot
maxTot := tot
maxTotIdx := i
span = endBar - startBar + 1
blendTxtColor = color.new(color.white, 30)
minWidthForText = 2
if maxTot > 0
for r = 0 to rows - 1
upV = array.get(volUp, r)
dnV = array.get(volDn, r)
if upV + dnV > 0
normUp = int((upV / maxTot) * span)
normDn = int((dnV / maxTot) * span)
yTop = bottom + step * (r + 1)
yBot = bottom + step * r
// Draw Bull Box
if normUp > 0
txtBull = (showVolText and normUp > minWidthForText) ? str.tostring(upV, format.volume) : ""
bxBull = box.new(startBar + (flipOrder ? 0 : normDn), yTop, startBar + (flipOrder ? normUp : normUp + normDn), yBot,
bgcolor = bull_color, border_style = line.style_dotted, border_color = color.new(bull_color, 50),
text = txtBull, text_color = blendTxtColor, text_size = size.tiny, text_halign = text.align_center, text_valign = text.align_center)
array.push(fibProfileBoxes, bxBull)
// Draw Bear Box
if normDn > 0
txtBear = (showVolText and normDn > minWidthForText) ? str.tostring(dnV, format.volume) : ""
bxBear = box.new(startBar + (flipOrder ? normUp : 0), yTop, startBar + (flipOrder ? normUp + normDn : normDn), yBot,
bgcolor = bear_color, border_style = line.style_dotted, border_color = color.new(bear_color, 50),
text = txtBear, text_color = blendTxtColor, text_size = size.tiny, text_halign = text.align_center, text_valign = text.align_center)
array.push(fibProfileBoxes, bxBear)
// Draw POC Line
if showPOC
pocY = bottom + step * (maxTotIdx + 0.5) // Midpoint of max bin
pocLn = line.new(startBar, pocY, bar_index + 10, pocY, color = pocColor, width = 2, style = line.style_solid)
array.push(pocLines, pocLn)
// 6. Volume Delta Logic
if showFibDelta and hiBar != loBar
while array.size(fibDeltaBoxes) > 0
cleaner(fibDeltaBoxes, 0)
fibPrices = array.new_float()
array.push(fibPrices, hiPrice)
array.push(fibPrices, loPrice)
for e in lvls
array.push(fibPrices, fibbFunc(e, HB < LB, hiPrice, loPrice))
array.sort(fibPrices)
bandsCount = array.size(fibPrices) - 1
bandBull = array.new_float(bandsCount, 0.0)
bandBear = array.new_float(bandsCount, 0.0)
startBar = math.min(hiBar, loBar)
endBar = math.max(hiBar, loBar)
for bi = startBar to endBar
offset = bar_index - bi
if offset < 4999
p = hlc3[offset]
v = nz(volume[offset])
isBull = close[offset] > open[offset]
for b = 0 to bandsCount - 1
bLow = array.get(fibPrices, b)
bHigh = array.get(fibPrices, b + 1)
if p >= bLow and p < bHigh
if isBull
array.set(bandBull, b, array.get(bandBull, b) + v)
else
array.set(bandBear, b, array.get(bandBear, b) + v)
break
maxAbsDelta = 0.0
for b = 0 to bandsCount - 1
maxAbsDelta := math.max(maxAbsDelta, math.abs(array.get(bandBull, b) - array.get(bandBear, b)))
if maxAbsDelta > 0
for b = 0 to bandsCount - 1
delta = array.get(bandBull, b) - array.get(bandBear, b)
if delta != 0
widthBars = int((math.abs(delta) / maxAbsDelta) * deltaMaxWidth)
widthBars := math.max(widthBars, 1)
col = delta >= 0 ? deltaBullColor : deltaBearColor
dBox = box.new(startBar - widthBars, array.get(fibPrices, b+1), startBar, array.get(fibPrices, b),
bgcolor = col, border_color = na,
text = "Δ " + str.tostring(delta, format.volume), text_color = color.new(color.white, 20), text_size = size.small)
array.push(fibDeltaBoxes, dBox)
// -----------------------------------------------------------------------------
// ~~ Biller's Info Box Logic
// -----------------------------------------------------------------------------
var table infoTable = table.new(
position = billerPos == "Top Right" ? position.top_right : billerPos == "Bottom Right" ? position.bottom_right : billerPos == "Bottom Left" ? position.bottom_left : position.top_left,
columns = 1,
rows = 3,
bgcolor = color.new(color.black, 40),
border_width = 1,
border_color = color.new(color.white, 80)
)
if showBillerBox and barstate.islast
// Determine Bias: If the last Pivot was a LOW (LB < HB), market is technically trending UP from that low.
bool isBullish = LB < HB
string biasTitle = isBullish ? "🐂 BULLISH BIAS" : "🐻 BEARISH BIAS"
color biasColor = isBullish ? color.new(color.green, 20) : color.new(color.red, 20)
string biasMsg = isBullish ? "Don't look for shorts, Biller!" : "Don't look for longs, Biller!"
// Array of Quotes
string[] quotes = array.from(
"Biller, you're not gonna pass ur eval looking at the chart all day.",
"Fuck it, go in. I believe in u.",
"Trust JD's Signals.",
"Scared money makes no money, Biller.",
"Evaluation is just a mindset.",
"JD is watching... don't fumble.",
"Are you really gonna take that trade?",
"Wait for the setup, Biller.",
"Don't be a liquidity exit, Biller."
)
int quoteIdx = bar_index % array.size(quotes)
string currentQuote = array.get(quotes, quoteIdx)
// Row 1: Bias Header
table.cell(infoTable, 0, 0, biasTitle, bgcolor = biasColor, text_color = color.white, text_size = size.normal)
// Row 2: Instruction
table.cell(infoTable, 0, 1, biasMsg, text_color = color.white, text_size = size.small)
// Row 3: Motivation/Quote
table.cell(infoTable, 0, 2, "\"" + currentQuote + "\"", text_color = color.yellow, text_size = size.small, text_halign = text.align_center)
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.