Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: resample and plot error #83

Open
dindom999 opened this issue Dec 16, 2021 · 1 comment
Open

bug: resample and plot error #83

dindom999 opened this issue Dec 16, 2021 · 1 comment

Comments

@dindom999
Copy link

It happened when resample 5m to 60m and plot. I am not sure it's from resampling or plotting. Any one can reproduce it by using the sample data in source code.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import time

import backtrader as bt

class St(bt.Strategy):
    params = dict(multi=True)

    def __init__(self):
        self.pp = pp = bt.ind.PivotPoint(self.data1)
        pp.plotinfo.plot = False  # deactivate plotting

        if self.p.multi:
            pp1 = pp()  # couple the entire indicators
            self.sellsignal = self.data0.close < pp1.s1
        else:
            self.sellsignal = self.data0.close < pp.s1()

    def next(self):
        txt = ','.join(
            ['%04d' % len(self),
             '%04d' % len(self.data0),
             '%04d' % len(self.data1),
             self.data.datetime.date(0).isoformat(),
             '%.2f' % self.data0.close[0],
             '%.2f' % self.pp.s1[0],
             '%.2f' % self.sellsignal[0]])

        print(txt)

cerebro = bt.cerebro.Cerebro()
# Data feed
data_file = r"D:\tmp\backtrader\datas\2006-min-005.txt"  # D:\tmp\backtrader\datas is where the backtrader source folder
data0 = bt.feeds.BacktraderCSVData(dataname=data_file,  timeframe=bt.TimeFrame.Minutes, compression=5)
cerebro.adddata(data0)

cerebro.resampledata(data0, timeframe=bt.TimeFrame.Minutes, compression=60)

cerebro.addanalyzer(bt.analyzers.Returns, _name="RE")
cerebro.addanalyzer(bt.analyzers.TradeAnalyzer, _name="TA")

cerebro.addstrategy(St)
btrs1 = cerebro.run()

pstart=0
pend=100

cerebro.plot(start=pstart, end=pend, style='candle')

60minutes view is obviously incorrect

image

But when I change plot end to 200
pstart=0 pend=200
It's correct now.
Figure_0

@dindom999
Copy link
Author

I have fix this bug and fire a pull requests https://github.com/backtrader2/backtrader/pull/84/commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant