Мне нужен скрипт, который строит линию на уровнях flatbottom или flat top до тех пор, пока они не будут прорваны, и в этот момент я хочу, чтобы линия удалила себя. Немного застрять здесь ...
На двух графиках показаны примеры, где фиолетовая линия должна удалять себя.
Я думаю, что мне нужно каким-то образом использовать индекс бара xlo c, но я не уверен, как
//@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