本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This work is licensed under Attribution-NonCommercial-ShareAlike 4.0 International.
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// Original heatmap reference © LuxAlgo; POC zone design
//@version=6
indicator("Aurora Volume POC", "Aurora VOL", overlay = true, behind_chart = false, explicit_plot_zorder = true, max_boxes_count = 500, max_lines_count = 100, max_labels_count = 50)
string GROUP_PROFILE = "1. Volume profile"
string anchorTimeframe = input.timeframe("D", "Profile period", group = GROUP_PROFILE, tooltip = "A new POC starts at each selected period.")
string intrabarTimeframe = input.timeframe("1", "Volume sampling timeframe", group = GROUP_PROFILE, tooltip = "Use a timeframe lower than your chart for more precise volume distribution.")
int profileRows = input.int(50, "Price rows", minval = 10, maxval = 100, group = GROUP_PROFILE)
int maxSamples = input.int(4000, "Maximum samples per period", minval = 500, maxval = 10000, step = 500, group = GROUP_PROFILE, tooltip = "Limits lower-timeframe history used in each profile to control processing time.")
string GROUP_ZONES = "2. POC zones and bounces"
bool showDeveloping = input.bool(true, "Show current POC", group = GROUP_ZONES)
bool showPrior = input.bool(true, "Show completed POCs", group = GROUP_ZONES)
int priorCount = input.int(8, "Completed POCs to show", minval = 1, maxval = 20, group = GROUP_ZONES, active = showPrior)
bool extendPrior = input.bool(true, "Align completed POCs with latest bar", group = GROUP_ZONES, active = showPrior)
int boxWidth = input.int(9, "POC line length (bars)", minval = 2, maxval = 60, group = GROUP_ZONES)
int rightOffset = input.int(5, "Distance from latest bar (bars)", minval = 0, maxval = 150, group = GROUP_ZONES)
int waveRows = input.int(11, "Heatmap rows around POC", minval = 3, maxval = 19, step = 2, group = GROUP_ZONES)
bool showBounceCount = input.bool(true, "Show bounce count on nearest POC", group = GROUP_ZONES)
int bounceDays = input.int(5, "Count bounces over last (days)", minval = 1, maxval = 90, group = GROUP_ZONES, active = showBounceCount)
int bounceConfirmBars = input.int(2, "Bars allowed to confirm bounce", minval = 0, maxval = 10, group = GROUP_ZONES, active = showBounceCount)
int bounceCooldownBars = input.int(3, "Bars before another bounce can count", minval = 0, maxval = 100, group = GROUP_ZONES, active = showBounceCount)
int bounceBufferTicks = input.int(0, "Required close beyond POC (ticks)", minval = 0, maxval = 100, group = GROUP_ZONES, active = showBounceCount, tooltip = "Price must touch the row from outside and close back on the approach side. Add a buffer to require a stronger rejection.")
bool includeDevelopingBounce = input.bool(true, "Include current POC when finding nearest", group = GROUP_ZONES, active = showBounceCount, tooltip = "The current POC can move, so its count is provisional until the profile period closes.")
string GROUP_STYLE = "3. Appearance"
string displayMode = input.string("Heatmap", "POC display", options = ["Heatmap", "Clean lines"], group = GROUP_STYLE, tooltip = "Clean lines shows only the POC row edges and center line. It removes heatmap fills.")
string theme = input.string("Custom", "Theme", options = ["Custom", "Light", "Dark"], group = GROUP_STYLE)
color customEdge = input.color(#D0D0D0, "POC zone edges (Custom)", group = GROUP_STYLE, active = theme == "Custom")
color customPoc = input.color(#FFFFFF, "POC center line (Custom)", group = GROUP_STYLE, active = theme == "Custom")
color customBuy = input.color(#58B7E8, "Up-pressure heat (Custom)", group = GROUP_STYLE, active = theme == "Custom", tooltip = "Pressure uses lower-timeframe candle direction as an estimate, not trade-side volume.")
color customSell = input.color(#ED785B, "Down-pressure heat (Custom)", group = GROUP_STYLE, active = theme == "Custom")
color customText = input.color(#D0D0D0, "POC label text (Custom)", group = GROUP_STYLE, active = theme == "Custom")
int pocLineWidth = input.int(2, "POC line width", minval = 1, maxval = 4, group = GROUP_STYLE)
color edgeInk = theme == "Light" ? #414A58 : theme == "Dark" ? #ADB6C7 : customEdge
color pocInk = theme == "Light" ? #174EA6 : theme == "Dark" ? #F7D46A : customPoc
color buyInk = theme == "Light" ? #1175B7 : theme == "Dark" ? #45B7E9 : customBuy
color sellInk = theme == "Light" ? #BD4A37 : theme == "Dark" ? #FF876B : customSell
color textInk = theme == "Light" ? #232A32 : theme == "Dark" ? #E7EDF5 : customText
int quietHeat = input.int(97, "Low-volume heat transparency", minval = 80, maxval = 100, group = GROUP_STYLE, active = displayMode == "Heatmap")
int peakHeat = input.int(42, "High-volume heat transparency", minval = 0, maxval = 80, group = GROUP_STYLE, active = displayMode == "Heatmap")
bool showLabels = input.bool(true, "Show POC labels", group = GROUP_STYLE)
string labelDetail = input.string("Compact", "POC label detail", options = ["Compact", "Expanded"], group = GROUP_STYLE, active = showLabels, tooltip = "Expanded adds the POC price, distance from the current close, and estimated pressure.")
string GROUP_MARKERS = "4. Volume display"
string markerMode = input.string("Bubbles", "Show volume as", options = ["Bubbles", "Bubble-only", "Candle color", "Both", "Off"], group = GROUP_MARKERS, tooltip = "Candle color and Both draw opaque original-price candles with matching body, wick, and border colors. Bubble-only draws every volume bubble and a close-price path; hide the chart symbol to remove native wicks and borders.")
color customBubbleUp = input.color(#58B7E8, "Up bubbles (Custom)", group = GROUP_MARKERS, active = theme == "Custom")
color customBubbleDown = input.color(#ED785B, "Down bubbles (Custom)", group = GROUP_MARKERS, active = theme == "Custom")
color bubbleUpInk = theme == "Light" ? #1175B7 : theme == "Dark" ? #45B7E9 : customBubbleUp
color bubbleDownInk = theme == "Light" ? #BD4A37 : theme == "Dark" ? #FF876B : customBubbleDown
int volumeLength = input.int(30, "Average over previous bars", minval = 2, maxval = 500, group = GROUP_MARKERS, tooltip = "Each candle's volume is compared with the average of this many completed candles.")
float bubbleMinRatio = input.float(0.7, "Show bubble above average x", minval = 0.0, maxval = 10.0, step = 0.1, group = GROUP_MARKERS, tooltip = "For example, 0.7 means 70% of the previous average. Bubble-only shows all candles with volume.")
float bubbleMaxRatio = input.float(4.0, "Largest bubble at average x", minval = 1.0, maxval = 50.0, step = 0.1, group = GROUP_MARKERS, tooltip = "Bubble size grows automatically between the minimum and this value.")
int bubbleTransparency = input.int(20, "Bubble transparency", minval = 0, maxval = 90, group = GROUP_MARKERS)
bool confirmedMarkers = input.bool(true, "Show bubbles after candle closes", group = GROUP_MARKERS)
string GROUP_ABS = "5. Reversal markers"
bool showAbsorption = input.bool(true, "Show absorption proxy dots", group = GROUP_ABS, tooltip = "A high-volume rejection wick followed within 1-2 candles by opposite-direction volume and price confirmation. The dot is placed on the original wick after confirmation. This does not measure the order book.")
color customDotUp = input.color(#78D9A1, "Bullish dot (Custom)", group = GROUP_ABS, active = theme == "Custom" and showAbsorption)
color customDotDown = input.color(#F7B967, "Bearish dot (Custom)", group = GROUP_ABS, active = theme == "Custom" and showAbsorption)
color dotUpInk = theme == "Light" ? #168350 : theme == "Dark" ? #78D9A1 : customDotUp
color dotDownInk = theme == "Light" ? #A65A17 : theme == "Dark" ? #F7B967 : customDotDown
float absorptionVolume = input.float(1.2, "Minimum volume / average", minval = 0.5, maxval = 30.0, step = 0.1, group = GROUP_ABS, active = showAbsorption)
float maxBodyFraction = input.float(0.65, "Maximum body / candle range", minval = 0.01, maxval = 0.95, step = 0.05, group = GROUP_ABS, active = showAbsorption)
float minWickFraction = input.float(0.25, "Minimum rejection wick / range", minval = 0.05, maxval = 0.95, step = 0.05, group = GROUP_ABS, active = showAbsorption)
float wickDominance = input.float(1.2, "Wick vs opposite wick", minval = 1.0, maxval = 5.0, step = 0.1, group = GROUP_ABS, active = showAbsorption)
float switchRatio = input.float(1.1, "New pressure vs opposite pressure", minval = 1.0, maxval = 5.0, step = 0.1, group = GROUP_ABS, active = showAbsorption)
int confirmWithin = input.int(2, "Confirm within bars", minval = 1, maxval = 2, group = GROUP_ABS, active = showAbsorption)
bool showSwitchBubbles = input.bool(true, "Mark the confirming candle with a bubble", group = GROUP_ABS, active = showAbsorption)
int dotTransparency = input.int(5, "Dot transparency", minval = 0, maxval = 90, group = GROUP_ABS, active = showAbsorption)
string GROUP_SR = "6. Support and resistance"
string srMode = input.string("Auto pivot", "Zone source", options = ["Off", "Auto pivot", "Manual"], group = GROUP_SR)
string srSide = input.string("Both", "Zones to show", options = ["Both", "Nearest", "Support", "Resistance"], group = GROUP_SR, active = srMode != "Off")
string srTimeframe = input.timeframe("60", "Pivot timeframe", group = GROUP_SR, active = srMode == "Auto pivot", tooltip = "Select a timeframe equal to or higher than the chart timeframe.")
int srPivotBars = input.int(3, "Bars to confirm a pivot", minval = 1, maxval = 20, group = GROUP_SR, active = srMode == "Auto pivot")
float srAtrWidth = input.float(0.25, "Automatic zone width (ATR fraction)", minval = 0.01, maxval = 5.0, step = 0.05, group = GROUP_SR, active = srMode == "Auto pivot")
float srManualSupport = input.float(0.0, "Manual support price (0 = hide)", minval = 0.0, group = GROUP_SR, active = srMode == "Manual")
float srManualResistance = input.float(0.0, "Manual resistance price (0 = hide)", minval = 0.0, group = GROUP_SR, active = srMode == "Manual")
int srManualWidthTicks = input.int(20, "Manual zone half-width (ticks)", minval = 1, maxval = 10000, group = GROUP_SR, active = srMode == "Manual")
int srBackBars = input.int(120, "Zone length (bars)", minval = 2, maxval = 500, group = GROUP_SR, active = srMode != "Off")
int srTransparency = input.int(88, "Zone fill transparency", minval = 0, maxval = 100, group = GROUP_SR, active = srMode != "Off")
color customSupport = input.color(#38AB75, "Support zone (Custom)", group = GROUP_SR, active = srMode != "Off" and theme == "Custom")
color customResistance = input.color(#D65C60, "Resistance zone (Custom)", group = GROUP_SR, active = srMode != "Off" and theme == "Custom")
color supportInk = theme == "Light" ? #138452 : theme == "Dark" ? #5BD19A : customSupport
color resistanceInk = theme == "Light" ? #AF3E45 : theme == "Dark" ? #FA8290 : customResistance
string GROUP_ALERTS = "7. Alerts"
bool alertZoneTouch = input.bool(false, "Alert on POC touch", group = GROUP_ALERTS)
bool alertBubble = input.bool(false, "Alert on high-volume bubble", group = GROUP_ALERTS)
bool alertAbsorption = input.bool(false, "Alert on confirmed reversal marker", group = GROUP_ALERTS)
type PocZone
int startBar
int endBar
int startTime
float lowPrice
float highPrice
float centerPrice
float pocVolume
float pocPressure
array<float> heat
array<float> pressure
array<box> bands
box frame
line upper
line lower
line midline
label caption
array<int> bounceTimes
int pendingSide
int pendingBar
int lastBounceBar
bool wasTouching
type SrVisual
box area
line center
label caption
f_clamp(float value, float lo, float hi) =>
math.max(lo, math.min(hi, value))
f_volume(float value) =>
value >= 1000000000 ? str.tostring(value / 1000000000, "#.##") + "B" : value >= 1000000 ? str.tostring(value / 1000000, "#.##") + "M" : value >= 1000 ? str.tostring(value / 1000, "#.##") + "K" : str.tostring(value, "#")
f_age(int stamp) =>
int minutes = int(math.floor(math.max(0, time - stamp) / 60000.0))
minutes >= 1440 ? str.tostring(int(math.floor(minutes / 1440.0))) + "d" : minutes >= 60 ? str.tostring(int(math.floor(minutes / 60.0))) + "h" : str.tostring(minutes) + "m"
// Count one confirmed return to the approach side per visit to a POC row.
f_update_bounces(PocZone zone) =>
int cutoff = time - bounceDays * 86400000
while array.size(zone.bounceTimes) > 0 and array.get(zone.bounceTimes, 0) < cutoff
array.shift(zone.bounceTimes)
if barstate.isconfirmed and not na(zone.centerPrice)
bool touching = low <= zone.highPrice and high >= zone.lowPrice
if zone.pendingSide == 0 and touching and not zone.wasTouching and bar_index - zone.lastBounceBar > bounceCooldownBars
zone.pendingSide := close[1] > zone.highPrice ? 1 : close[1] < zone.lowPrice ? -1 : 0
zone.pendingBar := bar_index
if zone.pendingSide != 0
float buffer = bounceBufferTicks * syminfo.mintick
bool wrongSide = zone.pendingSide == 1 ? close < zone.lowPrice : close > zone.highPrice
bool returned = zone.pendingSide == 1 ? close > zone.highPrice + buffer : close < zone.lowPrice - buffer
if wrongSide or bar_index - zone.pendingBar > bounceConfirmBars
zone.pendingSide := 0
else if returned
array.push(zone.bounceTimes, time)
if array.size(zone.bounceTimes) > 500
array.shift(zone.bounceTimes)
zone.lastBounceBar := bar_index
zone.pendingSide := 0
zone.wasTouching := touching
array.size(zone.bounceTimes)
f_hide_sr(SrVisual visual) =>
if not na(visual.area)
box.delete(visual.area)
visual.area := na
if not na(visual.center)
line.delete(visual.center)
visual.center := na
if not na(visual.caption)
label.delete(visual.caption)
visual.caption := na
true
f_draw_sr(SrVisual visual, float price, float halfWidth, bool support, int left, int right, string sourceName) =>
color zoneInk = support ? supportInk : resistanceInk
if na(visual.area)
visual.area := box.new(left, price + halfWidth, right, price - halfWidth, xloc = xloc.bar_index, border_color = zoneInk, bgcolor = color.new(zoneInk, srTransparency))
box.set_lefttop(visual.area, left, price + halfWidth)
box.set_rightbottom(visual.area, right, price - halfWidth)
box.set_border_color(visual.area, zoneInk)
box.set_bgcolor(visual.area, color.new(zoneInk, srTransparency))
if na(visual.center)
visual.center := line.new(left, price, right, price, xloc = xloc.bar_index, color = zoneInk, style = line.style_dashed)
line.set_xy1(visual.center, left, price)
line.set_xy2(visual.center, right, price)
line.set_color(visual.center, zoneInk)
if na(visual.caption)
visual.caption := label.new(right + 2, price, "", xloc = xloc.bar_index, yloc = yloc.price, style = label.style_label_left, color = color.new(color.black, 100), textcolor = zoneInk, size = size.tiny)
label.set_xy(visual.caption, right + 2, price)
label.set_textcolor(visual.caption, zoneInk)
label.set_text(visual.caption, (support ? "SUP " : "RES ") + str.tostring(price, format.mintick) + " · " + sourceName)
true
f_delete(PocZone zone) =>
for band in zone.bands
box.delete(band)
if not na(zone.frame)
box.delete(zone.frame)
if not na(zone.upper)
line.delete(zone.upper)
if not na(zone.lower)
line.delete(zone.lower)
if not na(zone.midline)
line.delete(zone.midline)
if not na(zone.caption)
label.delete(zone.caption)
true
// Spread each intrabar's volume across the actual overlap of its price range and each row.
f_profile(array<float> highs, array<float> lows, array<float> volumes, array<float> directions, int count, int bandCount) =>
float pocLow = na
float pocHigh = na
float pocCenter = na
float pocVolume = na
float pocPressure = na
array<float> heat = array.new_float(bandCount, 0.0)
array<float> pressure = array.new_float(bandCount, 0.0)
int samples = array.size(highs)
if samples > 0
float top = na
float bottom = na
for i = 0 to samples - 1
float h = array.get(highs, i)
float l = array.get(lows, i)
float v = array.get(volumes, i)
if not na(h) and not na(l) and not na(v) and v > 0
top := na(top) ? h : math.max(top, h)
bottom := na(bottom) ? l : math.min(bottom, l)
if not na(top) and not na(bottom)
top := top <= bottom ? bottom + syminfo.mintick * count : top
float step = (top - bottom) / count
array<float> rows = array.new_float(count, 0.0)
array<float> signedRows = array.new_float(count, 0.0)
for i = 0 to samples - 1
float h = array.get(highs, i)
float l = array.get(lows, i)
float v = array.get(volumes, i)
float direction = array.get(directions, i)
if not na(h) and not na(l) and not na(v) and v > 0
int first = int(f_clamp(math.floor((l - bottom) / step), 0, count - 1))
int last = int(f_clamp(math.floor((h - bottom) / step), 0, count - 1))
for j = first to last
float rowLow = bottom + j * step
float overlap = math.max(0.0, math.min(h, rowLow + step) - math.max(l, rowLow))
float piece = h > l ? v * overlap / (h - l) : (j == first ? v : 0.0)
array.set(rows, j, array.get(rows, j) + piece)
array.set(signedRows, j, array.get(signedRows, j) + piece * direction)
float maximum = 0.0
int peak = 0
for j = 0 to count - 1
float candidate = array.get(rows, j)
if candidate > maximum
maximum := candidate
peak := j
if maximum > 0
pocLow := bottom + peak * step
pocHigh := pocLow + step
pocCenter := math.avg(pocLow, pocHigh)
pocVolume := maximum
pocPressure := array.get(signedRows, peak) / maximum
int half = int(math.floor(bandCount / 2.0))
// A three-row kernel softens jagged data without inventing a symmetric profile.
for k = 0 to bandCount - 1
int row = peak + k - half
float left = row > 0 and row - 1 < count ? array.get(rows, row - 1) : 0.0
float middle = row >= 0 and row < count ? array.get(rows, row) : 0.0
float right = row + 1 >= 0 and row + 1 < count ? array.get(rows, row + 1) : 0.0
array.set(heat, k, f_clamp((left + 2.0 * middle + right) / (4.0 * maximum), 0.0, 1.0))
float signed = row >= 0 and row < count ? array.get(signedRows, row) : 0.0
array.set(pressure, k, middle > 0 ? signed / middle : 0.0)
[pocLow, pocHigh, pocCenter, pocVolume, pocPressure, heat, pressure]
// The bands occupy neighboring real price rows; the POC stays on the central row.
f_draw(PocZone zone, int left, int right, bool developing, int age) =>
int n = array.size(zone.heat)
float step = zone.highPrice - zone.lowPrice
int half = int(math.floor(n / 2.0))
float bottom = zone.lowPrice - half * step
float top = bottom + n * step
int fade = developing ? 0 : math.min(26, (age - 1) * 4)
color stroke = color.new(edgeInk, developing ? 14 : math.min(88, 44 + fade))
color pocStroke = color.new(pocInk, developing ? 0 : math.min(80, 24 + fade))
color words = color.new(textInk, developing ? 0 : math.min(85, 22 + fade))
if displayMode == "Clean lines"
if na(zone.upper)
zone.upper := line.new(left, zone.highPrice, right, zone.highPrice, xloc = xloc.bar_index, color = stroke, width = 1)
if na(zone.lower)
zone.lower := line.new(left, zone.lowPrice, right, zone.lowPrice, xloc = xloc.bar_index, color = stroke, width = 1)
line.set_xy1(zone.upper, left, zone.highPrice)
line.set_xy2(zone.upper, right, zone.highPrice)
line.set_color(zone.upper, stroke)
line.set_xy1(zone.lower, left, zone.lowPrice)
line.set_xy2(zone.lower, right, zone.lowPrice)
line.set_color(zone.lower, stroke)
else
if na(zone.frame)
zone.frame := box.new(left, top, right, bottom, xloc = xloc.bar_index, border_color = stroke, border_width = 1, bgcolor = na)
box.set_lefttop(zone.frame, left, top)
box.set_rightbottom(zone.frame, right, bottom)
box.set_border_color(zone.frame, stroke)
for k = 0 to n - 1
float bandLow = bottom + k * step
float bandHigh = bandLow + step
float strength = array.get(zone.heat, k)
float signedPressure = array.get(zone.pressure, k)
int opacity = int(f_clamp(quietHeat - strength * (quietHeat - peakHeat) + fade, 0, 100))
color pressureInk = color.from_gradient(math.abs(signedPressure), 0.0, 1.0, edgeInk, signedPressure >= 0 ? buyInk : sellInk)
color fill = color.new(pressureInk, opacity)
if array.size(zone.bands) <= k
array.push(zone.bands, box.new(left, bandHigh, right, bandLow, xloc = xloc.bar_index, border_color = na, bgcolor = fill))
box band = array.get(zone.bands, k)
box.set_lefttop(band, left, bandHigh)
box.set_rightbottom(band, right, bandLow)
box.set_bgcolor(band, fill)
if na(zone.midline)
zone.midline := line.new(left, zone.centerPrice, right, zone.centerPrice, xloc = xloc.bar_index, color = pocStroke, style = line.style_dotted, width = pocLineWidth)
line.set_xy1(zone.midline, left, zone.centerPrice)
line.set_xy2(zone.midline, right, zone.centerPrice)
line.set_color(zone.midline, pocStroke)
line.set_width(zone.midline, pocLineWidth)
if showLabels
if na(zone.caption)
zone.caption := label.new(right + 2, zone.centerPrice, "", xloc = xloc.bar_index, yloc = yloc.price, style = label.style_label_left, color = color.new(color.black, 100), textcolor = words, size = size.tiny, textalign = text.align_left, text_font_family = font.family_monospace)
string status = developing ? "LIVE" : f_age(zone.startTime)
string caption = "POC " + status + " · " + f_volume(zone.pocVolume)
if labelDetail == "Expanded"
float pct = zone.centerPrice != 0 ? (close / zone.centerPrice - 1.0) * 100.0 : na
string distance = na(pct) ? "n/a" : (pct > 0 ? "+" : "") + str.tostring(pct, "#.##") + "%"
string pressureText = (zone.pocPressure > 0 ? "+" : "") + str.tostring(zone.pocPressure * 100.0, "#.0") + "% pressure proxy"
caption := "POC " + str.tostring(zone.centerPrice, format.mintick) + " · " + status + "\n" + distance + " close · " + f_volume(zone.pocVolume) + " vol · " + pressureText
label.set_xy(zone.caption, right + 2, zone.centerPrice)
label.set_textcolor(zone.caption, words)
label.set_text(zone.caption, caption)
true
[ltfHighs, ltfLows, ltfVolumes, ltfOpens, ltfCloses] = request.security_lower_tf(syminfo.tickerid, intrabarTimeframe, [high, low, volume, open, close], ignore_invalid_timeframe = true)
var array<float> anchorHighs = array.new_float()
var array<float> anchorLows = array.new_float()
var array<float> anchorVolumes = array.new_float()
var array<float> anchorDirections = array.new_float()
var array<PocZone> history = array.new<PocZone>()
var PocZone active = na
if barstate.isfirst or timeframe.change(anchorTimeframe)
if not na(active) and not na(active.centerPrice)
active.endBar := bar_index - 1
if showPrior
array.push(history, active)
while array.size(history) > priorCount
f_delete(array.shift(history))
else
f_delete(active)
else if not na(active)
f_delete(active)
array.clear(anchorHighs)
array.clear(anchorLows)
array.clear(anchorVolumes)
array.clear(anchorDirections)
active := PocZone.new(bar_index, bar_index, time, na, na, na, na, na, array.new_float(), array.new_float(), array.new<box>(), na, na, na, na, na, array.new_int(), 0, na, -1000000, false)
int intrabars = array.size(ltfHighs)
float candleUpVolume = 0.0
float candleDownVolume = 0.0
if intrabars > 0
for i = 0 to intrabars - 1
float h = array.get(ltfHighs, i)
float l = array.get(ltfLows, i)
float v = array.get(ltfVolumes, i)
float o = array.get(ltfOpens, i)
float c = array.get(ltfCloses, i)
if not na(h) and not na(l) and not na(v) and not na(o) and not na(c) and v > 0
array.push(anchorHighs, h)
array.push(anchorLows, l)
array.push(anchorVolumes, v)
array.push(anchorDirections, c > o ? 1.0 : c < o ? -1.0 : 0.0)
candleUpVolume += c > o ? v : c == o ? v * 0.5 : 0.0
candleDownVolume += c < o ? v : c == o ? v * 0.5 : 0.0
else if not na(volume) and volume > 0
array.push(anchorHighs, high)
array.push(anchorLows, low)
array.push(anchorVolumes, volume)
array.push(anchorDirections, close > open ? 1.0 : close < open ? -1.0 : 0.0)
candleUpVolume := close > open ? volume : close == open ? volume * 0.5 : 0.0
candleDownVolume := close < open ? volume : close == open ? volume * 0.5 : 0.0
while array.size(anchorHighs) > maxSamples
array.shift(anchorHighs)
array.shift(anchorLows)
array.shift(anchorVolumes)
array.shift(anchorDirections)
[pocLow, pocHigh, pocCenter, pocVolume, pocPressure, wave, pressureWave] = f_profile(anchorHighs, anchorLows, anchorVolumes, anchorDirections, profileRows, waveRows)
if not na(pocCenter)
active.endBar := bar_index
active.lowPrice := pocLow
active.highPrice := pocHigh
active.centerPrice := pocCenter
active.pocVolume := pocVolume
active.pocPressure := pocPressure
active.heat := wave
active.pressure := pressureWave
if showDeveloping
int left = math.max(active.startBar, bar_index - boxWidth + 1) + rightOffset
f_draw(active, left, bar_index + rightOffset, true, 0)
if showBounceCount and not na(active) and not na(active.centerPrice)
f_update_bounces(active)
if showBounceCount and showPrior and array.size(history) > 0
for i = 0 to array.size(history) - 1
f_update_bounces(array.get(history, i))
if barstate.islast and showPrior and array.size(history) > 0
int total = array.size(history)
for i = 0 to total - 1
PocZone zone = array.get(history, i)
int right = (extendPrior ? bar_index : zone.endBar) + rightOffset
int left = math.max(zone.startBar + rightOffset, right - boxWidth + 1)
f_draw(zone, left, right, false, total - i)
// Ratio is candle volume divided by the previous N completed candles' average.
// Five fixed shape sizes map to monotonically increasing relative-volume bands.
float averageVolume = ta.sma(volume[1], volumeLength)
float volumeRatio = averageVolume > 0 ? volume / averageVolume : na
plot(volumeRatio, title = "Candle volume / prior average", display = display.data_window, precision = 2)
bool markerReady = not confirmedMarkers or barstate.isconfirmed
bool bubbleOnly = markerMode == "Bubble-only"
bool bubblesEnabled = markerMode == "Bubbles" or markerMode == "Both" or bubbleOnly
bool colorsEnabled = markerMode == "Candle color" or markerMode == "Both"
float volumeSizeSpan = math.max(0.4, bubbleMaxRatio - bubbleMinRatio)
float smallCut = bubbleMinRatio + volumeSizeSpan * 0.15
float mediumCut = bubbleMinRatio + volumeSizeSpan * 0.35
float largeCut = bubbleMinRatio + volumeSizeSpan * 0.60
float hugeCut = bubbleMinRatio + volumeSizeSpan
bool bubbleSignal = bubblesEnabled and markerReady and not na(volumeRatio) and volume > 0 and (bubbleOnly or volumeRatio >= bubbleMinRatio)
bool buyDominant = candleUpVolume > candleDownVolume
bool sellDominant = candleDownVolume > candleUpVolume
bool bubbleBuyer = buyDominant or not sellDominant and close >= open
float bubbleY = bubbleBuyer ? low + (high - low) * 0.15 : high - (high - low) * 0.15
color bubbleInk = color.new(bubbleBuyer ? bubbleUpInk : bubbleDownInk, bubbleTransparency)
color quietBubbleInk = color.new(bubbleBuyer ? bubbleUpInk : bubbleDownInk, math.min(90, bubbleTransparency + 40))
// Opaque color and the same original-price OHLC for body, wick, and border.
// Keep native bars in sync underneath the overlay; color live bars as volume evolves.
color candleInk = color.from_gradient(math.min(nz(volumeRatio), hugeCut), 0.0, hugeCut, edgeInk, bubbleBuyer ? bubbleUpInk : bubbleDownInk)
bool paintVolumeCandle = colorsEnabled and not na(volumeRatio)
barcolor(bubbleOnly ? color.new(color.white, 100) : paintVolumeCandle ? candleInk : na)
plotcandle(paintVolumeCandle ? open : na, paintVolumeCandle ? high : na, paintVolumeCandle ? low : na, paintVolumeCandle ? close : na, title = "Volume-colored original candles", color = candleInk, wickcolor = candleInk, bordercolor = candleInk)
plotshape(bubbleSignal and volumeRatio < smallCut ? bubbleY : na, title = "Volume bubble · very low", style = shape.circle, location = location.absolute, color = quietBubbleInk, size = size.tiny, force_overlay = true)
plotshape(bubbleSignal and volumeRatio >= smallCut and volumeRatio < mediumCut ? bubbleY : na, title = "Volume bubble · low", style = shape.circle, location = location.absolute, color = bubbleInk, size = size.small, force_overlay = true)
plotshape(bubbleSignal and volumeRatio >= mediumCut and volumeRatio < largeCut ? bubbleY : na, title = "Volume bubble · medium", style = shape.circle, location = location.absolute, color = bubbleInk, size = size.normal, force_overlay = true)
plotshape(bubbleSignal and volumeRatio >= largeCut and volumeRatio < hugeCut ? bubbleY : na, title = "Volume bubble · high", style = shape.circle, location = location.absolute, color = bubbleInk, size = size.large, force_overlay = true)
plotshape(bubbleSignal and volumeRatio >= hugeCut ? bubbleY : na, title = "Volume bubble · extreme", style = shape.circle, location = location.absolute, color = bubbleInk, size = size.huge, force_overlay = true)
plot(bubbleOnly ? close : na, title = "Bubble-only close-price path", color = color.new(pocInk, 25), linewidth = 2, style = plot.style_line, force_overlay = true)
// Bubble-only fades native bodies; its wick/border visibility depends on chart settings.
float candleRange = high - low
float bodyFraction = candleRange > 0 ? math.abs(close - open) / candleRange : 1.0
float lowerWick = candleRange > 0 ? (math.min(open, close) - low) / candleRange : 0.0
float upperWick = candleRange > 0 ? (high - math.max(open, close)) / candleRange : 0.0
bool absorptionBase = not na(volumeRatio) and volumeRatio >= absorptionVolume and bodyFraction <= maxBodyFraction
bool bullCandidate = absorptionBase and sellDominant and lowerWick >= minWickFraction and lowerWick >= upperWick * wickDominance
bool bearCandidate = absorptionBase and buyDominant and upperWick >= minWickFraction and upperWick >= lowerWick * wickDominance
bool switchedBuy = markerReady and candleUpVolume >= candleDownVolume * switchRatio and candleUpVolume > 0 and close > open
bool switchedSell = markerReady and candleDownVolume >= candleUpVolume * switchRatio and candleDownVolume > 0 and close < open
bool bullConfirmed1 = bullCandidate[1] and switchedBuy and close >= math.avg(open[1], close[1])
bool bearConfirmed1 = bearCandidate[1] and switchedSell and close <= math.avg(open[1], close[1])
bool bullConfirmed2 = confirmWithin == 2 and bullCandidate[2] and not bullConfirmed1[1] and switchedBuy and close >= math.avg(open[2], close[2])
bool bearConfirmed2 = confirmWithin == 2 and bearCandidate[2] and not bearConfirmed1[1] and switchedSell and close <= math.avg(open[2], close[2])
bool bullSwitch = bullConfirmed1 or bullConfirmed2
bool bearSwitch = bearConfirmed1 or bearConfirmed2
// Confirmation comes later; offsets place the absorption dot back on the actual rejection wick.
plotshape(showAbsorption and bullConfirmed1 ? low[1] + (high[1] - low[1]) * 0.08 : na, title = "Bullish absorption · 1-bar confirmation", style = shape.circle, location = location.absolute, color = color.new(dotUpInk, dotTransparency), size = size.small, offset = -1, force_overlay = true)
plotshape(showAbsorption and bullConfirmed2 ? low[2] + (high[2] - low[2]) * 0.08 : na, title = "Bullish absorption · 2-bar confirmation", style = shape.circle, location = location.absolute, color = color.new(dotUpInk, dotTransparency), size = size.small, offset = -2, force_overlay = true)
plotshape(showAbsorption and bearConfirmed1 ? high[1] - (high[1] - low[1]) * 0.08 : na, title = "Bearish absorption · 1-bar confirmation", style = shape.circle, location = location.absolute, color = color.new(dotDownInk, dotTransparency), size = size.small, offset = -1, force_overlay = true)
plotshape(showAbsorption and bearConfirmed2 ? high[2] - (high[2] - low[2]) * 0.08 : na, title = "Bearish absorption · 2-bar confirmation", style = shape.circle, location = location.absolute, color = color.new(dotDownInk, dotTransparency), size = size.small, offset = -2, force_overlay = true)
plotshape(showAbsorption and showSwitchBubbles and bubblesEnabled and bullSwitch ? low + (high - low) * 0.15 : na, title = "Confirmed buy switch bubble", style = shape.circle, location = location.absolute, color = color.new(dotUpInk, bubbleTransparency), size = size.large, force_overlay = true)
plotshape(showAbsorption and showSwitchBubbles and bubblesEnabled and bearSwitch ? high - (high - low) * 0.15 : na, title = "Confirmed sell switch bubble", style = shape.circle, location = location.absolute, color = color.new(dotDownInk, bubbleTransparency), size = size.large, force_overlay = true)
// Request the previous completed source-timeframe bar to avoid developing-pivot repainting.
[srResistancePivot, srSupportPivot, srAtr] = request.security(syminfo.tickerid, srTimeframe, [ta.pivothigh(high, srPivotBars, srPivotBars)[1], ta.pivotlow(low, srPivotBars, srPivotBars)[1], ta.atr(14)[1]], lookahead = barmerge.lookahead_on)
var float lastResistance = na
var float lastSupport = na
if not na(srResistancePivot)
lastResistance := srResistancePivot
if not na(srSupportPivot)
lastSupport := srSupportPivot
var SrVisual srSupportVisual = SrVisual.new(na, na, na)
var SrVisual srResistanceVisual = SrVisual.new(na, na, na)
if barstate.islast
bool manual = srMode == "Manual"
float supportPrice = manual ? srManualSupport : lastSupport
float resistancePrice = manual ? srManualResistance : lastResistance
bool validSupport = srMode != "Off" and not na(supportPrice) and supportPrice > 0
bool validResistance = srMode != "Off" and not na(resistancePrice) and resistancePrice > 0
bool chooseSupport = validSupport and (not validResistance or math.abs(close - supportPrice) <= math.abs(close - resistancePrice))
bool drawSupport = validSupport and (srSide == "Both" or srSide == "Support" or srSide == "Nearest" and chooseSupport)
bool drawResistance = validResistance and (srSide == "Both" or srSide == "Resistance" or srSide == "Nearest" and not chooseSupport)
float halfWidth = manual ? srManualWidthTicks * syminfo.mintick : math.max(syminfo.mintick, srAtr * srAtrWidth)
int zoneLeft = math.max(0, bar_index - srBackBars + 1)
int zoneRight = bar_index + rightOffset
string sourceName = manual ? "manual" : srTimeframe
if drawSupport and not na(halfWidth)
f_draw_sr(srSupportVisual, supportPrice, halfWidth, true, zoneLeft, zoneRight, sourceName)
else
f_hide_sr(srSupportVisual)
if drawResistance and not na(halfWidth)
f_draw_sr(srResistanceVisual, resistancePrice, halfWidth, false, zoneLeft, zoneRight, sourceName)
else
f_hide_sr(srResistanceVisual)
var label nearestBounceBadge = na
if barstate.islast and showBounceCount
PocZone nearestZone = na
float nearestDistance = na
int nearestRight = na
if showPrior and array.size(history) > 0
for i = 0 to array.size(history) - 1
PocZone zone = array.get(history, i)
float distance = math.abs(close - zone.centerPrice)
if not na(distance) and (na(nearestDistance) or distance <= nearestDistance)
nearestZone := zone
nearestDistance := distance
nearestRight := (extendPrior ? bar_index : zone.endBar) + rightOffset
if includeDevelopingBounce and showDeveloping and not na(active) and not na(active.centerPrice)
float distance = math.abs(close - active.centerPrice)
if na(nearestDistance) or distance <= nearestDistance
nearestZone := active
nearestDistance := distance
nearestRight := bar_index + rightOffset
if not na(nearestZone)
string bounceText = "bounces " + str.tostring(array.size(nearestZone.bounceTimes)) + " / " + str.tostring(bounceDays) + "d"
if showLabels and not na(nearestZone.caption)
label.set_text(nearestZone.caption, label.get_text(nearestZone.caption) + " · " + bounceText)
else
if na(nearestBounceBadge)
nearestBounceBadge := label.new(nearestRight + 2, nearestZone.centerPrice, "", xloc = xloc.bar_index, yloc = yloc.price, style = label.style_label_left, color = color.new(color.black, 100), textcolor = pocInk, size = size.tiny)
label.set_xy(nearestBounceBadge, nearestRight + 2, nearestZone.centerPrice)
label.set_textcolor(nearestBounceBadge, pocInk)
label.set_text(nearestBounceBadge, bounceText)
PocZone latest = array.size(history) > 0 ? array.get(history, array.size(history) - 1) : na
bool activeTouch = not na(active) and not na(active.lowPrice) and high >= active.lowPrice and low <= active.highPrice
bool priorTouch = not na(latest) and high >= latest.lowPrice and low <= latest.highPrice
alertcondition(alertZoneTouch and barstate.isconfirmed and (activeTouch or priorTouch), "AURORA POC touch", "Price touched an AURORA POC row on {{ticker}}")
alertcondition(alertBubble and bubbleSignal and volumeRatio >= smallCut, "AURORA high-volume bubble", "High relative candle volume on {{ticker}}")
alertcondition(alertAbsorption and showAbsorption and (bullSwitch or bearSwitch), "AURORA reversal proxy", "Confirmed wick rejection and opposite-direction volume switch on {{ticker}}; OHLCV proxy")