根据当前价格绘制 hline
Drawing hline based on the current price
我想根据当前价格画一个hline
。我知道当前价格可以来自 close
系列,但我无法将系列的最后一个值转换为简单的浮点数,这是价格所需的类型。
//@version=4
study("Current price + 42", overlay=true)
hline((close + 42), color=color.orange, linestyle=hline.style_dashed)
这些行给我这个错误,我理解为“给我一个浮动,而不是一个系列”:
Cannot call 'hline' with arguments (series[float], color=const color, linestyle=const integer); available overloads: hline(input float, const string, input color, input integer, input integer, const bool, string) => hline
您可以像这样模仿 hline():
//@version=4
study("MoveLine", overlay=true)
offset = input(42)
var line myLine = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.both, color=color.orange, style=line.style_dashed, width=1)
y = close + offset
// Move line
line.set_xy1(myLine, time, y)
line.set_xy2(myLine, time + 1, y)
产生这个:
你也可以使用一个函数来移动线:
//@version=4
study("MoveLine", overlay=true)
offset = input(42)
f_hline(_line, _y) =>
line.set_xy1(_line, time, _y)
line.set_xy2(_line, time + 1, _y)
var line myLine = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.both, color=color.orange, style=line.style_dashed, width=1)
// Move line
f_hline(myLine, close + offset)
我想根据当前价格画一个hline
。我知道当前价格可以来自 close
系列,但我无法将系列的最后一个值转换为简单的浮点数,这是价格所需的类型。
//@version=4
study("Current price + 42", overlay=true)
hline((close + 42), color=color.orange, linestyle=hline.style_dashed)
这些行给我这个错误,我理解为“给我一个浮动,而不是一个系列”:
Cannot call 'hline' with arguments (series[float], color=const color, linestyle=const integer); available overloads: hline(input float, const string, input color, input integer, input integer, const bool, string) => hline
您可以像这样模仿 hline():
//@version=4
study("MoveLine", overlay=true)
offset = input(42)
var line myLine = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.both, color=color.orange, style=line.style_dashed, width=1)
y = close + offset
// Move line
line.set_xy1(myLine, time, y)
line.set_xy2(myLine, time + 1, y)
产生这个:
你也可以使用一个函数来移动线:
//@version=4
study("MoveLine", overlay=true)
offset = input(42)
f_hline(_line, _y) =>
line.set_xy1(_line, time, _y)
line.set_xy2(_line, time + 1, _y)
var line myLine = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.both, color=color.orange, style=line.style_dashed, width=1)
// Move line
f_hline(myLine, close + offset)