MHIDa Crest Blow-Off Detector

MHIDa · study · 151 行 · 点赞 2 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
// =============================================================================
// Crest Blow-Off Detector
// A context aid for what you observe on the chart - not a signal and not advice.
// It is NOT a winner on its own: it serves to HIGHLIGHT when price has stretched
// EXTREMELY far above its moving average (a parabolic blow-off) and the upward
// acceleration starts to die. You always decide.
// =============================================================================
//
// WHAT IT OBSERVES (all causal, only already-closed bars):
//   1) EXTREME STRETCH: the highest close of the last few bars sits well above
//      the EMA20 average. Measure = max(close[last N]) / EMA20 - 1.
//      Above a threshold (default 8%) we call it a "blow-off stretch".
//   2) DYING ACCELERATION (decel): the recent rise slows down versus the prior
//      rise. It compares (close-close[3]) against (close[3]-close[6]).
//      When the second push is weaker than the first, the parabola loses thrust.
//   3) OPTIONAL CONTEXT: volume climax at the peak, percentage run-up, distance
//      from the long EMA (200). These help you gauge HOW stretched it is.
//
//   A bar is highlighted when the stretch exceeds the threshold AND (if
//   requested) the acceleration is already slowing.
//
// HONEST NOTE: the default values are a STARTING POINT, not a tuned config.
// They are free inputs: change them and study what happens on your own chart.
// No performance or success rate is claimed or implied.
// =============================================================================
 
indicator("MHIDa Crest Blow-Off Detector", shorttitle="BlowOff", overlay=true)
 
// ----------------------------------------------------------------------------
// CONFIGURABLE INPUTS (defaults = educational starting point)
// ----------------------------------------------------------------------------
emaLen      = input.int(20,    "Short EMA length (average)",   minval=2, group="Stretch",
     tooltip="The moving average we measure the stretch against.")
stretchWin  = input.int(5,     "Peak window for stretch (bars)", minval=1, group="Stretch",
     tooltip="How many bars back to look for the highest close.")
stretchPct  = input.float(8.0, "Stretch threshold % above the average", minval=0.1, step=0.1, group="Stretch",
     tooltip="Above this % distance of the highest close from the EMA we call it a blow-off.")
 
reqDecel    = input.bool(true, "Require slowing acceleration", group="Acceleration",
     tooltip="If on, highlight only when the recent rise slows down (decel<0). Turn it off to see the stretch alone.")
 
emaLongLen  = input.int(200,   "Long EMA length (context)", minval=2, group="Context")
runupLen    = input.int(12,    "Run-up: bars back",        minval=1, group="Context",
     tooltip="Over how many bars to measure how far price has risen.")
volLen      = input.int(20,    "Volume average (bars)",          minval=1, group="Context")
volWin      = input.int(5,     "Volume peak: bars back",  minval=1, group="Context")
 
showInfo    = input.bool(true, "Show context panel",      group="Display")
showLabels  = input.bool(true, "Show BLOW-OFF label",     group="Display")
 
// ----------------------------------------------------------------------------
// BASE CALCULATIONS (all causal: they only use closed bars)
// ----------------------------------------------------------------------------
ema20  = ta.ema(close, emaLen)
ema200 = ta.ema(close, emaLongLen)
 
// 1) STRETCH = max(close last stretchWin) / EMA20 - 1
hiClose  = ta.highest(close, stretchWin)
stretch  = ema20 > 0 ? hiClose / ema20 - 1.0 : na
nThresh  = stretchPct / 100.0
isStretched = not na(stretch) and stretch > nThresh
 
// 2) DECEL = (close-close[3] - (close[3]-close[6])) / close[6]
//    Negative = the recent rise slows down versus the prior rise.
momRecent = close - close[3]
momPrev   = close[3] - close[6]
base6     = close[6]
decel     = base6 != 0 ? (momRecent - momPrev) / base6 : na
// accel_ratio = mom_recent / mom_prev (panel-only, informational)
accelRatio = momPrev != 0 ? momRecent / momPrev : na
decelOK   = not na(decel) and decel < 0.0
 
// 3) CONTEXT (informational, does not filter by default)
//    vol climax = max(volume last volWin) / mean(volume last volLen)
volMean   = ta.sma(volume, volLen)
volPeak   = ta.highest(volume, volWin)
volClimax = volMean > 0 ? volPeak / volMean : na
//    run-up = close/close[runupLen] - 1
runup     = close[runupLen] > 0 ? close / close[runupLen] - 1.0 : na
//    dist long EMA = close/EMA200 - 1
distLong  = ema200 > 0 ? close / ema200 - 1.0 : na
 
