首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在Pine脚本中获取当前条的前一个主要轴心?

在Pine脚本中,要获取当前条的前一个主要轴心,可以使用ta.valuewhen()函数结合条件判断来实现。

主要轴心是指价格走势中的高点或低点,可以通过判断当前价格与前一个价格的大小关系来确定当前条是否为主要轴心。以下是一个示例代码:

代码语言:txt
复制
//@version=4
study("获取前一个主要轴心", overlay=true)

// 定义一个变量来保存前一个主要轴心的索引
var int prevPivotIndex = na

// 判断当前条是否为主要轴心
isPivot = high > high[1] and high > high[2] and high > high[3] and high > high[4] and
           high > high[5] and high > high[6] and high > high[7] and high > high[8] and
           high > high[9] and high > high[10] and high > high[11] and high > high[12] and
           high > high[13] and high > high[14] and high > high[15] and high > high[16] and
           high > high[17] and high > high[18] and high > high[19] and high > high[20]

// 如果当前条是主要轴心,则更新prevPivotIndex变量
if isPivot
    prevPivotIndex := bar_index

// 获取前一个主要轴心的索引
prevPivotIndex := ta.valuewhen(isPivot, bar_index, 1)

// 输出前一个主要轴心的索引
plot(prevPivotIndex, title="前一个主要轴心的索引", color=color.blue, linewidth=2)

在上述代码中,我们使用isPivot变量来判断当前条是否为主要轴心,通过比较当前价格与前20个价格的大小关系来确定。如果当前条是主要轴心,则更新prevPivotIndex变量为当前条的索引;如果不是主要轴心,则使用ta.valuewhen()函数获取前一个主要轴心的索引。

请注意,以上代码仅为示例,具体的判断条件和逻辑可以根据实际需求进行调整。此外,腾讯云并没有与Pine脚本相关的产品或服务,因此无法提供相关的产品介绍链接地址。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券