change = price['adjclose'].diff(1)
change.dropna(inplace=True)
positive = change.copy()
negative = change.copy()
positive[positive<0] = 0
negative[negative>0] = 0
days = 10
average_gain = positive.rolling(window=days).mean()
average_loss = abs(negative.rolling(window=days).mean())
simple_moving_average = change.rolling(window=days).mean()
relative_strength = average_gain/average_loss
RSI = 100.0-(100.0/(1.0+relative_strength))
combined = pd.DataFrame()
combined['adjclose'] = price['adjclose']
combined['RSI'] = RSI
combined['SMA'] = simple_moving_average
#PLOTTING
plt.figure(figsize=(12,8))
ax1 = plt.subplot(211)
ax1.plot(combined.index, combined['adjclose'], color='lightgrey')
ax1.plot(combined['SMA'], color='green')
ax1.set_title("Adjusted Close Price", color='white')
ax1.grid(True, color='#555555')
ax1.set_axisbelow(True)
ax1.set_facecolor('black')
ax1.figure.set_facecolor('#121212')
ax1.tick_params(axis='x', colors='white')
ax1.tick_params(axis='y', colors='white')
The RSI graph is showing properly. However, when plotting the SMA alongside the price, the value of the SMA is very low and is not even close to the actual price. What am I doing wrong?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…