Pine Script报错求助:ta.sma参数类型不匹配问题
问题解决:Pine Script中ta.sma参数类型不匹配报错
报错原因
ta.sma()函数的length参数要求传入整数类型值,但你代码里的smoothK、smoothD、lengthRSI、lengthStoch都是用input.float()定义的浮点数类型,参数类型不匹配导致了这个错误。
修复方案
把这些周期类参数的input.float()替换为input.int(),因为均线长度、RSI周期这类参数本身就是整数,不需要浮点数类型。
修改后的完整代码
//@version=5 strategy("FingersCrossed Signals", overlay=true) //ta.ema ema3 = ta.ema(close,9) ema4 = ta.ema(close,21) long_ema = ta.crossover(ema3,ema4) short_ema = ta.crossover(ema4,ema3) //stochrsi smoothK = input.int(3, minval=1) smoothD = input.int(3, minval=1) lengthRSI = input.int(14, minval=1) lengthStoch = input.int(14, minval=1) src = input(close, title="RSI Source") rsi1 = ta.rsi(src, lengthRSI) k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK) d = ta.sma(k, smoothD) data = (60-k[1])/2 data2 = (k[1]-40)/2 long_stoch = k[1] >= d[1] and k[2] <= d[2] and k <= 60 and k >= 10 short_stoch = k[1] <= d[1] and k[2] >= d[2] and k >= 40 and k <= 95 //entries if (long_ema) strategy.entry("buy", strategy.long) if (ema3 > ema4 and long_stoch) // ema3 > ema4 means that crossover was already and uptrend is continuing strategy.entry("buy+1", strategy.long) if (short_ema) strategy.entry("sell", strategy.short)
内容的提问来源于stack exchange,提问作者Cletis Klampett
相关产品推荐
相关产品推荐

