如何比较 PineScript 中的两个高点

How to compare two highs in PineScript

我试图找到过去某个时期的摆动低点和摆动高点(我用其他方式计算的 numOfCandles,但我不想包括它,这对这个问题并不重要)。 我遇到一个问题,我的 if 语句永远不会成真,而它们应该是。它很简单,我想念

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

// numOfCandles is for example on 1minute chart 480

var HH = high[0]
var LL = low[0]
var HHcandleNum = 0
var LLcandleNum = 0

for i = 1 to numOfCandles
    if high[i] > HH
        HH:=high[i],
        HHcandleNum := i
    if low[i] < LL
        LL:=low[i],
        LLcandleNum := i


var lastLabel1 = label.new(bar_index-numOfCandles,high[numOfCandles],text="")
var lastLabel2 = label.new(bar_index-numOfCandles,high[numOfCandles],text="")
var lastLabel3 = label.new(bar_index-numOfCandles,high[numOfCandles],text="")

if barstate.islast == true
    if label.get_text(lastLabel1)!=""
        label.delete(lastLabel1)
    if label.get_text(lastLabel2)!=""
        label.delete(lastLabel2)
    if label.get_text(lastLabel3)!=""
        label.delete(lastLabel3)
    lastLabel1 := label.new(bar_index-numOfCandles,high[numOfCandles],text="start"),
    lastLabel2 := label.new(bar_index-HHcandleNum,high[HHcandleNum],text="HH"),
    lastLabel3 := label.new(bar_index-LLcandleNum,high[LLcandleNum],text=tostring(low[1]))
    

如果barstate.islast == true,我应该把计算放在里面...愚蠢的错误...