本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) Bitpunk
//@version=6
indicator("Squeeze Breakout Signals [bitpunk]", shorttitle="bitpunk.squeeze-breakout", overlay=true, max_boxes_count=16, max_lines_count=4)
// Independent public implementation. See research/design.md for definitions and sources.
// Compression setup and entry window use this chart's completed candles.
int length = input.int(20, "Compression Length", minval=5, maxval=200, tooltip="Lookback for close dispersion and mean true range. Compression means the two-standard-deviation band fits inside a 1.5-times-mean-TR channel. A shorter lookback responds faster but changes the episodes.", display=display.none)
int minimumBars = input.int(3, "Minimum Compression", minval=2, maxval=20, tooltip="Consecutive compressed closes before breakouts become eligible. A forming box appears earlier. Developing geometry uses at most Compression Length recent compressed candles; the event candle cannot expand its own edge. A fresh episode requires this many noncompressed closes. A mature overlapping run shares the old watch; only a disjoint range replaces it.", display=display.none)
int validityBars = input.int(20, "Range Watch (bars)", minval=1, maxval=200, tooltip="Completed candles from the first close escape or width release, including that starting candle. Twenty allows ages 0–19 for breakout and retest observations. Contacts and width flickers never renew it. A mature disjoint compression replaces it; overlapping ranges share its clock and entry allowance. Longer watches admit later events but retain older structure.", display=display.none)
float maxExtension = input.float(0.0, "Max Entry Extension (TR)", minval=0, maxval=3, step=0.1, tooltip="Zero accepts the owning first close breakout and its held retest inside the watch. Opposite escapes remain context. A positive value limits entry-label/entry-alert distance from the frozen edge, in prior mean TR. Overextended events still appear as context and event readouts. A later nearby close is not a new breakout; a distinct retest can qualify.", display=display.none)
float retestTolerance = input.float(0.25, "Retest Tolerance (TR)", minval=0, maxval=2, step=0.05, tooltip="A later candle must intersect the frozen edge ± this many frozen mean TR. A close back outside confirms the retest, on contact or a later candle. Zero requires an exact edge touch/sweep. Closing at/through the opposite edge invalidates that pending retest. Before returning, a completed candle must clear the entire pocket. The first close breakout owns the direction: at most one breakout and one retest entry per box.", display=display.none)
// Display and theme
bool entryFilter = input.bool(true, "Retest Close Progress", group="Signals", tooltip="For a held retest, require the close to advance beyond the preceding close in its direction. Breakouts are unchanged; some early pullback holds can be missed. Disable to restore original entries. Recreate saved alerts after changing.", display=display.none)
bool enableSignals = input.bool(true, "Enable Signals", group="Signals", tooltip="Enable entry markers and signal alerts. Disabling keeps structure, setup state and context readings active. Recreate existing alerts after changing this setting.", display=display.none)
bool showStructure = input.bool(true, "Structure", group="Display", tooltip="Show the current setup and its exact price boundaries. Hiding it does not change entries or alerts.", display=display.none)
bool showContext = input.bool(true, "Breakout Context", group="Display", tooltip="Quiet edge dots show first wick probes and excluded/opposite close breakouts. Edge diamonds show held retests without a white entry label. These context marks are distinct from the white ▲/▼ entry labels. Hiding them never changes calculations or alerts.", display=display.none)
int historyCount = input.int(6, "Previous Structures", minval=0, maxval=12, group="Display", tooltip="Number of completed boxes to retain quietly. Zero keeps only the current opportunity. This setting does not limit historical entry marks.", display=display.none)
string panelChoice = input.string("bottom", "Status Panel", options=["none", "bottom", "top", "bottom-left", "top-left"], group="Display", tooltip="Shows the latest confirmed setup state. None hides only the panel.", display=display.none)
string panelSize = input.string("small", "Panel Size", options=["small", "medium", "large"], group="Display", tooltip="Shared card scale: small, medium or large. Bottom and top use the right corners; left variants use the left corners.", display=display.none)
string structureEffects = input.string("Enhanced", "Structure Effects", options=["Normal", "Enhanced"], group="Display", tooltip="Exact 2px prepared/locked edges stay clear in both modes. Enhanced adds edge-to-center glass and optional dashed entry-limit guides. Dotted boxes develop; solid boxes are locked. Appearance never changes events or entries.", display=display.none)
string signalEffects = input.string("Enhanced", "Signal Effects", options=["Normal", "Enhanced"], group="Display", tooltip="Normal uses compact ▲/▼ entry labels. Enhanced adds larger labels and a pin with a soft glow at the confirmed close. Appearance does not change signals.", display=display.none)
color bullColor = input.color(color.rgb(0, 194, 255), "Bull", inline="theme", group="Theme Colors", display=display.none, tooltip="Long-side colors. All directional effects derive from Bull and Bear and adapt to the chart background.")
color bearColor = input.color(color.rgb(255, 56, 100), "Bear", inline="theme", group="Theme Colors", display=display.none, tooltip="Short-side colors. All directional effects derive from Bull and Bear and adapt to the chart background.")
// Public visual conventions: Pullback Reclaim and script-visual-style.md.
// Public presentation helpers: opaque primary ink and readable white glyphs.
f_v_linear(float channel) =>
float unit = channel / 255.0
unit <= 0.04045 ? unit / 12.92 : math.pow((unit + 0.055) / 1.055, 2.4)
f_v_luminance(color value) =>
0.2126 * f_v_linear(color.r(value)) + 0.7152 * f_v_linear(color.g(value)) + 0.0722 * f_v_linear(color.b(value))
f_v_contrast(color first, color second) =>
float a = f_v_luminance(first)
float b = f_v_luminance(second)
(math.max(a, b) + 0.05) / (math.min(a, b) + 0.05)
f_v_ink(color source) =>
color result = color.rgb(color.r(source), color.g(source), color.b(source))
bool lightBackground = f_v_luminance(chart.bg_color) > 0.179
for step = 0 to 15
if f_v_contrast(result, chart.bg_color) < 3.2
result := lightBackground ? color.rgb(math.floor(color.r(result) * 0.8), math.floor(color.g(result) * 0.8), math.floor(color.b(result) * 0.8)) : color.rgb(math.ceil(color.r(result) + (255 - color.r(result)) * 0.2), math.ceil(color.g(result) + (255 - color.g(result)) * 0.2), math.ceil(color.b(result) + (255 - color.b(result)) * 0.2))
result
f_v_label(color source) =>
color result = color.rgb(color.r(source), color.g(source), color.b(source))
for step = 0 to 15
if f_v_luminance(result) > 0.175
result := color.rgb(math.floor(color.r(result) * 0.9), math.floor(color.g(result) * 0.9), math.floor(color.b(result) * 0.9))
result
var color f_vBullInk = f_v_ink(bullColor)
var color f_vBearInk = f_v_ink(bearColor)
var color f_vBullLabel = f_v_label(bullColor)
var color f_vBearLabel = f_v_label(bearColor)
f_panel_position(string choice) =>
switch choice
"top" => position.top_right
"top-left" => position.top_left
"bottom-left" => position.bottom_left
=> position.bottom_right
f_dim(color source, float strength) =>
color.from_gradient(strength, 0, 1, chart.bg_color, source)
f_ink(color source) =>
f_v_ink(source)
f_signal(color source) =>
f_v_label(source)
f_tf() =>
float seconds = timeframe.isticks ? na : timeframe.in_seconds()
seconds < 60 ? str.tostring(seconds) + "s" : seconds < 3600 ? str.tostring(seconds / 60) + "m" : seconds < 86400 ? str.tostring(seconds / 3600) + "h" : timeframe.period == "D" ? "1D" : timeframe.period == "W" ? "1W" : timeframe.period == "M" ? "1M" : timeframe.period
var color neutralColor = chart.fg_color
var color bullInk = f_ink(bullColor)
var color bearInk = f_ink(bearColor)
var color bullSignal = f_signal(bullColor)
var color bearSignal = f_signal(bearColor)
f_archive(box drawing, int side, array<box> history, int keep) =>
if not na(drawing)
color accent = side > 0 ? bullColor : side < 0 ? bearColor : neutralColor
box.set_bgcolor(drawing, color.new(accent, 98))
box.set_border_color(drawing, color.new(f_ink(accent), 88))
array.push(history, drawing)
if array.size(history) > keep
box.delete(array.shift(history))
0
// Formula layer: same-center BB/KC width, not a historical-volatility percentile.
float deviation = ta.stdev(close, length, true)
float scale = ta.sma(ta.tr(true), length)
float recentHigh = ta.highest(high, length)
float recentLow = ta.lowest(low, length)
bool supported = chart.is_standard and not timeframe.isticks and not na(time_close)
bool pricesReady = not na(high) and not na(low) and not na(close) and high >= low and close >= low and close <= high
bool dataReady = supported and not na(deviation) and not na(scale) and scale > 0 and pricesReady
bool compressed = dataReady and 2.0 * deviation < 1.5 * scale
f_distance(float price, float referencePrice, float referenceScale) =>
(price - referencePrice) / referenceScale
// Event identity is independent of display and optional entry proximity.
type RangeStudy
int count = 0
int episode = 0
int outsideCount = 0
bool canStart = true
float runHigh = na
float runLow = na
int runStart = na
bool used = false
bool runUpperProbe = false
bool runLowerProbe = false
bool watching = false
int watchEpisode = na
float rangeHigh = na
float rangeLow = na
float frozenScale = na
int started = na
int startTime = na
int opportunityTime = na
bool upperBroken = false
bool lowerBroken = false
int ownerSide = 0
bool departed = false
bool failed = false
bool upperProbed = false
bool lowerProbed = false
int retestSide = 0
int breakAt = na
bool touched = false
int breakout = 0
int retest = 0
int signal = 0
int kind = 0
bool probeUpper = false
bool probeLower = false
bool replaced = false
bool expired = false
float eventUpper = na
float eventLower = na
float eventScale = na
float eventEdge = na
float distance = na
string status = "Warming up"
method clearWatch(RangeStudy this) =>
this.watching := false
this.watchEpisode := na
this.retestSide := 0
this.breakAt := na
this.touched := false
this.departed := false
this.failed := false
0
method lock(RangeStudy this, float priorScale) =>
this.used := true
if not na(priorScale) and priorScale > 0
this.watching := true
this.watchEpisode := this.episode
this.rangeHigh := this.runHigh
this.rangeLow := this.runLow
this.frozenScale := priorScale
this.started := bar_index
this.startTime := this.runStart
this.opportunityTime := time
this.upperBroken := false
this.lowerBroken := false
this.ownerSide := 0
this.departed := false
this.failed := false
this.upperProbed := this.runUpperProbe
this.lowerProbed := this.runLowerProbe
this.retestSide := 0
this.breakAt := na
this.touched := false
0
method observe(RangeStudy this) =>
this.eventUpper := this.rangeHigh
this.eventLower := this.rangeLow
this.eventScale := this.frozenScale
if high > this.rangeHigh and not this.upperProbed
this.probeUpper := true
this.upperProbed := true
if low < this.rangeLow and not this.lowerProbed
this.probeLower := true
this.lowerProbed := true
int side = close > this.rangeHigh ? 1 : close < this.rangeLow ? -1 : 0
bool firstBreak = side > 0 ? not this.upperBroken : side < 0 ? not this.lowerBroken : false
if firstBreak
this.breakout := side
this.upperBroken := this.upperBroken or side > 0
this.lowerBroken := this.lowerBroken or side < 0
if this.ownerSide == 0
this.ownerSide := side
this.retestSide := side
this.breakAt := bar_index
this.touched := false
float pocket = retestTolerance * this.frozenScale
this.departed := side > 0 ? low > this.rangeHigh + pocket : high < this.rangeLow - pocket
if this.retestSide != 0 and bar_index > this.breakAt
int direction = this.retestSide
float edge = direction > 0 ? this.rangeHigh : this.rangeLow
float opposite = direction > 0 ? this.rangeLow : this.rangeHigh
if direction * f_distance(close, opposite, this.frozenScale) <= 0
this.retestSide := 0
this.touched := false
this.failed := true
else
float pocket = retestTolerance * this.frozenScale
if this.departed
this.touched := this.touched or (low <= edge + pocket and high >= edge - pocket)
if this.touched and direction * f_distance(close, edge, this.frozenScale) > 0
this.retest := direction
this.retestSide := 0
this.touched := false
else if (direction > 0 ? low > edge + pocket : high < edge - pocket)
this.departed := true
int eventSide = this.retest != 0 ? this.retest : this.breakout
if eventSide != 0
this.eventEdge := eventSide > 0 ? this.rangeHigh : this.rangeLow
this.distance := eventSide * f_distance(close, this.eventEdge, this.frozenScale)
bool withinCap = maxExtension == 0 or this.distance <= maxExtension
if eventSide == this.ownerSide and withinCap
this.signal := eventSide
this.kind := this.retest != 0 ? 2 : 1
0
method step(RangeStudy this, float priorScale) =>
this.breakout := 0
this.retest := 0
this.signal := 0
this.kind := 0
this.probeUpper := false
this.probeLower := false
this.replaced := false
this.expired := false
this.eventUpper := na
this.eventLower := na
this.eventScale := na
this.eventEdge := na
this.distance := na
if not dataReady
this.clearWatch()
this.count := 0
this.outsideCount := 0
this.canStart := true
this.used := false
this.runHigh := na
this.runLow := na
this.runStart := na
this.status := supported ? "Warming up" : "Standard time chart required"
else
bool hadWatch = this.watching
if this.watching and bar_index - this.started >= validityBars
this.clearWatch()
this.expired := true
// Check old geometry before a mature new run can replace it.
if this.watching
this.observe()
if compressed
if this.count == 0
if this.canStart
this.episode += 1
this.used := false
this.runUpperProbe := false
this.runLowerProbe := false
this.runHigh := high
this.runLow := low
this.runStart := time
this.canStart := false
this.outsideCount := 0
bool priorPrepared = this.count >= minimumBars and not this.used and this.runHigh > this.runLow
if priorPrepared and not hadWatch
int earlySide = close > this.runHigh ? 1 : close < this.runLow ? -1 : 0
if earlySide != 0
this.lock(priorScale)
if this.watching
this.observe()
else
this.eventUpper := this.runHigh
this.eventLower := this.runLow
this.eventScale := priorScale
if high > this.runHigh and not this.runUpperProbe
this.probeUpper := true
this.runUpperProbe := true
if low < this.runLow and not this.runLowerProbe
this.probeLower := true
this.runLowerProbe := true
this.count += 1
if not this.used
this.runHigh := this.count >= length ? recentHigh : math.max(this.runHigh, high)
this.runLow := this.count >= length ? recentLow : math.min(this.runLow, low)
this.runStart := this.count >= length ? time[length - 1] : this.runStart
if this.watching and this.watchEpisode != this.episode and this.count >= minimumBars and this.runHigh > this.runLow
bool overlaps = this.runLow <= this.rangeHigh and this.runHigh >= this.rangeLow
if overlaps
// Same price area shares the old geometry, deadline and entry allowance.
this.used := true
else
this.clearWatch()
this.replaced := true
if not this.watching
this.rangeHigh := this.runHigh
this.rangeLow := this.runLow
this.startTime := this.runStart
else
if this.count >= minimumBars and not this.used and not this.watching and this.runHigh > this.runLow
this.lock(priorScale)
if this.watching
this.observe()
this.count := 0
this.outsideCount += 1
if this.outsideCount >= minimumBars
this.canStart := true
int eventSide = this.retest != 0 ? this.retest : this.breakout
if eventSide != 0
this.status := eventSide != this.ownerSide ? "Range failed · opposite break" : (eventSide > 0 ? "Long" : "Short") + (this.retest != 0 ? " retest" : " breakout") + (this.signal != 0 ? "" : " · extended")
else if this.watching
this.status := this.failed ? "Range failed · watch" : this.retestSide != 0 ? (this.retestSide > 0 ? "Long" : "Short") + (this.touched ? " · reclaim pending" : this.departed ? " · retest pending" : " · departure pending") : "Range watch"
else if this.count > 0 and not this.used
this.status := this.count >= minimumBars ? "Ready · compressed" : "Compressing"
else
this.status := this.expired ? "Expired" : this.count > 0 ? "Compression observed" : "Waiting for compression"
0
var RangeStudy study = RangeStudy.new()
if barstate.isconfirmed
study.step(scale[1])
bool entryPass = not entryFilter or (study.kind != 2 or (not na(close[1]) and study.signal * (close - close[1]) > 0))
var bool lastEntryFiltered = false
if barstate.isconfirmed
lastEntryFiltered := study.signal != 0 and not entryPass
bool longSignal = barstate.isconfirmed and study.signal == 1 and entryPass
bool shortSignal = barstate.isconfirmed and study.signal == -1 and entryPass
int breakoutSide = barstate.isconfirmed ? study.breakout : 0
int retestSide = barstate.isconfirmed ? study.retest : 0
bool probeUpper = barstate.isconfirmed and study.probeUpper
bool probeLower = barstate.isconfirmed and study.probeLower
bool eventNow = breakoutSide != 0 or retestSide != 0 or probeUpper or probeLower
bool forming = study.count > 0 and not study.used
bool prepared = forming and study.count >= minimumBars
bool setupVisible = forming or study.watching or eventNow
float referenceUpper = eventNow ? study.eventUpper : study.rangeHigh
float referenceLower = eventNow ? study.eventLower : study.rangeLow
float referenceScale = eventNow ? study.eventScale : study.watching ? study.frozenScale : (barstate.isconfirmed ? scale : scale[1])
// Bounded objects are an observer; none of these controls enters the engine.
var box activeBox = na
var array<box> history = array.new<box>()
var line upperLimit = na
var line lowerLimit = na
if barstate.isconfirmed
if study.replaced or study.expired
if study.replaced and not na(activeBox)
box.set_right(activeBox, time_close)
f_archive(activeBox, study.signal, history, historyCount)
activeBox := na
if showStructure and (forming or study.watching)
if na(activeBox)
activeBox := box.new(study.startTime, study.rangeHigh, time_close, study.rangeLow, xloc=xloc.bar_time, border_color=color.new(neutralColor, 82), bgcolor=color.new(neutralColor, 100))
box.set_left(activeBox, study.startTime)
box.set_top(activeBox, study.rangeHigh)
box.set_bottom(activeBox, study.rangeLow)
box.set_right(activeBox, time_close)
box.set_border_style(activeBox, study.watching ? line.style_solid : line.style_dotted)
else if not na(activeBox)
f_archive(activeBox, 0, history, historyCount)
activeBox := na
bool showLimits = showStructure and structureEffects == "Enhanced" and study.watching and maxExtension > 0
if showLimits
if na(upperLimit)
upperLimit := line.new(study.opportunityTime, study.rangeHigh + maxExtension * study.frozenScale, time_close, study.rangeHigh + maxExtension * study.frozenScale, xloc=xloc.bar_time, color=color.new(bullInk, 68), style=line.style_dashed)
lowerLimit := line.new(study.opportunityTime, study.rangeLow - maxExtension * study.frozenScale, time_close, study.rangeLow - maxExtension * study.frozenScale, xloc=xloc.bar_time, color=color.new(bearInk, 68), style=line.style_dashed)
line.set_xy1(upperLimit, study.opportunityTime, study.rangeHigh + maxExtension * study.frozenScale)
line.set_xy2(upperLimit, time_close, study.rangeHigh + maxExtension * study.frozenScale)
line.set_xy1(lowerLimit, study.opportunityTime, study.rangeLow - maxExtension * study.frozenScale)
line.set_xy2(lowerLimit, time_close, study.rangeLow - maxExtension * study.frozenScale)
else if not na(upperLimit)
line.delete(upperLimit)
line.delete(lowerLimit)
upperLimit := na
lowerLimit := na
// Causal price series retain exact edges; break between different range identities.
bool visible = showStructure and (prepared or study.watching) and not study.replaced
float upper = visible ? study.rangeHigh : na
float lower = visible ? study.rangeLow : na
upperPlot = plot(upper, "Upper Edge", color.new(bullInk, 0), 2, plot.style_linebr, display=display.pane)
lowerPlot = plot(lower, "Lower Edge", color.new(bearInk, 0), 2, plot.style_linebr, display=display.pane)
float midpoint = (upper + lower) / 2
centerMask = plot(midpoint, "Range Glass Center", color=na, display=display.none, editable=false)
color upperGlass = color.new(bullInk, structureEffects == "Enhanced" ? (study.watching ? 94 : 97) : 98)
color lowerGlass = color.new(bearInk, structureEffects == "Enhanced" ? (study.watching ? 94 : 97) : 98)
fill(upperPlot, centerMask, upper, midpoint, upperGlass, color.new(bullInk, 100), title="Upper Range Glass", fillgaps=false)
fill(centerMask, lowerPlot, midpoint, lower, color.new(bearInk, 100), lowerGlass, title="Lower Range Glass", fillgaps=false)
plot(setupVisible ? referenceUpper : na, "Exact Upper", display=display.data_window)
plot(setupVisible ? referenceLower : na, "Exact Lower", display=display.data_window)
float widthRatio = dataReady ? 2.0 * deviation / (1.5 * scale) : na
float confirmedRatio = barstate.isconfirmed ? widthRatio : widthRatio[1]
plot(confirmedRatio, "Compression Width Ratio", display=display.data_window)
plot(setupVisible and maxExtension > 0 ? referenceUpper + maxExtension * referenceScale : na, "Long Entry Limit", display=display.data_window)
plot(setupVisible and maxExtension > 0 ? referenceLower - maxExtension * referenceScale : na, "Short Entry Limit", display=display.data_window)
int setupPhase = longSignal or shortSignal ? 5 : retestSide != 0 ? 6 : study.watching and study.failed ? 7 : study.watching ? (study.retestSide != 0 ? 4 : 3) : prepared ? 2 : forming ? 1 : 0
plot(setupPhase, "Setup Phase", display=display.data_window)
int futureCloses = study.watching ? math.max(0, validityBars - ((barstate.isconfirmed ? bar_index : bar_index - 1) - study.started) - 1) : na
plot(futureCloses, "Eligible Future Closes", display=display.data_window)
plot(breakoutSide, "Breakout Side", display=display.data_window)
plot(retestSide, "Retest Side", display=display.data_window)
plot(probeUpper and probeLower ? 2 : probeUpper ? 1 : probeLower ? -1 : 0, "Probe Side (2=both)", display=display.data_window)
plot(longSignal or shortSignal ? study.kind : 0, "Entry Kind (1=break, 2=retest)", display=display.data_window)
plot(eventNow ? study.eventEdge : na, "Event Edge", display=display.data_window)
plot(eventNow ? study.distance : na, "Event Distance (TR)", display=display.data_window)
plot(setupVisible ? referenceScale : na, "Reference Mean TR", display=display.data_window)
// Fixed sizes keep plotshape parameters const; display switches are cosmetic.
bool enhancedSignal = signalEffects == "Enhanced"
color entryAccent = longSignal ? bullColor : bearColor
color entryInk = longSignal ? bullInk : bearInk
plotshape(enableSignals and (enhancedSignal and (longSignal or shortSignal)) ? close : na, "Entry Glow", shape.circle, location.absolute, color.new(entryAccent, 80), size=size.large, display=display.pane)
plotshape(enableSignals and (enhancedSignal and (longSignal or shortSignal)) ? close : na, "Entry Close Pin", shape.circle, location.absolute, entryInk, size=size.tiny, display=display.pane)
plotshape(enableSignals and (enhancedSignal and longSignal), "Long Entry", shape.labelup, location.belowbar, bullSignal, text="▲", textcolor=color.white, size=size.small, display=display.pane)
plotshape(enableSignals and (not enhancedSignal and longSignal), "Long Normal", shape.labelup, location.belowbar, bullSignal, text="▲", textcolor=color.white, size=size.tiny, display=display.pane)
plotshape(enableSignals and (enhancedSignal and shortSignal), "Short Entry", shape.labeldown, location.abovebar, bearSignal, text="▼", textcolor=color.white, size=size.small, display=display.pane)
plotshape(enableSignals and (not enhancedSignal and shortSignal), "Short Normal", shape.labeldown, location.abovebar, bearSignal, text="▼", textcolor=color.white, size=size.tiny, display=display.pane)
plotshape(showContext and (probeUpper or breakoutSide == 1) and not longSignal ? referenceUpper : na, "Upper Probe / Observed Break", shape.circle, location.absolute, color.new(bullInk, 25), size=size.tiny, display=display.pane)
plotshape(showContext and (probeLower or breakoutSide == -1) and not shortSignal ? referenceLower : na, "Lower Probe / Observed Break", shape.circle, location.absolute, color.new(bearInk, 25), size=size.tiny, display=display.pane)
plotshape(showContext and retestSide == 1 and not longSignal ? study.eventEdge : na, "Long Held Retest", shape.diamond, location.absolute, bullInk, size=size.tiny, display=display.pane)
plotshape(showContext and retestSide == -1 and not shortSignal ? study.eventEdge : na, "Short Held Retest", shape.diamond, location.absolute, bearInk, size=size.tiny, display=display.pane)
plot(enableSignals and (longSignal) ? close : na, "Long Entry Close", display=display.data_window)
plot(enableSignals and (shortSignal) ? close : na, "Short Entry Close", display=display.data_window)
// Choose entry conditions/Any alert() OR an observed-event route deliberately.
alertcondition(enableSignals and (longSignal), "Long Entry", "{{interval}} ▲ LONG @{{close}}")
alertcondition(enableSignals and (shortSignal), "Short Entry", "{{interval}} ▼ SHORT @{{close}}")
alertcondition(enableSignals and (breakoutSide != 0), "Breakout Observed", "{{ticker}} {{interval}} compression close breakout @{{close}}; inspect direction and proximity")
alertcondition(enableSignals and (retestSide != 0), "Retest Observed", "{{ticker}} {{interval}} compression held retest @{{close}}; inspect direction and proximity")
if enableSignals and barstate.isrealtime and barstate.isconfirmed and (longSignal or shortSignal)
alert(f_tf() + (longSignal ? " ▲ LONG @" : " ▼ SHORT @") + str.tostring(close, format.mintick) + (study.kind == 2 ? " · RETEST" : " · BREAKOUT"), alert.freq_once_per_bar_close)
var table panel = na
if barstate.islast
if panelChoice == "none"
if not na(panel)
table.delete(panel)
panel := na
else
if na(panel)
panel := table.new(position.bottom_right, 1, 3, bgcolor=f_dim(chart.fg_color, 0.025), frame_color=f_dim(chart.fg_color, 0.12), frame_width=1, border_width=0)
table.set_position(panel, f_panel_position(panelChoice))
string panelTextSize = panelSize == "small" ? size.tiny : panelSize == "large" ? size.normal : size.small
string panelHeadingSize = panelSize == "small" ? size.small : panelSize == "large" ? size.large : size.normal
color panelAccent = str.startswith(study.status, "Long") ? bullColor : str.startswith(study.status, "Short") ? bearColor : neutralColor
table.cell(panel, 0, 0, " SQUEEZE BREAKOUT · " + f_tf() + " ", bgcolor=f_dim(panelAccent, 0.06), text_color=f_ink(panelAccent), text_size=panelHeadingSize, text_halign=text.align_left)
table.cell(panel, 0, 1, " " + study.status + (lastEntryFiltered ? " · filtered" : "") + " ", text_color=chart.fg_color, text_size=panelTextSize, text_halign=text.align_left)
string detail = study.watching ? str.tostring(futureCloses) + " future closes · " + (maxExtension == 0 ? "cap off" : "cap " + str.tostring(maxExtension, "#.0") + " TR") : (forming ? str.tostring(math.min(study.count, length)) + " range bars · " : "") + "Width " + (na(confirmedRatio) ? "n/a" : str.tostring(confirmedRatio, "#.00"))
table.cell(panel, 0, 2, " " + detail + " ", text_color=f_dim(chart.fg_color, 0.64), text_size=panelTextSize, text_halign=text.align_left)