// ----------------------------------------------------------------------------
// HIGHLIGHTED CONDITION
// ----------------------------------------------------------------------------
isBlowOff = isStretched and (reqDecel ? decelOK : true)
 
// ----------------------------------------------------------------------------
// DRAWING
// ----------------------------------------------------------------------------
plot(ema20,  "Average EMA", color=color.new(color.orange, 0),  linewidth=2)
plot(ema200, "Long EMA",    color=color.new(color.gray, 40),   linewidth=1)
 
// Light background on blow-off bars
bgcolor(isBlowOff ? color.new(color.fuchsia, 80) : na, title="Blow-off background")
 
// Marker above the candle (the parabola is above the average)
plotshape(isBlowOff and chart.is_standard, title="Blow-off highlighted", style=shape.triangledown,
     location=location.abovebar, color=color.new(color.fuchsia, 0), size=size.tiny)
 
// Optional text label with the stretch value
if showLabels and isBlowOff and chart.is_standard
    label.new(bar_index, high,
         "BLOW-OFF\nstretch " + str.tostring(stretch * 100.0, "#.0") + "%",
         style=label.style_label_down,
         color=color.new(color.fuchsia, 10), textcolor=color.white, size=size.tiny)
 
// ----------------------------------------------------------------------------
// CONTEXT PANEL (read-only, updated on the last bar)
// ----------------------------------------------------------------------------
var table info = na
if showInfo
    if na(info)
        info := table.new(position.top_right, 2, 7, border_width=1)
    if barstate.islast
        table.clear(info, 0, 0, 1, 6)
        table.cell(info, 0, 0, "MHIDa Blow-Off", text_color=color.white,
             bgcolor=color.new(color.fuchsia, 20), text_size=size.small)
        table.cell(info, 1, 0, "context, not a signal", text_color=color.white,
             bgcolor=color.new(color.fuchsia, 20), text_size=size.small)
 
        table.cell(info, 0, 1, "Stretch", text_color=color.gray, text_size=size.small)
        table.cell(info, 1, 1, na(stretch) ? "-" : str.tostring(stretch * 100.0, "#.0") + "%",
             text_color = isStretched ? color.fuchsia : color.gray, text_size=size.small)
 
        table.cell(info, 0, 2, "Accel. slowing?", text_color=color.gray, text_size=size.small)
        table.cell(info, 1, 2, na(decel) ? "-" : (decelOK ? "yes (" : "no (") + str.tostring(decel * 100.0, "#.00") + "%)",
             text_color = decelOK ? color.fuchsia : color.gray, text_size=size.small)
 
        table.cell(info, 0, 3, "Volume climax x", text_color=color.gray, text_size=size.small)
        table.cell(info, 1, 3, na(volClimax) ? "-" : str.tostring(volClimax, "#.0") + "x",
             text_color=color.silver, text_size=size.small)
 
        table.cell(info, 0, 4, "Run-up " + str.tostring(runupLen) + " bars", text_color=color.gray, text_size=size.small)
        table.cell(info, 1, 4, na(runup) ? "-" : str.tostring(runup * 100.0, "#.0") + "%",
             text_color=color.silver, text_size=size.small)
 
        table.cell(info, 0, 5, "Distance long EMA", text_color=color.gray, text_size=size.small)
        table.cell(info, 1, 5, na(distLong) ? "-" : str.tostring(distLong * 100.0, "#.0") + "%",
             text_color=color.silver, text_size=size.small)
 
        table.cell(info, 0, 6, "Blow-off now?", text_color=color.gray, text_size=size.small)
        table.cell(info, 1, 6, isBlowOff ? "YES" : "no",
             text_color = isBlowOff ? color.fuchsia : color.gray, text_size=size.small)
 
// ----------------------------------------------------------------------------
// OPTIONAL ALERT (the user decides whether to create it). It stays a CONTEXT note.
// ----------------------------------------------------------------------------
alertcondition(isBlowOff, title="MHIDa blow-off highlighted",
     message="MHIDa Crest Blow-Off: extreme stretch above the average highlighted (a context aid, not a signal and not advice).")

← 返回列表