MHIDa Parabolic-Run Dip

MHIDa · study · 104 行 · 点赞 3 · TradingView 原页

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

Pine Script

//@version=6
// ============================================================================
// Parabolic-Run Dip - a tool to help you assess what you see
// on the chart. It is NOT a signal, NOT advice, and NOT a winner on its own.
// You always decide.
// ----------------------------------------------------------------------------
// WHAT IT IS: a context highlighter. It first looks for a "parabolic run" (many
// consecutive up-candles, a push that accelerates) and waits for that run to
// BREAK (a non-up candle). That break "arms" a short observation window. Inside
// that window it highlights the FIRST dip where price closes well below its EMA
// (the EMA20 by default) - i.e. the excess unwinding after the euphoria.
//
// WHAT IT IS FOR: to see at a glance "the push has run out and now price has
// fallen below its moving average" - a context for YOU to evaluate with your
// own eyes on the chart. It does NOT say "buy" or "sell". It is NOT financial
// advice. It guarantees nothing, and on its own it is not enough: it is a
// support, not a strategy.
//
// HONESTY: this pattern is an interesting observation, NOT a standalone edge.
// That is exactly why this is a context tool, not a system. The defaults below
// are an educational starting point - all of them are adjustable.
// ============================================================================
 
indicator("MHIDa Parabolic-Run Dip", shorttitle="ParaRunDip", overlay=true)
 
// ---------------------------------------------------------------------------
// INPUTS - all configurable. Defaults are just an educational starting point.
// ---------------------------------------------------------------------------
runBars    = input.int(5,    "Consecutive up-bars (run)",         minval=2,   step=1,   tooltip="How many up-candles in a row are needed to call it a 'parabolic run'. Default 5.")
dipPct     = input.float(3.5, "Dip depth % below EMA20",          minval=0.1, step=0.1, tooltip="How far below the EMA20 price must close to call it a 'dip'. Default 3.5%.")
windowBars = input.int(8,    "Window bars (armed duration)",      minval=1,   step=1,   tooltip="For how many bars after the run breaks the window stays open to look for the first dip. Default 8.")
emaLen     = input.int(20,   "EMA length",                        minval=1,   step=1,   tooltip="Periods for the EMA moving average. Default 20.")
firstOnly  = input.bool(true, "Only the FIRST dip of the window", tooltip="Highlight only the first dip inside each armed window (as in the description 'the first dip below the moving average'), then disarm. Turn off to see every dip in the window.")
showLabels = input.bool(true, "Show labels",                      tooltip="Show the 'RUN BROKE' and 'DIP' text on the chart.")
 
// ---------------------------------------------------------------------------
// BASE CALCULATIONS - reference EMA20 and the consecutive up-bar count.
// ---------------------------------------------------------------------------
ema20 = ta.ema(close, emaLen)        // reference exponential moving average
upBar = close > close[1]             // "up" candle: closes above the prior close
 
// Count how many consecutive up-bars we have accumulated up to this bar.
var int upStreak = 0
upStreak := upBar ? upStreak + 1 : 0
 
// ---------------------------------------------------------------------------
// 1) PARABOLIC RUN -> BREAK
//    "Run": we have had >=runBars up-bars in a row (the accelerating push).
//    "Break": the current bar is NOT up (the run interrupts). That moment of
//    exhaustion of the push is what opens the observation window.
//    We read the streak of the PREVIOUS bar [1] so that the break is confirmed
//    on a closed candle.
// ---------------------------------------------------------------------------
runBroke = (upStreak[1] >= runBars) and not upBar
 
// ---------------------------------------------------------------------------
// "ARMED" WINDOW
//    On the break, the window stays open for 'windowBars' bars. A counter that
//    reloads on the break and decrements by 1 each bar.
// ---------------------------------------------------------------------------
var int armedCount = 0
armedCount := runBroke ? windowBars : (armedCount > 0 ? armedCount - 1 : 0)
inWindow = armedCount > 0
 
// ---------------------------------------------------------------------------
// 2) FIRST DIP INSIDE THE WINDOW
//    Inside the window: close < EMA20 * (1 - dip%). dipPct=3.5 -> close at
//    least 3.5% below the EMA20. If 'firstOnly' is active, after the first dip
//    we disarm the window (highlighting only the FIRST dip below the moving
//    average, as in the description).
// ---------------------------------------------------------------------------
dipLevel = ema20 * (1 - dipPct / 100.0)
rawDip   = inWindow and not na(ema20) and close < dipLevel
 
var bool firedThisWindow = false
// Reset the "already flagged" flag on every new break/arming.
if runBroke
    firedThisWindow := false
dipNow = rawDip and (not firstOnly or not firedThisWindow)
if dipNow and firstOnly
    firedThisWindow := true
    armedCount := 0                  // disarm: we look only for the first dip
 
// ---------------------------------------------------------------------------
// VISUALIZATION
// ---------------------------------------------------------------------------
plot(ema20,    "EMA20",       color=color.new(color.orange, 0),  linewidth=2)
plot(dipLevel, "Dip level",   color=color.new(color.teal, 40),   linewidth=1, style=plot.style_stepline)
 
// Light amber background when the window is armed: highlights the "context".
bgcolor(inWindow ? color.new(color.orange, 88) : na, title="Armed window")
 
// Markers
plotshape(runBroke and chart.is_standard, title="Run broke",     style=shape.triangledown, location=location.abovebar, color=color.new(color.orange, 0), size=size.small)
plotshape(dipNow and chart.is_standard, title="Dip in window", style=shape.circle,       location=location.belowbar, color=color.new(color.teal, 0),   size=size.small)
 
// Text labels (optional)
if showLabels and runBroke and chart.is_standard
    label.new(bar_index, high, "RUN BROKE", style=label.style_label_down, color=color.new(color.orange, 20), textcolor=color.white, size=size.tiny)
if showLabels and dipNow and chart.is_standard
    label.new(bar_index, low, "DIP", style=label.style_label_up, color=color.new(color.teal, 10), textcolor=color.white, size=size.tiny)
 
// Optional alert: a CONTEXT notification only, not an order and not advice.
alertcondition(dipNow, title="ParaRunDip context", message="Parabolic-Run Dip: first dip below the EMA20 after a broken parabolic run. Context only, to be evaluated, not advice.")

← 返回列表