找出蜡烛最高和最低的时间



我想从最后20支蜡烛中最高的蜡烛到最低的蜡烛画一个方框。每个盒子有4个侧面:顶部、底部、左侧和右侧。对于顶部和底部,我使用highest((和lowest((,但对于左侧和右侧,我如何找到最高和最低蜡烛的时间?

您可以使用最高函数找到最高值,使用最低函数找到最低值。然后可以使用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)

当检测到新的最高/最低值时,将时间保存在变量中此外,您还可以在box.new变量中选择使用bar_index。给你举一个使用";times";

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

最新更新