can't get 2 timeframes to plot in 1 graph
-
Hi all,
I'm trying to run a strategy that uses 1 indicator and 2 timeframes, 1 long for the strategy and 1 short for stoploss. I know backtrader already has a built in mechanism for stoploss but I want to use it for live trading too so I need to have control over what to send to the brokerage when that happens.
I have 2 candles one for 240 minutes and another for 15 minutes.
I can see the results plotted as 2 graphs, but I only want the longer timeframe to be plotted. More over, the buy and sell arrows should be drawn on the longer candle, which isn't the case.this is the relevant code
# Create a cerebro entity cerebro = bt.Cerebro() # Add a strategy cerebro.addstrategy(EmaCross) data_ticks_long = bt.feeds.CCXT( exchange='binance', symbol='BTC/USDT', name='EMA 21', timeframe=bt.TimeFrame.Minutes, fromdate=FROM_DATE, todate=TO_DATE, historical='True', compression=STRATEGY_CANDLE_SIZE_IN_MINUTES) data_ticks_short = bt.feeds.CCXT( exchange='binance', symbol='BTC/USDT', name='STOP_LOSS', timeframe=bt.TimeFrame.Minutes, fromdate=FROM_DATE, todate=TO_DATE, historical='True', compression=STOPLOSS_CANDLE_SIZE_IN_MINUTES) # Add the Data Feed to Cerebro cerebro.adddata(data_ticks_short) cerebro.adddata(data_ticks_long) # Set our desired cash start cerebro.broker.setcash(STARTING_BALANCE) # Add a FixedSize sizer according to the stake cerebro.addsizer(bt.sizers.PercentSizer,percents=95) # Set the commission cerebro.broker.setcommission(commission=COMMISION) # Print out the starting conditions print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) # Run over everything cerebro.run() # Print out the final result print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue()) # Plot the result # cerebro.plot(style='candlestick', barup='green', bardown='red') cerebro.plot()
I tried using plotinfo.sameaxis = True or plotinfo.plotmaster but it throws a
KeyError: <backtrader.feeds.ccxt.CCXT object at 0x7fe9e2959250>Any help would be really appreciated!
-
I can always add this to show only the shorter timeframe graph
data_ticks_long.plotinfo.plot=False
so I guess my question is how can I get both the strategy line and buy/sell signals to show on the long timeframe graph instead ?