Osprey Pivots

El_Bichotico · study · 110 行 · 点赞 12 · TradingView 原页

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

Pine Script

//@version=6
indicator("Osprey Pivots", "Osprey Pivots", overlay = true, max_lines_count = 500, max_labels_count = 500)
 
// ---------- INPUTS ----------
minGapTicks = input.int(1, "Minimum gap (ticks)", minval = 1, tooltip = "How many ticks a candle must miss the running extreme by to confirm it. 1 = it simply must not touch it.")
showMarks   = input.bool(true,  "Mark all pivots")
showLast    = input.bool(true,  "Show last High / Low line")
showRays    = input.bool(false, "Extend each pivot until broken")
colHigh     = input.color(#ff5252, "High color")
colLow      = input.color(#00e676, "Low color")
 
isBull = close > open
isBear = close < open
 
// ---------- STATE ----------
var bool  hActive  = false
var float candH    = na
var int   candHBar = na
var bool  lActive  = false
var float candL    = na
var int   candLBar = na
 
var float lastHigh    = na
var int   lastHighBar = na
var float lastLow     = na
var int   lastLowBar  = na
 
bool newHigh = false
bool newLow  = false
 
// ---------- LOGIC (confirmed bars only, no repainting) ----------
if barstate.isconfirmed
    // High leg: starts on a bullish candle
    if hActive
        gapH = math.round((candH - high) / syminfo.mintick)
        if high > candH
            candH    := high
            candHBar := bar_index
        else if gapH >= minGapTicks
            newHigh     := true
            lastHigh    := candH
            lastHighBar := candHBar
            hActive     := false
    if not hActive and isBull
        hActive  := true
        candH    := high
        candHBar := bar_index
 
    // Low leg: starts on a bearish candle
    if lActive
        gapL = math.round((low - candL) / syminfo.mintick)
        if low < candL
            candL    := low
            candLBar := bar_index
        else if gapL >= minGapTicks
            newLow     := true
            lastLow    := candL
            lastLowBar := candLBar
            lActive    := false
    if not lActive and isBear
        lActive  := true
        candL    := low
        candLBar := bar_index
 
// ---------- MARKERS ----------
if showMarks and newHigh
    label.new(lastHighBar, na, "", yloc = yloc.abovebar, color = colHigh, style = label.style_triangledown, size = size.tiny)
if showMarks and newLow
    label.new(lastLowBar, na, "", yloc = yloc.belowbar, color = colLow, style = label.style_triangleup, size = size.tiny)
 
// ---------- LAST HIGH / LOW LINES ----------
var line lastHighLn = na
var line lastLowLn  = na
if showLast and newHigh
    line.delete(lastHighLn)
    lastHighLn := line.new(lastHighBar, lastHigh, bar_index, lastHigh, color = colHigh, width = 2, extend = extend.right)
if showLast and newLow
    line.delete(lastLowLn)
    lastLowLn := line.new(lastLowBar, lastLow, bar_index, lastLow, color = colLow, width = 2, extend = extend.right)
 
// ---------- RAYS UNTIL BROKEN ----------
var array<line> hRays = array.new<line>()
var array<line> lRays = array.new<line>()
 
if showRays and newHigh
    hRays.push(line.new(lastHighBar, lastHigh, bar_index, lastHigh, color = color.new(colHigh, 50), style = line.style_dotted))
if showRays and newLow
    lRays.push(line.new(lastLowBar, lastLow, bar_index, lastLow, color = color.new(colLow, 50), style = line.style_dotted))
 
if hRays.size() > 200
    hRays.shift()
if lRays.size() > 200
    lRays.shift()
 
if hRays.size() > 0
    for i = hRays.size() - 1 to 0
        ln = hRays.get(i)
        ln.set_x2(bar_index)
        if high > ln.get_y1()
            hRays.remove(i)
if lRays.size() > 0
    for i = lRays.size() - 1 to 0
        ln = lRays.get(i)
        ln.set_x2(bar_index)
        if low < ln.get_y1()
            lRays.remove(i)
 
// ---------- ALERTS ----------
alertcondition(newHigh, "New High", "New confirmed swing high on {{ticker}}")
alertcondition(newLow,  "New Low",  "New confirmed swing low on {{ticker}}")

← 返回列表