dataHLOC = Cartera.get_timeData(symbolID, period1).get_timeSeries( ["High", "Low", "Open", "Close"]) dates = Cartera.get_timeData(symbolID, period1).get_dates() ########## Plotting ! #################### gl.set_subplots(2, 1) ax1 = gl.plot(dates, price, legend=["Price"], labels=["Crossing MA Strategy", "", "Price"], nf=1) gl.plot(dates, EMAslow, legend=["Slow"], lw=3) gl.plot(dates, EMAfast, legend=["fast"]) 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)) gl.subplots_adjust(left=.09,
## 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"],
crosses, dates = myEstrategia.get_TradeSignals() ########## Signals simulation #################### EMAslow = Cartera.get_timeData(symbolID,period1).EMA(n = Lslow) EMAfast = Cartera.get_timeData(symbolID,period1).EMA(n = Lfast) price = Cartera.get_timeData(symbolID,period1).get_timeSeries() dates = Cartera.get_timeData(symbolID,period1).get_dates() ########## Plotting ! #################### gl.set_subplots(2,1) ax1 = gl.plot(dates,price, legend = ["Price"], labels = ["Crossing MA Strategy", "","Price"], nf = 1) gl.plot(dates,EMAslow, legend = ["Slow"], lw = 3) gl.plot(dates,EMAfast, legend = ["fast"]) 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)) gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.10, hspace=0.01) trade_events = myEstrategia.get_TradeEvents() # We can observe the apparent delay ! #crosses, dates = Hitler.RobustXingAverages(symbols[0], Ls_list,Ll_list) #
dates = Cartera.symbols[symbol1].TDs[period1].get_dates() ########## Plotting ! #################### gl.set_subplots(4,1) ## Plot both prices and EMAs ax1 = gl.plot(dates,price, legend = ["Price"], labels = ["Crossing MA Strategy", "","Price"], alpha = 0, nf = 1) title = "Bar Chart. " + str(symbols[0]) + "(" + ul.period_dic[timeData.period]+ ")" timeData = Cartera.symbols[] gl.tradingBarChart(timeData, ax = ax1, legend = ["Close price"], color = "k", labels = [title,"",r"Price ($\$$)"], AxesStyle = "Normal - No xaxis") 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)) # We can observe the apparent delay ! #crosses, dates = Hitler.RobustXingAverages(symbols[0], Ls_list,Ll_list) #
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) gl.stem(datesExit,exitcrosses, legend = ["TradeSignal"] ) gl.scatter(datesExit, ul.scale(-(all_stops - pCheckCross)), lw = 0.5, alpha = 0.5) gl.add_hlines(datesExit2, all_stops2, ax = ax1, legend = ["TrailingStop2"], alpha = 0.8, lw = 0.2) gl.plot(datesExit2, ul.scale(all_stops2 - pCheckCross2), legend = ["TrailingStop2"], lw = 0.5, alpha = 0.5, fill = 1)