Pine script 在最后一条上查找系列中的值(Pine脚本、Tradingview)

Pine script 在最后一条上查找系列中的值(Pine脚本、Tradingview),pine-script,Pine Script,首先,我计算每个条上的序列值,在最后一个条上,我想知道特定值是否在计算的序列中。不幸的是,“valuewhen”似乎不能与“if barstate.islast==true”结合使用。“valuewhen”的结果总是很难,我不明白为什么。当我在if语句之外使用“valuewhen”时,我在每个条上都会得到预期的结果(但我只需要在最后一条上使用它)。有什么想法吗 var hh = close[0] curh = highest(high, 15) if curh > hh[1] hh

首先,我计算每个条上的序列值,在最后一个条上,我想知道特定值是否在计算的序列中。不幸的是,“valuewhen”似乎不能与“if barstate.islast==true”结合使用。“valuewhen”的结果总是很难,我不明白为什么。当我在if语句之外使用“valuewhen”时,我在每个条上都会得到预期的结果(但我只需要在最后一条上使用它)。有什么想法吗

var hh = close[0]
curh = highest(high, 15)

if curh > hh[1]
   hh := curh

if barstate.islast == true
   level = 1.31428 // a value which is definitely in the hh series
   high1 = valuewhen(level==hh, hh, 1)

myLabel = label.new(x=bar_index, y=low - 0.5 * tr,
      color=color.orange, textcolor=color.white,
      style=label.style_labelup)
label.set_text(id=myLabel, text=tostring(high1))  // only shows NaN, although I expect to see 1.31428