SREN - Price Breakout

sren20 · study · 58 行 · 点赞 31 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sren20
 
 
//@version=6
indicator("Price Breakout", overlay = true, max_lines_count = 300)
 
// ── Inputs ─────────────────────────────────────────────
leftBars   = input.int(20, "Bars left of high",  minval = 1, group = "Swing high")
rightBars  = input.int(5, "Bars right of high", minval = 1, group = "Swing high",
     tooltip = "A high is confirmed once this many bars close below it")
useClose   = input.bool(true, "Require a close above the high", group = "Breakout",
     tooltip = "Off = a wick through the high counts as a breakout")
 
showLevel  = input.bool(true, "Show waiting level (dotted)", group = "Style")
showMarker = input.bool(true, "Show breakout marker",        group = "Style")
breakColor = input.color(#26a69a, "Breakout line", group = "Style")
pendColor  = input.color(color.new(color.gray, 50), "Waiting level", group = "Style")
lineWidth  = input.int(1, "Line width", minval = 1, maxval = 4, group = "Style")
 
// ── State ──────────────────────────────────────────────
var float lastHigh    = na
var int   lastHighBar = na
var line  pending     = na
var bool  broken      = true
 
// ── New swing high ─────────────────────────────────────
ph = ta.pivothigh(high, leftBars, rightBars)
 
if not na(ph)
    line.delete(pending)                       // drop the old, unbroken level
    lastHigh    := ph
    lastHighBar := bar_index - rightBars
    broken      := false
    pending     := showLevel ? line.new(lastHighBar, lastHigh, bar_index, lastHigh,
         color = pendColor, style = line.style_dotted, width = 1) : na
 
// Keep the waiting level stretched to the current bar
if not broken and not na(pending)
    line.set_x2(pending, bar_index)
 
// ── Breakout ───────────────────────────────────────────
src      = useClose ? close : high
breakout = not broken and not na(lastHigh) and src > lastHigh
 
if breakout
    broken := true
    line.delete(pending)
    pending := na
    line.new(lastHighBar, lastHigh, bar_index, lastHigh,
         color = breakColor, style = line.style_solid, width = lineWidth)
 
plotshape(showMarker and breakout, "Breakout", shape.triangleup, location.belowbar,
     color.new(breakColor, 20), size = size.tiny)
 
alertcondition(breakout, "Breakout above last high", "{{ticker}} broke above the last swing high")
 
plot(close)

← 返回列表