将值从 highestbars() 传递到 lowestbars() 的问题

Problems Passing value from highestbars() into lowestbars()

.

我的目标是确定自 highest-high[lookback] 以来 lowest-low 的柱线位置。

我不知道为什么不能将 hb 的值插入 lowestbars(),尽管我的感觉是 highestbars() 正在创建一个不可接受的变量类型lowestbars() ?

lookback = input(100)

hb  = -highestbars(high, lookback)

lb  = -lowestbars(low, hb)

据我了解,hb = -highestbars(high, lookback) 只是 returns 一个 int,即指定 (source, length).

的偏移量

我也通过绘图

在数据window中验证了这一点
plotchar(hb, title="hb",char="")`

plotchar(lb, title="lb",char="")`

既然如此,为什么不能简单地将hb的值传递给lowestbars()呢?

例如,如果我尝试 lowestbars(low, 5),我没有问题。但是 lowestbars(low, hb)——看起来具有相同的形式——不知何故导致 lowestbars() 计算 hb 就好像 na.

不幸的是,lowestbars(low, int(hb) )和其他类似的尝试都没有成功。

类似地,在 Pine Script 中是否有可能以某种方式确定变量 type 的内容,就像在 javascript:

中那样
var str = "this is string";

typeof str; // returns string

?

这可能是因为一些内置函数不能接受时间序列变量作为输入,hb 是一个系列 int,而不是 var int 或 input int。

lookback = input(30)

int h_offset = 0
float hh = high
int l_offset = 0
float ll = low

for i = 1 to lookback - 1
    if high[i] > hh
        hh := high[i]
        h_offset := i

for j = 1 to h_offset
    if low[j] < ll
        ll := low[j]
        l_offset := j


hh_lab = label.new(x = bar_index - h_offset, y = hh, style = label.style_label_down)
label.delete(hh_lab[1])
ll_lab = label.new(x = bar_index - l_offset, y = ll, style = label.style_label_up)
label.delete(ll_lab[1])