I'm converting a Pinescript Indicator to python to use it with pandas:
Here is pinescrip code:
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)
Now this is what I got so far in 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'])
And this is the error: ----> 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\site-packages\pandas\core\generic.py in nonzero(self) 1571 raise ValueError("The truth value of a {0} is ambiguous. " 1572 "Use a.empty, a.bool(), a.item(), a.any() or a.all()." -> 1573 .format(self.class.name)) 1574 1575 bool = nonzero
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().