I'm trying to create a new column in a DataFrame that flags 'signals'. I cannot seem to figure out how to achieve this within pandas without setting variables and doing the following:
all_candles = pd.read_csv('ExportTest.csv', index_col=0)
all_candles.reset_index(level=0, inplace=True)
rows = len(all_candles.index)
for i in range(1,rows):
current_RSI = all_candles.loc[i]['RSI']
prev_RSI = all_candles.loc[i-1]['RSI']
if prev_RSI < 30 and current_RSI >= 30:
print('BULL SIGNAL')
elif prev_RSI >= 70 and current_RSI < 70:
print('BEAR SIGNAL')
Where it states BULL SIGNAL or BEAR SIGNAL, i want it to fill in a new column called all_candles['SIGNAL']. The ideal solution i want is to have it all contained in pandas so i don't have to do a for loop.
e.g. (forgive the crude way of noting this out, i know the syntax isn't valid at all.)
if all_candles['RSI'].shift(-1) < 30 and all_candles['RSI'] >= 30:
all_candles['SIGNAL'] = 'BULL'
elif all_candles['RSI'].shift(-1) >= 70 and all_candles['RSI'] < 70:
all_candles['SIGNAL'] = 'BEAR'
else
all_candles['SIGNAL'] = 'NON'
Any help would be much appreciated with regards to the art of the possible.