从Pinescript到Python,得到一个Series的真值是模糊的

问题描述 投票:0回答:1

我正在将一个Pinescript指标转换为python,以便与pandas一起使用。

这是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) and df['RSI_ma'] > df['longband'].shift(1), 5 max(df['longband'].shift(1) ,df['newlongband']), df['newlongband']) 6 df['shortband'] = 0.0。

~Anaconda3\envs\finance\lib\sit-packages\pandas\core\generic.py中。非零(self) 1571 raise ValueError("a {0}的真值含糊不清。" 1572 "使用a.empty,a.bool(,a.item(,a.any(或a.all()。"-> 1573 .format(self. " 1572 "使用a.empty、a.bool()、a.item()、a.any()或a.all()。"-> 1573 .format(self.a.a.bool(,a.item(,a.any()或a.all()。"-> 1573 .format(self..名称)) 1574 1575 布尔 = 非零

ValueError。一个Series的真值含糊不清,请使用a.empty、a.bool(、a.item(、a.any(或a.all()。使用a.empty, a.bool(), a.item(), a.any()或a.all()。

python pandas trading pine-script
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.