Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    I believe I found a bug

    General Discussion
    1
    3
    131
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      dindom999 last edited by

      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')
      

      BTW, why https://github.com/mementum/backtrader disable "issues"

      1 Reply Last reply Reply Quote 0
      • D
        dindom999 last edited by

        60minutes view is obviously wrong
        Figure_0.png image url)

        1 Reply Last reply Reply Quote 0
        • D
          dindom999 last edited by

          I have fix this bug, check here:

          https://github.com/backtrader2/backtrader/pull/84/commits/3774134099fa6996d8a30f1654db2b830e732c70

          1 Reply Last reply Reply Quote 1
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors