在开放级别绘制一条线,直到它们被击中

Plotting a line at open levels until they are hit

我想要一个脚本,在平底或平顶水平绘制一条线,直到它们被破坏,此时我希望该线自行删除。有点卡在这里...

两个 plotshapes 显示了紫色线应该删除自己的例子..

我想我需要以某种方式使用 xloc 条形索引,但我不确定如何使用

//@version=4
study("Flat Bottom",overlay=true)
timeframe=timeframe.multiplier>=240?true:false
flatbottom= low == open and (timeframe or timeframe.isdwm)
flattop = high == open and (timeframe or timeframe.isdwm)



currentYear = year(timenow)
currentMonth = month(timenow)
currentDay = dayofmonth(timenow)
today = year == currentYear and month == currentMonth and dayofmonth == currentDay

plotshape(barssince(flatbottom)==1 and low<open[1]) 
plotshape(barssince(flattop)==1 and high>open[1]) 

var lineLevel = float(na)
if (flatbottom or flattop)
    lineLevel := open
    line line_3 = line.new(time, open, time + 60 * 60 * 24,open, xloc=xloc.bar_time, extend=extend.right, color=color.purple, width=1)

试图找出 breachBot 和 breachTop 的循环

// ————— Label-creating condition
var flatb = false
flatb := flatbottom

var flatt = false
flatt := flattop

// ————— Count number of bars since last 
var barCountfb = 0
barCountfb := flatb ? not flatb[1] ? 1 : barCountfb + 1 : 0

var barCountft = 0
barCountft := flatt ? not flatt[1] ? 1 : barCountft + 1 : 0

// ————— Create labels while keeping a trail of label ids in series "lbl".
// This is how we will later identify the bars where a label exist.
label lbltop = na
if flatt
    lbltop := label.new(bar_index, high, tostring(barCountft), xloc.bar_index, yloc.price, size = size.small,textcolor=color.white,color=color.purple)

label lblbot = na
if flatb
    lblbot := label.new(bar_index, low, tostring(barCountfb), xloc.bar_index, yloc.price, size = size.small,textcolor=color.white,color=color.purple,style=label.style_label_up)



var breachBot = false
for i = 1 to 4000
    if not na(lblbot[i])
        // We have identified a bar where a label was created.
        if barssince(flatbottom)==i and low<open[i]
            breachBot == true


var breachTop = false
for i = 1 to 4000
    if not na(lbltop[i])
        // We have identified a bar where a label was created.
       if barssince(flattop)==i and high>open[i]
            label.delete(lbltop[i])
            breachTop = true

这里我们分别跟踪底行和顶行,并在创建它们时记住行 ID,以便我们可以在需要时删除它们。这只会删除您的 X 绘制的行:

//@version=4
study("Flat Bottom",overlay=true)
timeframe=timeframe.multiplier>=240?true:false
flatbottom= low == open and (timeframe or timeframe.isdwm)
flattop = high == open and (timeframe or timeframe.isdwm)

currentYear = year(timenow)
currentMonth = month(timenow)
currentDay = dayofmonth(timenow)
today = year == currentYear and month == currentMonth and dayofmonth == currentDay

var line lineTop = na
var line lineBot = na
breachBot = barssince(flatbottom)==1 and low<open[1]
breachTop = barssince(flattop)==1 and high>open[1]

// Delete lines on breach.
if breachBot
    line.delete(lineBot)
if breachTop
    line.delete(lineTop)
// Create lines on new flat top/bot.
if flatbottom
    lineBot := line.new(time, open, time + 60 * 60 * 24,open, xloc=xloc.bar_time, extend=extend.right, color=color.purple, width=1)
if flattop
    lineTop := line.new(time, open, time + 60 * 60 * 24,open, xloc=xloc.bar_time, extend=extend.right, color=color.green, width=1)

plotshape(breachBot) 
plotshape(breachTop)