timeData.set_TD_from_google("AAPL", 5, "3d") #####################################################################3 timeData.set_interval(sdate, edate) opentime, closetime = timeData.guess_openMarketTime() period = timeData.guess_period() print "Period: %f" % period print "Market Hours " + str(opentime) + " - " + str(closetime) dataTransform = ["intraday", opentime, closetime] #dataTransform = None dataHLOC = timeData.get_timeSeries(["High", "Low", "Open", "Close"]) dates = timeData.get_dates() gl.barchart(dates, dataHLOC, lw=2, dataTransform=dataTransform, color="k", AxesStyle="Normal") ## Define IDs event_type = "NewAvailableData" eventID = "AAPL_M5" handlerID = "handler1" ### Define the event dataEvent = dict() dataEvent["symbolID"] = "AAPL" dataEvent["period"] = 5 dataEvent["src"] = "Google" myEvent = eSL.CEvent(event_type=event_type, data=dataEvent, eventID=eventID)
colorBB1 = "cobalt blue" colorBB2 = "irish green" ## Plotting t the BB !! ax1 = gl.subplot2grid((5, 1), (0, 0), rowspan=4, colspan=1) # gl.plot(dates, price, ax = ax1, AxesStyle = "Normal - No xaxis", # labels = ["Volatility indicator BB", "", "Price"], # legend = ["Price"], color = "dark navy blue") title = "Bollinger Bands. " + str( symbols[0]) + "(" + ul5.period_dic[timeData.period] + ")" ##### The problem is that we are using dataTrasnform so the X axis is not being transformed into integers ##### but fed directly, we need to still make such a transformation for this to work? gl.barchart(dates, dataHLOC, ax=ax1, color=color1, labels=[title, "", r"Price ($\$$)"], legend=["HLOC Price"]) BBs = np.concatenate([BB1[:, [0]], BB1[:, [1]]], axis=1) gl.plot(dates, SMA1, color=colorBB1, legend=["0.95 BB(%i)" % nBB1]) gl.plot(dates, BBs, color=colorBB1, ls="--") gl.plot_filled( dates, BBs, color=colorBB1, alpha=0.1, AxesStyle="Normal - No xaxis", ) gl.plot(dates, BBs, color=colorBB1, ls="--")
period=period1, maxPullback=maxPullback) exitcrosses2, all_stops2, pCheckCross2, datesExit2 = mySalida2.get_TradeSignals( ) ########## Plotting ! #################### gl.set_subplots(3, 1) ## Price Axes ax1 = gl.plot(dates, price, legend=["Price"], labels=["Crossing MA Strategy", "", "Price"], alpha=0, nf=1) gl.barchart(dates, dataHLOC) gl.plot(dates, EMAslow, legend=["Slow"], lw=1, color="b") gl.plot(dates, EMAfast, legend=["fast"], lw=1, color="r", xaxis_mode="hidden") ## Entry Axes ax2 = gl.plot(dates, ul.scale(EMAfast - EMAslow), legend=["Difference"], nf=1, sharex=ax1, labels=["", "", "Events"], fill=1, alpha=0.3) gl.stem(dates, crosses, legend=["TradeSignal"]) gl.scatter(dates, ul.scale(EMAfast - EMAslow), lw=0.5, alpha=0.5)
precision="m", start_date=dt.datetime(2016, 1, 1), end_date=dt.datetime(2017, 1, 1)) TD_google = gdl.download_TD_google("AAPL", period_seconds=60 * 1440 * 7, timeInterval="15d") TD_google = gdl.download_D1_TD_google("AAPL", sdate, edate) timeData.set_TD(TD_google) timeData.set_TD_from_google("ONT", 5, "10d") #####################################################################3 timeData.set_interval(sdate, edate) opentime, closetime = timeData.guess_openMarketTime() period = timeData.guess_period() print "Period: %f" % period print "Market Hours " + str(opentime) + " - " + str(closetime) dataTransform = ["intraday", opentime, closetime] #dataTransform = None dataHLOC = timeData.get_timeSeries(["High", "Low", "Open", "Close"]) dates = timeData.get_dates() gl.barchart(dates, dataHLOC, lw=2, dataTransform=dataTransform, color="k", labels=[symbols[0], "", "Price"], legend=[symbols[0]], AxesStyle="Normal")
gl.set_subplots(4,1) ############# 1: Basic Time Series and Volume seriesNames = ["Average", "High"] dataHLOC = timeData.get_timeSeries(["High","Low","Open","Close"]) prices = timeData.get_timeSeries(seriesNames); dates = timeData.get_dates() volume = timeData.get_timeSeries(["Volume"]); Returns = timeData.get_timeSeriesReturn(seriesNames = ["Close"]); CumReturns = timeData.get_timeSeriesCumReturn(seriesNames = ["Close"]); nSMA = 10 SMA = timeData.SMA(n = nSMA) ax1 = gl.plot(dates, SMA, labels = [timeData.symbolID + str(timeData.period), "Time", "Price"], legend = ["SMA(%i)" % nSMA], nf = 1, dataTransform = dataTransform, AxesStyle = "Normal - No xaxis", color = "cobalt blue") gl.barchart(dates, dataHLOC, lw = 2, dataTransform = dataTransform, color = "k", AxesStyle = "Normal - No xaxis") # Notice the Weekends and the displacement between bars and step ############# 2: Volume gl.stem(dates, volume, sharex = ax1, labels = [timeData.symbolID + str(timeData.period), "Time", "Volume"], legend = ["Volume"], nf = 1, alpha = 0.5, dataTransform = dataTransform, AxesStyle = "Normal - No xaxis") ############# 3: Returns gl.stem(dates, Returns, sharex = ax1, labels = [timeData.symbolID + str(timeData.period), "Time", "Return"], legend = ["Return"], nf = 1, dataTransform = dataTransform, AxesStyle = "Normal - No xaxis") ############# 4: Commulative Returns seriesNames = ["Close"]
BB2 = timeData.BBANDS(seriesNames = ["Close"], n = nBB2) SMA2 = timeData.SMA(n = nBB2) EMA1 = timeData.EMA(n = nBB1) BBE1 = timeData.BBANDS(seriesNames = ["Close"], MA = SMA1, n = nBB1) color1 = "k" colorBB1 = "cobalt blue" colorBB2 = "irish green" ## Plotting t the BB !! ax1 = gl.subplot2grid((5,1), (0,0), rowspan=4, colspan=1) # gl.plot(dates, price, ax = ax1, AxesStyle = "Normal - No xaxis", # labels = ["Volatility indicator BB", "", "Price"], # legend = ["Price"], color = "dark navy blue") title = "Bollinger Bands. " + str(symbols[0]) + "(" + ul.period_dic[timeData.period]+ ")" gl.barchart(dates, dataHLOC, ax = ax1, color = color1, labels = [title, "", r"Price ($\$$)"], legend = ["HLOC Price"]) BBs = np.concatenate([BB1[:,[0]],BB1[:,[1]]],axis = 1) gl.plot(dates, SMA1, color = colorBB1, legend = ["0.95 BB(%i)"%nBB1]) gl.plot(dates, BBs, color = colorBB1, ls = "--") gl.plot_filled(dates, BBs, color = colorBB1, alpha = 0.1, AxesStyle = "Normal - No xaxis",) gl.plot(dates, BBs, color = colorBB1, ls = "--") gl.plot_filled(dates, BBs, color = colorBB1, alpha = 0.1, AxesStyle = "Normal - No xaxis",)
period = period1, maxPullback = maxPullback) exitcrosses, all_stops, pCheckCross, datesExit = mySalida.get_TradeSignals() # Second Signal mySalida2 = CTS.CTrailingStop("salircaca",period1,Cartera) secondEntrySingal = EntrySignals[1] mySalida2.set_trailingStop(SymbolName = symbol,BUYSELL = secondEntrySingal.BUYSELL, datetime = secondEntrySingal.datetime, period = period1, maxPullback = maxPullback) exitcrosses2, all_stops2, pCheckCross2, datesExit2 = mySalida2.get_TradeSignals() ########## Plotting ! #################### gl.set_subplots(3,1) ## Price Axes ax1 = gl.plot(dates,price, legend = ["Price"], labels = ["Crossing MA Strategy", "","Price"], alpha = 0, nf = 1) gl.barchart(dates, dataHLOC) gl.plot(dates,EMAslow, legend = ["Slow"], lw = 1, color = "b") gl.plot(dates,EMAfast, legend = ["fast"], lw = 1, color = "r", xaxis_mode = "hidden") ## Entry Axes ax2 = gl.plot(dates, ul.scale(EMAfast - EMAslow), legend = ["Difference"] ,nf = 1, sharex = ax1, labels = ["","","Events"], fill = 1, alpha = 0.3) gl.stem(dates,crosses, legend = ["TradeSignal"] ) gl.scatter(dates, ul.scale(EMAfast - EMAslow), lw = 0.5, alpha = 0.5) gl.plot(dates,np.zeros(crosses.shape)) ## Exit Axes gl.add_hlines(datesExit, all_stops, ax = ax1, legend = ["TrailingStop"], alpha = 0.8, lw = 0.2) ax3 = gl.plot(datesExit, ul.scale(-(all_stops - pCheckCross)), legend = ["TrailingStop"] ,nf = 1, sharex = ax1, labels = ["","","TrailingStop"], lw = 0.5, alpha = 0.5, fill = 1)
############# 1: Basic Time Series and Volume seriesNames = ["Average", "High"] dataHLOC = timeData.get_timeSeries(["High","Low","Open","Close"]) prices = timeData.get_timeSeries(seriesNames); dates = timeData.get_dates() volume = timeData.get_timeSeries(["Volume"]); Returns = timeData.get_timeSeriesReturn(seriesNames = ["Close"]); CumReturns = timeData.get_timeSeriesCumReturn(seriesNames = ["Close"]); nSMA = 10 SMA = timeData.SMA(n = nSMA) ax1 = gl.plot(dates, SMA, labels = [timeData.symbolID + str(timeData.period), "Time", "Price"], legend = ["SMA(%i)" % nSMA], nf = 1, dataTransform = dataTransform, AxesStyle = "Normal - No xaxis", color = "cobalt blue") gl.barchart(dates, dataHLOC, lw = 2, dataTransform = dataTransform, color = "k", AxesStyle = "Normal - No xaxis", legend = ["OHCL"]) # Notice the Weekends and the displacement between bars and step ############# 2: Volume gl.stem(dates, volume, sharex = ax1, labels = ["", "Time", "Volume"], legend = ["Volume"], nf = 1, alpha = 0.8, dataTransform = dataTransform, AxesStyle = "Normal - No xaxis") ############# 3: Returns gl.stem(dates, Returns, sharex = ax1, labels = ["", "Time", "Return"], legend = ["Return"], nf = 1, dataTransform = dataTransform, AxesStyle = "Normal - No xaxis") ############# 4: Commulative Returns seriesNames = ["Close"]