首页 > 解决方案 > pivothigh/pivotlow 没有按预期工作

问题描述

为什么这段代码向我显示错误的数据透视高点?它正在计算左侧和右侧的每一秒栏,而不仅仅是一个...如果我更改为:

bar_index % 1 == 0,它工作正常。

这是我的代码:

//@version=4
study("fckn test", overlay=true) 

if bar_index % 2 == 0
    ph = pivothigh(1,1)

    label.new(bar_index-1, low, tostring(ph))

标签: pine-script

解决方案


不太确定您要做什么。也许这个?

//@version=4
study("fckn test", overlay=true)
pivotLegs = 1
// Find pivot outside `if` block because needs to run on every bar.
ph = pivothigh(pivotLegs, pivotLegs)
// Detect a new pivot.
newPh = not na(ph)
// If a new pivot is found, save the bar index where it was found.
bh = newPh ? bar_index - pivotLegs : na
if bar_index % 2 == 0 and not na(ph)
    label.new(bh, high[pivotLegs], tostring(ph))

在此处输入图像描述


推荐阅读