When sell
signal appears highest_buy
is equal na
and the label is not displayed. It is necessary to take the values on the previous bar.
//@version=4
study("Help prof (My Script)", overlay = true)
var bool track = false
var float highest_buy = na
ema1 = ema(close, 20)
ema2 = ema(close, 50)
buy = crossover(ema1, ema2)
sell = crossunder(ema1, ema2)
if buy
track := true
else if sell
track := false
highest_buy := track ? max(nz(highest_buy), high) : na
plot(ema1)
plot(ema2, color=color.yellow)
plot(highest_buy, color=color.purple, style=plot.style_linebr)
buy_entry = valuewhen(buy, close, 0)
plot(buy_entry, color = buy_entry == buy_entry[1] and ema1 > ema2? color.lime :na)
if sell
label1 = label.new(bar_index, highest_buy[1], text=tostring(highest_buy[1] - buy_entry[1]) , style=label.style_label_down, color=color.black, textcolor=color.white)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…