3

I have some code that produces a candlestick chart for stocks (below).

Input:

#import modules
import pandas as pd
from matplotlib.finance import candlestick2_ohlc
import matplotlib.ticker as ticker
import matplotlib.pyplot as plt

build the dataframe

api = 'http://finance.google.com/finance/getprices?q=SPY&i=300&p=3d&f=d,o,h,l,c,' 
df = pd.read_csv(api, skiprows=8, header=None)
df.columns = ['Record', 'Open', 'High', 'Low', 'Close']

build candlestick chart

quotes = df[-36:]
fig, ax = plt.subplots()
candlestick2_ohlc(ax,quotes['Open'],quotes['High'],quotes['Low'],quotes['Close'],width=0.6)
ax.xaxis.set_major_locator(ticker.MaxNLocator(6))
fig.autofmt_xdate()
fig.tight_layout()
plt.xlabel('5 Min Chart')
plt.savefig('candle.jpg')

Output is a candlestick chart

SPY CHART

What I want to do now is draw a line that connects the low of one candle to the low of another candle (for example, 10 lows ago vs current low) to create trend lines. I don't know how to achieve this on my chart.

Any help is greatly appreciated!

pmillerhk
  • 171
  • 1
  • 2
  • 12

0 Answers0