我正在尝试将以下pinescript代码转换为version4。我收到未声明的标识符错误。有人可以帮我吗?
//Declare General Trend
TL1(src, len) =>
weight = 3.5 / (len + 1)
sum = nz(sum[1]) - nz(src[len]) + src
ma = na(src[len]) ? na : sum/len
out = na(out[1]) ? ma : (src - out[1]) * weight + out[1]
out
TL(src, len) =>
weight = 2 / (len + 1)
sum = nz(sum[1]) - nz(src[len]) + src
ma = na(src[len]) ? na : sum/len
out = na(out[1]) ? ma : (src - out[1]) * weight + out[1]
out
TL3 = TL(low,16) - TL1(low,16)
TL4 = percentrank(TL3, 8)
TL5 = (TL3 < 0 and TL4 > 75) ? 1 : 0
答案 0 :(得分:1)
在没有可编译代码的情况下无法确认,但这应该可行。从v3开始,必须先声明变量,然后才能将变量与历史参考[ ]
一起使用。另外,使用var
仅在第一个小节上声明var,因此在小节之间传播它们的值,通常不必使用[1]
来引用它们的先前值:
//Declare General Trend
TL1(src, len) =>
var float sum = 0.
var float out = na
weight = 3.5 / (len + 1)
sum := sum - nz(src[len]) + src
ma = na(src[len]) ? na : sum/len
out := na(out) ? ma : (src - out) * weight + out
out
TL(src, len) =>
var float sum = 0.
var float out = na
weight = 2 / (len + 1)
sum := sum - nz(src[len]) + src
ma = na(src[len]) ? na : sum/len
out := na(out) ? ma : (src - out) * weight + out
out
TL3 = TL(low,16) - TL1(low,16)
TL4 = percentrank(TL3, 8)
TL5 = (TL3 < 0 and TL4 > 75) ? 1 : 0