本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Gabremoku
//@version=6
indicator("Wyckoff Effort vs Result [Gabremoku]", shorttitle="Effort/Result [Gabremoku]", overlay=false, max_labels_count=500, max_lines_count=500, max_boxes_count=500)
// ═══════════════════════════════════════════════════════════════
// Wyckoff Effort vs Result [Gabremoku]
// Volume (effort) vs price range (result) composite oscillator,
// self-calibrating z-score normalization, swing-position
// absorption detection, volume z-score spikes, pivot-based
// divergence engine, dashboard and on-chart explanatory legend.
// Effort-dominant = Purple | Result-dominant = Teal
// ═══════════════════════════════════════════════════════════════
// ── INPUTS ─────────────────────────────────────────────────────
grp0 = "⚙️ Core"
atrLen = input.int(14, "ATR Length (Result Baseline)", minval=1, group=grp0)
volLen = input.int(20, "Volume Average Length (Effort Baseline)", minval=1, group=grp0)
smoothLen = input.int(5, "Effort/Result Smoothing", minval=1, group=grp0)
swingLen = input.int(20, "Swing Range Lookback", minval=2, group=grp0)
grp1 = "📊 Effort/Result Scale"
erZLen = input.int(100, "Z-Score Lookback (Self-Calibration)", minval=20, group=grp1)
scaleFactor = input.float(25.0, "Points per Std Dev", minval=5.0, step=1.0, group=grp1)
climaxThresh = input.float(30.0, "Effort-Dominance Threshold", minval=1.0, step=1.0, group=grp1)
easeThresh = input.float(30.0, "Result-Dominance Threshold", minval=1.0, step=1.0, group=grp1)
grp2 = "📐 Climax Zones"
lowZoneThresh = input.float(0.25, "Swing Low Zone (0-1)", minval=0.0, maxval=0.5, step=0.01, group=grp2)
highZoneThresh = input.float(0.75, "Swing High Zone (0-1)", minval=0.5, maxval=1.0, step=0.01, group=grp2)
strongCloseThresh = input.float(0.60, "Strong Close Threshold (0-1)", minval=0.5, maxval=1.0, step=0.01, group=grp2)
weakCloseThresh = input.float(0.40, "Weak Close Threshold (0-1)", minval=0.0, maxval=0.5, step=0.01, group=grp2)
volZThresh = input.float(2.0, "Volume Climax Z-Score", minval=0.5, step=0.1, group=grp2)
grp3 = "🎨 Colors"
effortColor = input.color(color.rgb(156, 39, 176), "Effort-Dominant Color (Purple)", group=grp3)
easeColor = input.color(color.rgb(0, 150, 136), "Result-Dominant Color (Teal)", group=grp3)
bullColor = input.color(color.rgb(33, 150, 243), "Bullish Absorption Color (Blue)", group=grp3)
bearColor = input.color(color.rgb(255, 109, 0), "Bearish Absorption Color (Orange)", group=grp3)
neutralColor = input.color(color.gray, "Neutral Color", group=grp3)
grp4 = "📐 Style"
showHistogram = input.bool(true, "Show Effort/Result Histogram", group=grp4)
showScoreLine = input.bool(true, "Show Effort/Result Line", group=grp4)
showFill = input.bool(true, "Show Gradient Fill", group=grp4)
showClimaxMarkers = input.bool(true, "Show Absorption Markers on Chart", group=grp4)
showVolClimax = input.bool(true, "Show Raw Volume Climax Markers", group=grp4)
showDashboard = input.bool(true, "Show Dashboard", group=grp4)
showLastLabel = input.bool(true, "Show Last Value Label", group=grp4)
grp5 = "🚦 Divergence"
showDivergence = input.bool(true, "Enable Divergence Labels", group=grp5)
divLB_L = input.int(5, "Pivot Left Bars", minval=1, group=grp5)
divLB_R = input.int(5, "Pivot Right Bars", minval=1, group=grp5)
divMinBars = input.int(5, "Min Bars Between Pivots", minval=1, group=grp5)
divMaxBars = input.int(50, "Max Bars Between Pivots", minval=5, group=grp5)
divMinEffortDrop = input.float(15.0, "Divergence Min Effort Drop (%)", minval=0.0, maxval=90.0, step=1.0, group=grp5, tooltip="A divergence needs the new swing low/high to be made on at least this much less effort (smoothed volume vs its average) than the previous swing.")
grp6 = "🪧 Dashboard"
dashPosInput = input.string("Bottom Right", "Dashboard Position", options=["Top Right", "Top Left", "Bottom Right", "Bottom Left"], group=grp6)
dashTextSizeInput = input.string("Small", "Dashboard Text Size", options=["Tiny", "Small", "Normal"], group=grp6)
grp7 = "📖 Chart Legend"
showLegend = input.bool(true, "Show Explanatory Legend on Main Chart", group=grp7)
legendPosInput = input.string("Bottom Right", "Legend Position", options=["Top Right", "Top Left", "Bottom Right", "Bottom Left"], group=grp7)
legendTextSizeInput = input.string("Tiny", "Legend Text Size", options=["Tiny", "Small", "Normal"], group=grp7)
grp8 = "🏛️ Wyckoff Structure"
showStructure = input.bool(true, "Show Trading Ranges (Accumulation / Distribution)", group=grp8, tooltip="Draws a box over consolidations that are tight compared with the ATR, classed by the move that led into them.")
showEvents = input.bool(true, "Show Events (SC / BC / Spring / UT / SOS / SOW)", group=grp8, tooltip="Spring, UT, SOS and SOW are measured against the trading range, so they (and their alerts) need 'Show Trading Ranges' on.")
rangeLen = input.int(30, "Range Detection Bars", minval=10, group=grp8, tooltip="A window of this many bars is a trading range when its total height is at most 'Max Range Height' times the ATR.")
rangeMaxATR = input.float(7.0, "Max Range Height (x ATR)", minval=2.0, step=0.5, group=grp8)
rangeMaxBars = input.int(150, "Max Range Duration (Bars)", minval=30, group=grp8)
eventCooldown = input.int(5, "Event Cooldown (Bars)", minval=1, group=grp8, tooltip="Spring, upthrust and absorption markers show only the first bar of a cluster: no new marker of the same kind until this many bars have passed since the last raw signal.")
climaxMinRange = input.float(1.2, "Climax Min Bar Range (x ATR)", minval=0.5, step=0.1, group=grp8, tooltip="A selling/buying climax needs a bar at least this wide, on top of the Volume Climax Z-Score.")
dashTextSize = size.small
if dashTextSizeInput == "Tiny"
dashTextSize := size.tiny
else if dashTextSizeInput == "Normal"
dashTextSize := size.normal
legendTextSize = size.tiny
if legendTextSizeInput == "Small"
legendTextSize := size.small
else if legendTextSizeInput == "Normal"
legendTextSize := size.normal
// ── DASHBOARD POSITION ────────────────────────────────────────
dashPos = position.bottom_right
if dashPosInput == "Top Right"
dashPos := position.top_right
else if dashPosInput == "Top Left"
dashPos := position.top_left
else if dashPosInput == "Bottom Left"
dashPos := position.bottom_left
legendPos = position.bottom_right
if legendPosInput == "Top Right"
legendPos := position.top_right
else if legendPosInput == "Top Left"
legendPos := position.top_left
else if legendPosInput == "Bottom Left"
legendPos := position.bottom_left
// ── FUNCTIONS ──────────────────────────────────────────────────
clamp(_x, _min, _max) =>
math.max(_min, math.min(_max, _x))
// ── EFFORT / RESULT ENGINE ────────────────────────────────────
// "Result" = how far price actually traveled this bar, normalized
// against its own ATR baseline. "Effort" = how much volume was
// needed to produce that travel, normalized against its own
// volume average. Neither number means anything on its own — the
// Wyckoff idea is that the SAME range can be cheap or expensive
// depending on what it cost in volume, so the score only exists
// once the two are compared against each other.
//
// The raw log(Effort/Result) is z-scored against its own rolling
// history so "dominance" thresholds are self-calibrating per
// instrument and timeframe instead of relying on a fixed
// multiplier that behaves differently on every symbol.
trueRange = ta.tr(true)
resultBase = ta.atr(atrLen)
resultNorm = resultBase != 0 ? trueRange / resultBase : 1.0
volAvg = ta.sma(volume, volLen)
volStdev = ta.stdev(volume, volLen)
naVolume = na(volume) or volAvg == 0
effortNorm = naVolume ? 1.0 : volume / volAvg
floorVal = 0.05
erRaw = math.log(math.max(effortNorm, floorVal) / math.max(resultNorm, floorVal))
erSmooth = ta.ema(erRaw, smoothLen)
erMean = ta.sma(erSmooth, erZLen)
erStd = ta.stdev(erSmooth, erZLen)
erZ = erStd != 0 ? (erSmooth - erMean) / erStd : 0.0
erScaled = clamp(erZ * scaleFactor, -100.0, 100.0)
volZ = (not naVolume and volStdev != 0) ? (volume - volAvg) / volStdev : 0.0
volClimax = not naVolume and volZ > volZThresh
// ── BAR LOCATION & SWING CONTEXT ───────────────────────────────
barRange = high - low
closeLoc = barRange != 0 ? (close - low) / barRange : 0.5
swingHigh = ta.highest(high, swingLen)
swingLow = ta.lowest(low, swingLen)
swingSpan = swingHigh - swingLow
posInRange = swingSpan != 0 ? (close - swingLow) / swingSpan : 0.5
// ── CLASSIFICATION ─────────────────────────────────────────────
// Without volume data the score only reflects bar range, so no state is classified.
isEffortDominant = not naVolume and erScaled > climaxThresh
isResultDominant = not naVolume and erScaled < -easeThresh
nearSwingLow = posInRange <= lowZoneThresh
nearSwingHigh = posInRange >= highZoneThresh
closedStrong = closeLoc >= strongCloseThresh
closedWeak = closeLoc <= weakCloseThresh
bullishAbsorption = isEffortDominant and nearSwingLow and closedStrong
bearishAbsorption = isEffortDominant and nearSwingHigh and closedWeak
efficientMarkup = isResultDominant and close > open
efficientMarkdown = isResultDominant and close < open
string state = "Balanced"
if bullishAbsorption
state := "Bullish Absorption"
else if bearishAbsorption
state := "Bearish Absorption"
else if efficientMarkup
state := "Efficient Markup"
else if efficientMarkdown
state := "Efficient Markdown"
else if isEffortDominant
state := "Effort Without Result"
else if isResultDominant
state := "Result Without Effort"
color stateColor = neutralColor
if bullishAbsorption
stateColor := bullColor
else if bearishAbsorption
stateColor := bearColor
else if efficientMarkup
stateColor := color.new(bullColor, 35)
else if efficientMarkdown
stateColor := color.new(bearColor, 35)
else if isEffortDominant
stateColor := effortColor
else if isResultDominant
stateColor := easeColor
// ── COLORS ────────────────────────────────────────────────────
erColor =
erScaled >= 0
? color.from_gradient(erScaled, 0, 100, neutralColor, effortColor)
: color.from_gradient(erScaled, -100, 0, easeColor, neutralColor)
histColor = erScaled >= 0 ? color.new(effortColor, 30) : color.new(easeColor, 30)
fillColor = erScaled >= 0 ? color.new(effortColor, 85) : color.new(easeColor, 85)
// ── PLOTS ─────────────────────────────────────────────────────
hline(0, "Zero", color=color.new(#666666, 55))
hline(climaxThresh, "Effort Dominance", color=color.new(effortColor, 70), linestyle=hline.style_dashed)
hline(-easeThresh, "Result Dominance", color=color.new(easeColor, 70), linestyle=hline.style_dashed)
erPlotVal = naVolume ? na : erScaled
histPlot = plot(showHistogram ? erPlotVal : na, "Effort/Result Histogram", style=plot.style_columns, color=histColor)
scorePlot = plot(showScoreLine ? erPlotVal : na, "Effort/Result Score", color=erColor, linewidth=2)
zeroPlot = plot(showFill ? 0 : na, "Zero Fill Anchor", color=color.new(color.black, 100))
fill(scorePlot, zeroPlot, color=showFill ? fillColor : na, title="Effort/Result Fill")
// ── CLIMAX MARKERS ON CHART ────────────────────────────────────
// Only the first bar of an absorption cluster gets a marker (alerts still fire on every bar).
barsSinceAbsBull = nz(ta.barssince(bullishAbsorption[1]), 999)
barsSinceAbsBear = nz(ta.barssince(bearishAbsorption[1]), 999)
absBullFirst = bullishAbsorption and barsSinceAbsBull > eventCooldown
absBearFirst = bearishAbsorption and barsSinceAbsBear > eventCooldown
plotshape(showClimaxMarkers and absBullFirst, title="Bullish Absorption", text="ABS", style=shape.labelup, location=location.belowbar, color=color.new(bullColor, 8), textcolor=color.white, size=size.tiny, force_overlay=true)
plotshape(showClimaxMarkers and absBearFirst, title="Bearish Absorption", text="ABS", style=shape.labeldown, location=location.abovebar, color=color.new(bearColor, 8), textcolor=color.white, size=size.tiny, force_overlay=true)
plotshape(showVolClimax and volClimax, title="Volume Climax", style=shape.diamond, location=location.abovebar, color=color.new(neutralColor, 20), size=size.tiny, force_overlay=true)
// ── DIVERGENCE LOGIC ────────────────────────────────────────────
// Effort divergence on price swings: price makes a new swing low (high)
// but with clearly LESS effort (smoothed volume relative to its average)
// than the previous comparable swing. A new low made on drying-up effort
// suggests supply is exhausted (bullish); a new high made on drying-up
// effort suggests demand is exhausted (bearish). The Effort/Result score
// itself has no direction, so the direction always comes from the price swing.
effortSm = ta.ema(effortNorm, smoothLen)
pivLow = ta.pivotlow(low, divLB_L, divLB_R)
pivHigh = ta.pivothigh(high, divLB_L, divLB_R)
foundPL = not na(pivLow)
foundPH = not na(pivHigh)
// bars between the previous pivot and this one (computed on every bar, never inside a condition)
barsFromPrevPL = ta.barssince(foundPL[1]) + 1
barsFromPrevPH = ta.barssince(foundPH[1]) + 1
prevPivLowPrice = ta.valuewhen(foundPL, low[divLB_R], 1)
prevPivLowEffort = ta.valuewhen(foundPL, effortSm[divLB_R], 1)
prevPivHighPrice = ta.valuewhen(foundPH, high[divLB_R], 1)
prevPivHighEffort = ta.valuewhen(foundPH, effortSm[divLB_R], 1)
effortDropFactor = 1.0 - divMinEffortDrop / 100.0
bullDiv = foundPL and barsFromPrevPL >= divMinBars and barsFromPrevPL <= divMaxBars and low[divLB_R] < prevPivLowPrice and effortSm[divLB_R] < prevPivLowEffort * effortDropFactor
bearDiv = foundPH and barsFromPrevPH >= divMinBars and barsFromPrevPH <= divMaxBars and high[divLB_R] > prevPivHighPrice and effortSm[divLB_R] < prevPivHighEffort * effortDropFactor
if showDivergence and bullDiv
label.new(bar_index - divLB_R, low[divLB_R], "BULL", style=label.style_label_up, color=bullColor, textcolor=color.white, size=size.small, tooltip="Effort divergence: new swing low made on clearly less effort than the previous swing low", force_overlay=true)
if showDivergence and bearDiv
label.new(bar_index - divLB_R, high[divLB_R], "BEAR", style=label.style_label_down, color=bearColor, textcolor=color.white, size=size.small, tooltip="Effort divergence: new swing high made on clearly less effort than the previous swing high", force_overlay=true)
// ── WYCKOFF STRUCTURE (DRAWN ON THE PRICE CHART) ───────────────
// Trading range: a window of rangeLen bars whose total height is small
// compared with the ATR is treated as a Wyckoff trading range. The box is
// classed as Accumulation if price fell into it, Distribution if price
// rose into it. While the range is active:
// - low pierces support but closes back inside = SPRING
// - high pierces resistance but closes back inside = UT (upthrust)
// - close above resistance = SOS (sign of strength)
// - close below support = SOW (sign of weakness), and the range ends.
// Climaxes (SC / BC) are heavy-volume, wide-range bars at the swing extremes.
rangeHigh = ta.highest(high, rangeLen)
rangeLow = ta.lowest(low, rangeLen)
rangeHeightATR = resultBase != 0 ? (rangeHigh - rangeLow) / resultBase : 999.0
tightNow = rangeHeightATR <= rangeMaxATR
var bool rngActive = false
var float rngTop = na
var float rngBot = na
var int rngStart = na
var int rngEndBar = -1000
var int lastSpringBar = -1000
var int lastUTBar = -1000
var string rngType = "None"
var box rngBox = na
var line rngMid = na
var string lastEvent = "None"
bool eventSpring = false
bool eventUT = false
bool eventSOS = false
bool eventSOW = false
if showStructure
if not rngActive
if tightNow and bar_index - rngEndBar > rangeLen and bar_index >= rangeLen * 2
rngActive := true
rngTop := rangeHigh
rngBot := rangeLow
rngStart := bar_index - rangeLen + 1
rngType := close[rangeLen] < close[rangeLen * 2] ? "Accumulation" : close[rangeLen] > close[rangeLen * 2] ? "Distribution" : "Range"
rngCol = rngType == "Accumulation" ? bullColor : rngType == "Distribution" ? bearColor : neutralColor
rngBox := box.new(rngStart, rngTop, bar_index, rngBot, border_color=color.new(rngCol, 15), border_width=1, bgcolor=color.new(rngCol, 90), text=rngType, text_color=color.new(rngCol, 10), text_size=size.small, text_halign=text.align_left, text_valign=text.align_top, force_overlay=true)
rngMid := line.new(rngStart, (rngTop + rngBot) / 2, bar_index, (rngTop + rngBot) / 2, color=color.new(rngCol, 45), style=line.style_dotted, force_overlay=true)
else
box.set_right(rngBox, bar_index)
line.set_x2(rngMid, bar_index)
if close > rngTop
eventSOS := true
else if close < rngBot
eventSOW := true
else if low < rngBot
if bar_index - lastSpringBar > eventCooldown
eventSpring := true
lastSpringBar := bar_index
else if high > rngTop
if bar_index - lastUTBar > eventCooldown
eventUT := true
lastUTBar := bar_index
rngEnds = eventSOS or eventSOW or bar_index - rngStart >= rangeMaxBars
if rngEnds
endCol = eventSOS ? bullColor : eventSOW ? bearColor : neutralColor
// The outcome renames the range: a range entered after an advance that breaks up was
// a re-accumulation, one entered after a decline that breaks down was a re-distribution.
endType = eventSOS and rngType == "Distribution" ? "Re-accumulation" : eventSOW and rngType == "Accumulation" ? "Re-distribution" : rngType
box.set_border_color(rngBox, color.new(endCol, 0))
box.set_border_width(rngBox, 2)
box.set_text(rngBox, endType)
box.set_text_color(rngBox, color.new(endCol, 10))
box.set_bgcolor(rngBox, color.new(endCol, 90))
rngActive := false
rngEndBar := bar_index
// Climaxes: ultra-high volume on a wide bar at the swing extreme
climaxBar = volClimax and resultNorm >= climaxMinRange
rawSC = climaxBar and nearSwingLow and close < open
rawBC = climaxBar and nearSwingHigh and close > open
eventSC = rawSC and nz(ta.barssince(rawSC[1]), 999) > swingLen
eventBC = rawBC and nz(ta.barssince(rawBC[1]), 999) > swingLen
if eventSC
lastEvent := "SC"
else if eventBC
lastEvent := "BC"
else if eventSpring
lastEvent := "Spring"
else if eventUT
lastEvent := "UT"
else if eventSOS
lastEvent := "SOS"
else if eventSOW
lastEvent := "SOW"
if showEvents
if eventSC
label.new(bar_index, low, "SC", style=label.style_label_up, color=bullColor, textcolor=color.white, size=size.small, tooltip="Selling climax: very heavy volume on a wide down bar at the swing low", force_overlay=true)
line.new(bar_index, low, bar_index + rangeLen, low, color=color.new(bullColor, 35), style=line.style_dotted, force_overlay=true)
if eventBC
label.new(bar_index, high, "BC", style=label.style_label_down, color=bearColor, textcolor=color.white, size=size.small, tooltip="Buying climax: very heavy volume on a wide up bar at the swing high", force_overlay=true)
line.new(bar_index, high, bar_index + rangeLen, high, color=color.new(bearColor, 35), style=line.style_dotted, force_overlay=true)
if eventSpring
label.new(bar_index, low, "SPRING", style=label.style_label_up, color=bullColor, textcolor=color.white, size=size.small, tooltip="Low pierced the range support and closed back inside. Effort: " + str.tostring(effortNorm, "0.00") + "x average volume", force_overlay=true)
if eventUT
label.new(bar_index, high, "UT", style=label.style_label_down, color=bearColor, textcolor=color.white, size=size.small, tooltip="Upthrust: high pierced the range resistance and closed back inside. Effort: " + str.tostring(effortNorm, "0.00") + "x average volume", force_overlay=true)
if eventSOS
label.new(bar_index, low, "SOS", style=label.style_label_up, color=bullColor, textcolor=color.white, size=size.small, tooltip="Sign of strength: close above the range resistance", force_overlay=true)
if eventSOW
label.new(bar_index, high, "SOW", style=label.style_label_down, color=bearColor, textcolor=color.white, size=size.small, tooltip="Sign of weakness: close below the range support", force_overlay=true)
// ── DASHBOARD (OSCILLATOR PANE) ──────────────────────────────
var table dash = table.new(dashPos, 2, 9, border_width=1)
if barstate.islast and showDashboard
structureText = rngActive ? rngType + " (" + str.tostring(bar_index - rngStart + 1) + " bars)" : "None"
structureColor = rngActive ? (rngType == "Accumulation" ? bullColor : rngType == "Distribution" ? bearColor : neutralColor) : chart.fg_color
table.cell(dash, 0, 0, "State", text_color=chart.fg_color, text_halign=text.align_left, text_size=dashTextSize)
table.cell(dash, 1, 0, naVolume ? "No Volume Data" : state, text_color=naVolume ? neutralColor : stateColor, text_halign=text.align_center, text_size=dashTextSize)
table.cell(dash, 0, 1, "ER Score", text_color=chart.fg_color, text_halign=text.align_left, text_size=dashTextSize)
table.cell(dash, 1, 1, str.tostring(erScaled, "0.0"), text_color=erColor, text_halign=text.align_center, text_size=dashTextSize)
table.cell(dash, 0, 2, "Effort (Vol)", text_color=chart.fg_color, text_halign=text.align_left, text_size=dashTextSize)
table.cell(dash, 1, 2, naVolume ? "n/a" : str.tostring(effortNorm, "0.00") + "x", text_color=chart.fg_color, text_halign=text.align_center, text_size=dashTextSize)
table.cell(dash, 0, 3, "Result (Range)", text_color=chart.fg_color, text_halign=text.align_left, text_size=dashTextSize)
table.cell(dash, 1, 3, str.tostring(resultNorm, "0.00") + "x", text_color=chart.fg_color, text_halign=text.align_center, text_size=dashTextSize)
table.cell(dash, 0, 4, "Close Location", text_color=chart.fg_color, text_halign=text.align_left, text_size=dashTextSize)
table.cell(dash, 1, 4, str.tostring(closeLoc * 100, "0") + "%", text_color=chart.fg_color, text_halign=text.align_center, text_size=dashTextSize)
table.cell(dash, 0, 5, "Swing Position", text_color=chart.fg_color, text_halign=text.align_left, text_size=dashTextSize)
table.cell(dash, 1, 5, str.tostring(posInRange * 100, "0") + "%", text_color=chart.fg_color, text_halign=text.align_center, text_size=dashTextSize)
table.cell(dash, 0, 6, "Vol Climax", text_color=chart.fg_color, text_halign=text.align_left, text_size=dashTextSize)
table.cell(dash, 1, 6, volClimax ? "Yes" : "No", text_color=volClimax ? neutralColor : chart.fg_color, text_halign=text.align_center, text_size=dashTextSize)
table.cell(dash, 0, 7, "Structure", text_color=chart.fg_color, text_halign=text.align_left, text_size=dashTextSize)
table.cell(dash, 1, 7, structureText, text_color=structureColor, text_halign=text.align_center, text_size=dashTextSize)
table.cell(dash, 0, 8, "Last Event", text_color=chart.fg_color, text_halign=text.align_left, text_size=dashTextSize)
table.cell(dash, 1, 8, lastEvent, text_color=chart.fg_color, text_halign=text.align_center, text_size=dashTextSize)
if barstate.islast and not showDashboard
table.clear(dash, 0, 0, 1, 8)
// ── CHART LEGEND (MAIN PANE, force_overlay) ──────────────────
// Static explanatory table for people who don't know the
// indicator's logic — placed on the price pane even though the
// script itself runs in a separate oscillator pane.
var table legend = table.new(legendPos, 2, 10, border_width=1, force_overlay=true)
if barstate.islast and showLegend
table.cell(legend, 0, 0, "Effort/Result", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize, text_formatting=text.format_bold)
table.cell(legend, 1, 0, "How to read it", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize, text_formatting=text.format_bold)
table.cell(legend, 0, 1, "ABS (blue)", text_color=bullColor, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 1, 1, "Heavy volume, little progress, near a low = possible bullish absorption", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 0, 2, "ABS (orange)", text_color=bearColor, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 1, 2, "Heavy volume, little progress, near a high = possible bearish absorption", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 0, 3, "◆ Diamond", text_color=neutralColor, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 1, 3, "Volume climax: this bar's volume is a statistical outlier", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 0, 4, "BULL / BEAR", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 1, 4, "Effort divergence: new swing low/high made on clearly less volume than the previous one", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 0, 5, "Purple / Teal", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 1, 5, "Oscillator color: effort-dominant (purple) vs result-dominant (teal)", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 0, 6, "Box", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 1, 6, "Trading range: blue = accumulation (price fell into it), orange = distribution (price rose into it). When it ends the outcome renames it: Re-accumulation / Re-distribution", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 0, 7, "SC / BC", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 1, 7, "Selling / buying climax: very heavy volume on a wide bar at the swing extreme", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 0, 8, "SPRING / UT", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 1, 8, "Range support / resistance pierced, then price closes back inside the range", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 0, 9, "SOS / SOW", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
table.cell(legend, 1, 9, "Sign of strength / weakness: close above resistance / below support, the range ends", text_color=chart.fg_color, text_halign=text.align_left, text_size=legendTextSize)
if barstate.islast and not showLegend
table.clear(legend, 0, 0, 1, 9)
// ── LAST VALUE LABEL ───────────────────────────────────────────
if barstate.islast and showLastLabel
label.delete(label.new(
bar_index, erScaled,
"◀ ER: " + str.tostring(erScaled, "0.0") + " | " + state,
color=color.new(color.black, 100),
textcolor=erColor,
style=label.style_label_left
)[1])
// ── ALERTS ────────────────────────────────────────────────────
alertcondition(bullishAbsorption, title="Bullish Absorption", message="Wyckoff Effort vs Result: bullish absorption detected on {{ticker}}")
alertcondition(bearishAbsorption, title="Bearish Absorption", message="Wyckoff Effort vs Result: bearish absorption detected on {{ticker}}")
alertcondition(volClimax, title="Volume Climax", message="Wyckoff Effort vs Result: volume climax on {{ticker}}")
alertcondition(bullDiv, title="Bullish Effort Divergence", message="Wyckoff Effort vs Result: bullish effort divergence on {{ticker}}")
alertcondition(bearDiv, title="Bearish Effort Divergence", message="Wyckoff Effort vs Result: bearish effort divergence on {{ticker}}")
alertcondition(eventSC, title="Selling Climax", message="Wyckoff Effort vs Result: selling climax on {{ticker}}")
alertcondition(eventBC, title="Buying Climax", message="Wyckoff Effort vs Result: buying climax on {{ticker}}")
alertcondition(eventSpring, title="Spring", message="Wyckoff Effort vs Result: spring on {{ticker}}")
alertcondition(eventUT, title="Upthrust", message="Wyckoff Effort vs Result: upthrust on {{ticker}}")
alertcondition(eventSOS, title="Sign of Strength", message="Wyckoff Effort vs Result: sign of strength (range breakout) on {{ticker}}")
alertcondition(eventSOW, title="Sign of Weakness", message="Wyckoff Effort vs Result: sign of weakness (range breakdown) on {{ticker}}")