本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// =============================================================================
// Squeeze-vs-Crest Disambiguator: a context tool to help you
// read what you see on the chart. Not a signal, not financial advice, and not a
// winner on its own. You always decide.
// =============================================================================
//
// WHAT IT DOES
// When you are looking at a possible TOP (a crest) on the chart, this tool
// helps you tell apart two cases that look alike but tend to resolve in
// opposite ways:
// - "CALM" crest -> volume/volatility NOT exploding: the push is
// fading quietly (the crest has a better chance of
// being a real top).
// - SQUEEZE / blow-off -> volume and/or volatility EXPLODING: often a false
// positive for anyone trying to fade the top, because
// price can keep ripping higher (and stop you out).
// It measures, causally (using only closed past bars), three things:
// vol_ratio = volume[bar] / mean(volume, last N bars)
// atr_expand = ATR(14)[now] / ATR(14)[N bars ago] (is volatility rising?)
// rsi_peak = max(RSI(14), last N bars) (how overbought it was)
//
// HONEST FRAMING (read this, it matters more than the rest)
// - On its own this is NOT enough to make money. It is a context lens, not an
// engine. Recognizing a "calm" crest does not, by itself, give you an edge.
// - The volume filter is a REFINER, not a driver: it can sharpen what you are
// looking at, but it does not create the outcome.
// - False positives go both ways: a "low" volume reading can still be a
// squeeze, and a climax can still mark a real top.
// - No look-ahead: it uses only completed bars up to the current one.
// - Use it as ONE extra input to your own judgement, never as the judgement.
//
// SUGGESTED USE
// When you see a possible top on the chart, glance here: is it "calm" (green,
// low vol_ratio, ATR not running away) or a "squeeze" (red, volume/ATR
// exploding)? Treat it as a single piece of context: the decision and the
// management stay yours.
// =============================================================================
indicator("MHIDa Squeeze-vs-Crest Disambiguator", shorttitle = "SqzCrest", overlay = false)
// ------------------------------- Inputs (defaults = starting points) ---------
volLen = input.int(20, "Volume mean lookback (bars)", minval = 2,
tooltip = "Volume mean used for vol_ratio.")
volCalmMax = input.float(1.7, "CALM volume threshold (vol_ratio <=)", minval = 1.0, step = 0.1,
tooltip = "Heart of the disambiguator. Below this = calm crest (low volume). Above = suspected squeeze/climax. A regulable starting point, not a guaranteed winning value.")
atrLen = input.int(14, "ATR period", minval = 2,
tooltip = "Wilder ATR.")
atrLookback = input.int(10, "Bars back for atr_expand", minval = 1,
tooltip = "atr_expand = ATR[now]/ATR[N bars ago].")
atrCalmMax = input.float(1.4, "CALM ATR threshold (atr_expand <=)", minval = 0.5, step = 0.05,
tooltip = "Above = volatility expanding (suspected squeeze). A regulable starting point.")
rsiLen = input.int(14, "RSI period", minval = 2)
rsiPeakLen = input.int(10, "Bars for rsi_peak (max RSI)", minval = 1,
tooltip = "rsi_peak = max(RSI, last N bars).")
rsiPeakMax = input.float(80.0, "CALM rsi_peak threshold (<=)", minval = 50.0, step = 1.0,
tooltip = "Above = it was very overbought (a more 'hysterical' crest). A regulable starting point.")
// ------------------------------- Calculations (causal) -----------------------
// Volume mean over the last volLen bars, EXCLUDING the current one -> consistent
// with mean(volume over bars i-N .. i-1).
volMeanPrev = ta.sma(volume[1], volLen)
volRatio = na(volMeanPrev) or volMeanPrev <= 0 ? na : volume / volMeanPrev
// ATR expansion: ATR now / ATR atrLookback bars ago.
atrNow = ta.atr(atrLen)
atrPast = atrNow[atrLookback]
atrExpand = na(atrPast) or atrPast <= 0 ? na : atrNow / atrPast
// rsi_peak: highest RSI over the last rsiPeakLen bars.
rsiVal = ta.rsi(close, rsiLen)
rsiPeak = ta.highest(rsiVal, rsiPeakLen)
// ------------------------------- Verdicts ------------------------------------
// "Calm" on each axis: true = quiet (favorable to a real crest for anyone who
// wants to fade it). If a value is missing (na) -> treated as NOT calm (cautious).
volCalm = not na(volRatio) and volRatio <= volCalmMax
atrCalm = not na(atrExpand) and atrExpand <= atrCalmMax
rsiCalm = not na(rsiPeak) and rsiPeak <= rsiPeakMax
// "Calm" score 0..3 (how many axes are quiet).
calmScore = (volCalm ? 1 : 0) + (atrCalm ? 1 : 0) + (rsiCalm ? 1 : 0)
// Summary state:
// CALM CREST = low volume (vol_ratio <= threshold), core filter on,
// and ATR not running away. (green)
// SQUEEZE = volume exploding (vol_ratio > threshold). (red)
// GRAY = calm volume but volatility/overbought do not confirm.
isSqueeze = not na(volRatio) and volRatio > volCalmMax
isCalm = volCalm and atrCalm
// ------------------------------- Plot ----------------------------------------
colVol = na(volRatio) ? color.new(color.gray, 70) :
isSqueeze ? color.new(color.red, 0) :
volCalm and atrCalm ? color.new(color.green, 0) :
color.new(color.gray, 30)
plot(volRatio, "vol_ratio (volume/mean)", color = colVol, style = plot.style_columns)
plot(atrExpand, "atr_expand (ATR now/ATR -N)", color = color.new(color.blue, 30), linewidth = 1)
hline(volCalmMax, "Calm volume threshold", color = color.new(color.red, 0), linestyle = hline.style_dashed)
hline(atrCalmMax, "Calm ATR threshold", color = color.new(color.blue, 40), linestyle = hline.style_dashed)
hline(1.0, "Volume = mean", color = color.new(color.gray, 60), linestyle = hline.style_dotted)
// Small triangle at the top when the disambiguator reads "calm crest" (low volume +
// ATR not running away). It is a HINT, not an order.
plotshape(isCalm and chart.is_standard, style = shape.triangledown, location = location.top,
color = color.new(color.green, 0), size = size.tiny,
title = "Calm crest: low volume + ATR not running away (hint, not a signal)")
// Cross when it is a suspected squeeze (volume exploding).
plotshape(isSqueeze and chart.is_standard, style = shape.xcross, location = location.bottom,
color = color.new(color.red, 0), size = size.tiny,
title = "Suspected squeeze: volume exploding (a typical false positive)")
// ------------------------------- On-screen note ------------------------------
var table note = table.new(position.top_right, 1, 1, border_width = 1)
if barstate.islast
state = isCalm ? "CALM CREST (low volume)" : isSqueeze ? "SQUEEZE suspected (high volume)" : "uncertain"
txt = "MHIDa Squeeze-vs-Crest\n" + state +
"\ncalm " + str.tostring(calmScore) + "/3" +
"\nCONTEXT, not a signal" +
"\nnot a standalone winner" +
"\nyou decide"
bg = isCalm ? color.new(color.green, 25) : isSqueeze ? color.new(color.red, 25) : color.new(color.black, 25)
table.cell(note, 0, 0, txt, text_size = size.small, text_color = color.white, bgcolor = bg)
// ------------------------------- Alerts (still just hints) --------------------
alertcondition(isCalm,
"MHIDa: calm crest (low volume)",
"Possible CALM crest: low volume and ATR not expanding. A hint to put in context on the chart, not a signal.")
alertcondition(isSqueeze,
"MHIDa: suspected squeeze (high volume)",
"Volume exploding: a typical false positive for anyone trying to fade the top. A hint, not an order.")