fix issue with candlestick chart

This commit is contained in:
damo1884
2017-11-08 19:28:44 -08:00
parent 12695474e3
commit 061de3c12f
+17 -14
View File
@@ -42,7 +42,7 @@ def initialize(context):
context.errors = []
# Bars to look at per iteration should be bigger than SMA_SLOW
context.BARS = 100
context.BARS = 365
context.COUNT = 0
# Technical Analysis Settings
@@ -144,7 +144,7 @@ def analyze(context, results):
results.to_csv(filename + '.csv')
log.info('the daily stats:\n{}'.format(get_pretty_stats(results)))
chart(context, context.prices, context.analysis)
chart(context, context.prices, context.analysis, results)
pass
def makeOrders(context, analysis):
@@ -235,31 +235,32 @@ def isSell(context, analysis):
return False
def chart(context, prices, analysis):
def chart(context, prices, analysis, results):
results.portfolio_value.plot()
# Data for matplotlib finance plot
dates = date2num(prices.index.to_pydatetime())
prices_ochl = [tuple([dates[i],
# Create the Open High Low Close Tuple
prices_ohlc = [tuple([dates[i],
prices.open[i],
prices.close[i],
prices.high[i],
prices.low[i]]) for i in range(len(dates))] #_1
prices.low[i],
prices.close[i]]) for i in range(len(dates))]
# Prepare plot
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, sharex=True)
fig = plt.figure(figsize=(14,18))
# Draw the candle sticks
ax1 = fig.add_subplot(411)
ax1.set_ylabel(context.ASSET_NAME, size=20)
#size plot
fig.set_size_inches(15,30)
# Plot candles
candlestick_ohlc(ax1, prices_ochl, width=0.5, colorup='g', colordown='r')
candlestick_ohlc(ax1, prices_ohlc, width=0.4 ,colorup='g', colordown='r')
# Draw Moving Averages
analysis.sma_f.plot(ax=ax1, c='r')
analysis.sma_s.plot(ax=ax1, c='g')
#RSI
ax2 = fig.add_subplot(412)
ax2.set_ylabel('RSI', size=12)
analysis.rsi.plot(ax = ax2, c='g', label = 'Period: ' + str(context.RSI_PERIOD))
analysis.sma_r.plot(ax = ax2, c='r', label = 'MA: ' + str(context.RSI_AVG_PERIOD))
@@ -271,6 +272,7 @@ def chart(context, prices, analysis):
ax2.legend(handles, labels)
# Draw MACD computed with Talib
ax3 = fig.add_subplot(413)
ax3.set_ylabel('MACD: '+ str(context.MACD_FAST) + ', ' + str(context.MACD_SLOW) + ', ' + str(context.MACD_SIGNAL), size=12)
analysis.macd.plot(ax=ax3, color='b', label='Macd')
analysis.macdSignal.plot(ax=ax3, color='g', label='Signal')
@@ -280,6 +282,7 @@ def chart(context, prices, analysis):
ax3.legend(handles, labels)
# Stochastic plot
ax4 = fig.add_subplot(414)
ax4.set_ylabel('Stoch (k,d)', size=12)
analysis.stoch_k.plot(ax=ax4, label='stoch_k:'+ str(context.STOCH_K), color='r')
analysis.stoch_d.plot(ax=ax4, label='stoch_d:'+ str(context.STOCH_D), color='g')