SHARE
TWEET

Untitled

a guest Sep 12th, 2019 460 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###############################################################################
  2. #                       5d. Candlesticks with Moving Averages                 #
  3. ###############################################################################
  4. # Define time interval to consider
  5. start_date = datetime.date(2015, 5, 18) # Year-Month-Day
  6. end_date   = datetime.date(2015, 7, 10)
  7.  
  8. # Create figure
  9. f, ax = plt.subplots(figsize=(13, 6.5))
  10.  
  11. # Plot ADI_OHLC data
  12. candlestick_ohlc(ax, ADI_candle.values.tolist(),
  13.                  width=.6,
  14.                  colorup='green',
  15.                  colordown='red')
  16.  
  17. # Plot 50-day SMA
  18. SMA50.plot(color = ["magenta"], style = ["-"], linewidth = 2.5, ax = ax)
  19.  
  20. # Plot 200-day SMA
  21. SMA200.plot(color = ["b"], style = ["-"], linewidth = 2.5, ax = ax)
  22.  
  23. # Plot 9-day EMA
  24. EMA9.plot(color = ["blueviolet"], linewidth = 2.5, style = ["--"], ax = ax)
  25.  
  26. # Plot 20-day EMA
  27. EMA20.plot(color = ["orange"], linewidth = 2.5, style = ["--"], ax = ax)
  28.  
  29. # Set x and y axis limits
  30. ax.set_xlim([start_date, end_date])
  31. ax.set_ylim([60, 69])
  32.  
  33. # Set axis labels
  34. ax.set_ylabel("Price ($)", fontsize = 20)
  35.  
  36. # Rotate tick labels
  37. xlabels = ax.get_xticklabels()
  38. ax.set_xticklabels(xlabels, rotation = 45, fontsize = 14)
  39.  
  40. # Change x-axis tick label fromat
  41. ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
  42.  
  43. # Send gridlines to back
  44. ax.set_axisbelow(True)
  45.  
  46. # Show legend
  47. plt.legend()
  48.  
  49. # Tight layout
  50. plt.tight_layout()
  51.  
  52. # Save Figure
  53. plt.savefig("ADI Candlestick Chart With Averages.png", dpi = 1080)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top