pythonbacktrader

Backtrader - trades not lining up on .plot


I am trying to learn backtrader, but when using my own data (1 min. charts), I am having this issue, where the trades are not lining up with the graph. Graop

Don't mind the many trades, there is not set a proper strategy at the moment as I am just testing out and trying to learn backtrader. I have looked around and read the reply's for other people who were having same issue. What fixed it for them in most cases was to add stdstats=False and a BuySell observer.


cerebro = bt.Cerebro(stdstats=False)
cerebro.addobserver(bt.observers.BuySell)

I have also declared that my timeframe is minutes:


data = bt.feeds.GenericCSVData(
        dataname='BTCUSD2.csv',
        timeframe=bt.TimeFrame.Minutes,
        fromdate=datetime.datetime(2021, 1, 1),
        todate=datetime.datetime(2021, 1, 17),
        reverse=False)

I simply can't figure out what else might be wrong?


Solution

  • notice other reports of this kind o problem here:

    basically you need to change this line, and add barplot and bardist according documentation

    cerebro.addobserver(bt.observers.BuySell, barplot=True, bardist=0.0025)
    

    the value above 0.0025 is just an example.