Pine 脚本:无法获取 Ichimoku 引导线的上限(或下限)值

Pine script: Cannot get the upper (nor the lower) value of the Ichimoku leading lines

寻找我做错了什么。 我在蜡烛上方得到的图不是上引导线的值(我用下引导线试过 --> 相同的结果) 这是我的代码:

//@version=4     
study(title="Ich1", overlay=true )
var upper_val = 0.1
var lower_val = 1.0

// ichimoku calculations 

conversionPeriods = input(9, minval=1, title="Conversion Line Periods"), 
basePeriods = input(26, minval=1, title="Base Line Periods") 
laggingSpan2Periods` = input(52, minval=1, title="Lagging Span 2 Periods"), 
displacement = input(26, minval=1, title="Displacement")

donchian(len) => avg(lowest(len), highest(len))

conversionLine = donchian(conversionPeriods) 
baseLine = donchian(basePeriods) 
leadLine1 = avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)

// plot    
plot(conversionLine,color=color.orange,linewidth=4,title="Conversion Line") 
plot(baseLine, color=color.purple , linewidth=3, title="Base Line") 
plot(close, offset = -displacement + 1, color=#459915, title="Lagging Span") 
p1=plot(leadLine1,offset=displacement - 1,color=color.green,  title="Lead 1") 
p2=plot(leadLine2,offset=displacement - 1,color=color.red, title="Lead 2")

// end plot ichimoku

 
// rules 
if (leadLine1 >= leadLine2)
    upper_val := leadLine1
    lower_val := leadLine2 
else
    upper_val := leadLine2
    lower_val := leadLine1

target = tostring(upper_val) // can be replaced with: 
                            // target = tostring(upper_val[0])

//print the upper_val

label.new(bar_index, high , yloc = yloc.abovebar, textcolor = color.red, style = label.style_none,
           text = target)

您的 upper_line 的偏移量等于 displacement - 1

因此,当您在当前柱上调用值的字符串时,它会显示没有偏移量的值。

更改代码的第 38 行以显示带偏移量的实际值:

target = tostring(upper_val[displacement - 1])