我想画一个盒子,从最高的蜡烛到最后的20支蜡烛的最低。每个盒子有四个侧面:上,下,左和右。对于顶部和底部,我使用的是最高()和最低(),但对于左和右,我如何为最高和最低的蜡烛找到时间呢?
发布于 2022-07-22 15:06:32
您可以找到高使用最高和低使用最低的功能。然后,您可以使用barssince函数找到它们的索引。然后,您可以使用它们在最后一个栏使用barstate.islast绘制一个框。下面的例子
//@version=5
indicator(title="Highest Lowest Bar", shorttitle="HLB", overlay=true)
hi=ta.highest(high,20)
lo=ta.lowest(low,20)
hiIndex=ta.barssince(high==hi)
loIndex=ta.barssince(low==lo)
var box b=na
if barstate.islast
box.delete(b)
b:=box.new(bar_index-hiIndex,hi,bar_index-loIndex,lo,bgcolor=color.new(color.blue,80),border_color=na)
发布于 2022-07-22 14:41:27
当检测到新的最高/最低值时,请将时间保存在变量中,您也可以在box.new变量中选择使用bar_index。给出使用“时间”的示例
var int time_high = 0
var int time_low = 0
current_highest = ta.highest(20)
current_lowest = ta.lowest(20)
// If new High/Low
if (current_highest != current_highest[1])
time_high := time
if (current_lowest != current_lowest[1])
time_low := time
https://stackoverflow.com/questions/73082046
复制相似问题