我在函数中使用For循环,并得到以下错误-
"对于";循环的索引不能使用字符串值
即使循环变量LookbackCounter被声明为Integer
Check_Conditions(CondCounter,Timeframe,RefType,RefPrm1,RefPrm2,RefPrm3,RefShift,NomType,NomPrm1,NomPrm2,NomPrm3,NomShift,NomBuffer) =>
float RetValue = 1.00000
OpenVal = request.security(syminfo.tickerid, Timeframe, open)
HighVal = request.security(syminfo.tickerid, Timeframe, high)
LowVal = request.security(syminfo.tickerid, Timeframe, low)
CloseVal = request.security(syminfo.tickerid, Timeframe, close)
VolumeVal = request.security(syminfo.tickerid, Timeframe, volume)
int LookbackCounter = 0
if RefType == "RSI"
RSIValue = ta.rsi(CloseVal, int(RefPrm1))
for LookbackCounter = 0 to LookBack[CondCounter]
array.set(RefVal,LookbackCounter,RSIValue[LookbackCounter + RefShift])
array.set(RefValPrv,LookbackCounter,RSIValue[LookbackCounter + RefShift+1])
RetValue := RSIValue
RetValue
我解决了自己的问题。
在这一行
for LookbackCounter = 0 to LookBack[CondCounter]
LookBack[CondCounter]就是问题所在。导致错误的是一个序列整数,而不是一个简单的整数。
我通过将值作为一个简单的整数传递给函数而不是引用全局序列整数来解决这个问题。