我正在将Pinescript Indicator转换为python以与大熊猫一起使用:
这是pinescrip代码:
RSI_Period = input(14,title='RSI')
SF = input(5,title='Slow Factor')
QQE=input(4.236)
Wilders_Period = RSI_Period * 2 - 1
Rsi = rsi(close,RSI_Period)
RsiMa = ema(Rsi, SF)
AtrRsi = abs(RsiMa[1] - RsiMa)
MaAtrRsi = ema(AtrRsi, Wilders_Period)
dar = ema(MaAtrRsi,Wilders_Period) * QQE
DeltaFastAtrRsi= dar
RSIndex=RsiMa
newshortband= RSIndex + DeltaFastAtrRsi
newlongband= RSIndex - DeltaFastAtrRsi
longband=RSIndex[1] > longband[1] and RSIndex > longband[1]?
max(longband[1],newlongband):newlongband
shortband=RSIndex[1] < shortband[1] and RSIndex < shortband[1]?
min(shortband[1], newshortband):newshortband
trend=cross(RSIndex, shortband[1])?1:cross(longband[1], RSIndex)?-1:nz(trend[1],1)
FastAtrRsiTL = trend==1? longband: shortband
plot(FastAtrRsiTL,color=red)
plot(RsiMa,color=yellow)
现在这就是我到目前为止在python中得到的:
RSIPeriod = 14
SF = 5
QQE=4.236
WildersPeriod = RSIPeriod * 2 - 1
df['RSI'] = ta.RSI(df['Price'], RSIPeriod)
df['RSI_ma'] = ta.EMA(df['RSI'], SF)
df['ATRrsi'] = abs(df['RSI_ma'].shift(1) - df['RSI_ma'])
df['MaATRrsi'] = ta.EMA(df['ATRrsi'], WildersPeriod)
df['dar'] = ta.EMA(df['MaATRrsi'], WildersPeriod) * QQE
df['newshortband'] = df['RSI_ma'] + df['dar']
df['newlongband'] = df['RSI_ma'] - df['dar']
df['longband'] = 0.0
df['longband'] = np.where( df['RSI_ma'].shift(1) > df['longband'].shift(1) and df['RSI_ma'] > df['longband'].shift(1),
max(df['longband'].shift(1) ,df['newlongband']), df['newlongband'])
df['shortband'] = 0.0
df['shortband'] = np.where( df['RSI_ma'].shift(1) < df['shortband'].shift(1) and df['RSI_ma'] < df['shortband'].shift(1),
max(df['shortband'].shift(1) ,df['newshortband']), df['newshortband'])
df['trend'] = np.where(df['RSI_ma'] > df['dar'].shift(1), 1, -1)
df['FastAtrRsiTL'] = np.where(df['trend'] == 1, df['longband'], df['shortband'])
这是错误: ----> 4 df ['longband'] = np.where(df ['RSI_ma']。shift(1)> df ['longband']。shift(1)和df ['RSI_ma']> df [ 'longband']。shift(1), 5个最大值(df ['longlong']。shift(1),df ['newlongband']),df ['newlongband']) 6 df ['shortband'] = 0.0
〜\ Anaconda3 \ envs \ finance \ lib \ site-packages \ pandas \ core \ generic.py in nonzero (自己) 1571提高ValueError(“ {0}的真值是不明确的。” 1572“使用a.empty,a.bool(),a.item(),a.any()或a.all()。” -> 1573 .format(self。 class 。 name )) 1574 1575 bool = nonzero
(非零)ValueError:系列的真值不明确。使用a.empty,a.bool(),a.item(),a.any()或a.all()。