dif = price_history.iloc[[x, x-1]].diff()
Is going to return a two element DataFrame, the first one will be the imaginary diff between the non-existant previous day.
Secondly you're calculating RSI wrong.
- First Average Gain = Sum of Gains over the past x periods / x
- First Average Loss = Sum of Losses over the past x periods / x
Subsequent Average Gain/Loss:
- Average Gain = [(previous Average Gain) x (x-1) + current Gain] / x
- Average Loss = [(previous Average Loss) x (x-1) + current Loss] / x.
Try not to reinvent the wheel if you dont have to.
Also I think your RSI checks are backwards. You're buying when the RSI shows overbought.
Also, a 180 day RSI is going to have almost zero signals because it'll average pretty close to 50.