gpt4 book ai didi

pine-script - pine 脚本版本 4 中的编译错误

转载 作者:行者123 更新时间:2023-12-04 10:54:35 26 4
gpt4 key购买 nike

这段代码用//@version=2 编译就像一个魅力:

//@version=2
study("My Script")
Factor=input(3, minval=1,maxval = 100)
Pd=input(7, minval=1,maxval = 100)
Up=hl2-(Factor*atr(Pd))
Dn=hl2+(Factor*atr(Pd))
TrendUp=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
TrendDown=close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
Trend = close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
Tsl = Trend==1? TrendUp: TrendDown
linecolor = Trend == 1 ? green : red
plot(Tsl)

与//@version=4 相同
Add to Chart operation failed, reason: line 9: Undeclared identifier `TrendUp`;
line 10: Undeclared identifier `TrendDown`;
line 11: Undeclared identifier `TrendDown`;
line 11: Undeclared identifier `TrendUp`;
line 11: Undeclared identifier `Trend`;
line 12: Undeclared identifier `Trend`;
line 12: Undeclared identifier `TrendUp`;
line 12: Undeclared identifier `TrendDown`;
line 13: Undeclared identifier `Trend`;
line 13: Undeclared identifier `green`;
line 13: Undeclared identifier `red`;
line 14: Undeclared identifier `Tsl`

如何将此代码转换为在版本 4 中编译?
谢谢

最佳答案

您不能在声明语句中使用要声明的变量。

您应该首先声明变量并使用 :=运算符稍后为其分配一些值。

//@version=4
study("My Script2")
Factor=input(3, minval=1,maxval = 100)
Pd=input(7, minval=1,maxval = 100)
Up=hl2-(Factor*atr(Pd))
Dn=hl2+(Factor*atr(Pd))
TrendUp=Up
TrendUp:=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
TrendDown=Dn
TrendDown:=close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
Trend=TrendUp
Trend := close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
Tsl = Trend==1? TrendUp: TrendDown
linecolor = Trend == 1 ? color.green : color.red
plot(Tsl)

关于pine-script - pine 脚本版本 4 中的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59294599/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com