繁体   English   中英

计算 pinescript 中 bar_index 之间的长度

[英]Calculate length between bar_index in pinescript

想要计算test_X1 bar 和bar_index之间的最高close价,然后是plot这条线,前提是最高close价不大于test_y增加 10%

当我尝试使用highest()时,它希望我使用 integer 值作为lengthbar_index-test_x1仍然是一个系列。

//@version=4
study(title="Test", shorttitle="Test", format=format.volume, overlay=true)

var line    hline                   = line.new(na, na, na, na, extend=extend.right, color=color.white)
var test_y = -1.0
var test_x1 = -1.0

if close > close[2]
    line.set_xy1(hline, bar_index - 20, close)
    line.set_xy2(hline, bar_index,      close)
    test_y := close
    test_x1 := bar_index

像这样?

//@version=4
study(title="Test", shorttitle="Test", format=format.volume, overlay=true)

var bars_back = input(20)

var line    hline = line.new(na, na, na, na, extend=extend.right, color=color.white)

hc = highest(close, bars_back)

if barstate.islast and (close <= hc * 1.1)
    line.set_xy1(hline, bar_index - bars_back,  hc)
    line.set_xy2(hline, bar_index,              hc)
else
    line.set_xy1(hline, na, na)
    line.set_xy2(hline, na, na)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM