Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###############################################################################
- # 5d. Candlesticks with Moving Averages #
- ###############################################################################
- # Define time interval to consider
- start_date = datetime.date(2015, 5, 18) # Year-Month-Day
- end_date = datetime.date(2015, 7, 10)
- # Create figure
- f, ax = plt.subplots(figsize=(13, 6.5))
- # Plot ADI_OHLC data
- candlestick_ohlc(ax, ADI_candle.values.tolist(),
- width=.6,
- colorup='green',
- colordown='red')
- # Plot 50-day SMA
- SMA50.plot(color = ["magenta"], style = ["-"], linewidth = 2.5, ax = ax)
- # Plot 200-day SMA
- SMA200.plot(color = ["b"], style = ["-"], linewidth = 2.5, ax = ax)
- # Plot 9-day EMA
- EMA9.plot(color = ["blueviolet"], linewidth = 2.5, style = ["--"], ax = ax)
- # Plot 20-day EMA
- EMA20.plot(color = ["orange"], linewidth = 2.5, style = ["--"], ax = ax)
- # Set x and y axis limits
- ax.set_xlim([start_date, end_date])
- ax.set_ylim([60, 69])
- # Set axis labels
- ax.set_ylabel("Price ($)", fontsize = 20)
- # Rotate tick labels
- xlabels = ax.get_xticklabels()
- ax.set_xticklabels(xlabels, rotation = 45, fontsize = 14)
- # Change x-axis tick label fromat
- ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
- # Send gridlines to back
- ax.set_axisbelow(True)
- # Show legend
- plt.legend()
- # Tight layout
- plt.tight_layout()
- # Save Figure
- plt.savefig("ADI Candlestick Chart With Averages.png", dpi = 1080)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement