我有一个 Pine Script,我用两条不同长度的线测量体积流量。白线的长度大约是40,绿线的长度大约是130。我想知道(暂时贴个标签),绿线和白线一起穿过中间(零)。线连在一起的样本点用红色垂直线表示空头,绿色垂直线表示多头。黄色垂直线显示绿线和白线不同步(一起)穿过中间的点。
因此,在我的例子中,白线称为 vfinal,绿线称为 vfinal2。
我试着写这样的东西:
var int mode = 0
if (vfinal[1] > 0 and vfinal < 0)
mode := 1
if (vfinal2[1] > 0 and vfinal2 < 0 and mode == 1)
lab = label.new(x = bar_index, y = 0, yloc = yloc.abovebar, style = label.style_label_down, text = "Sell", textcolor = color.white, size = size.normal, color = color.blue)
但是这个方法不看白线之前有没有穿过中间。我需要这两条线同步通过中间。
尝试ta.cross
类似的东西:
if ta.cross(vfinal, 0) and ta.cross(vfinal2, 0)
lab = label.new(x = bar_index, y = 0, yloc = yloc.abovebar, style = label.style_label_down, text = "Sell", textcolor = color.white, size = size.normal, color = color.blue)