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/

    Not plotting properly with almost identical data that does

    General Code/Help
    1
    1
    46
    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.
    • T
      typhereus last edited by

      I have two daily timeframe 10 day data sets (one that works and one that doesn't) which I am using to try to reduce this problem. One is example oracle data (A) which plots and buys properly and the other is fake ethusdt data (B) which doesn't buy or plot properly. The strategy is simply buy on day 3 close on day 7. I changed the dates so they are identical. The only data that is different are the prices.

      import backtrader
      
      class TheStrategy(backtrader.Strategy):
          def __init__(self):
              self.period = 0
      
          def next(self):
              self.period += 1
      
              if self.period == 3:
                  self.buy()
      
              if self.period == 7:
                  self.close()
      
      cerebro = backtrader.Cerebro()
      
      cerebro.broker.setcash(1000)
      
      print("Starting $ %.2f" % cerebro.broker.getvalue())
      
      # Get Data
      data = backtrader.feeds.GenericCSVData(dataname='ethusdt.csv', dtformat='%Y-%m-%d', openinterest=-1, volume=-1)
      #data = backtrader.feeds.GenericCSVData(dataname='oracle.csv', dtformat='%Y-%m-%d', openinterest=-1, volume=-1)
      
      # Add Data
      cerebro.adddata(data)
      
      # Add Strategy
      cerebro.addstrategy(TheStrategy)
      
      # Run
      cerebro.run()
      
      print("Final $ %.2f" % cerebro.broker.getvalue())
      
      cerebro.plot(volume=False)
      

      Oracle Data

      Date,Open,High,Low,Close
      1995-01-03,2.179012,2.191358,2.117284,2.117284
      1995-01-04,2.123457,2.148148,2.092592,2.135803
      1995-01-05,2.141975,2.148148,2.08642,2.092592
      1995-01-06,2.092592,2.154321,2.061728,2.117284
      1995-01-09,2.135803,2.179012,2.12963,2.179012
      1995-01-10,2.191358,2.216049,2.185185,2.185185
      1995-01-11,2.203704,2.216049,2.098765,2.12037
      1995-01-12,2.123457,2.12963,2.08642,2.104938
      1995-01-13,2.12963,2.145062,2.074074,2.080247
      

      Fake Eth Data (Same Dates)

      Date,Open,High,Low,Close
      1995-01-03,1892,1893,1887,1888
      1995-01-04,1888,1892,1886,1888
      1995-01-05,1888,1890,1885,1887
      1995-01-06,1887,1891,1887,1890
      1995-01-09,1889,1892,1889,1892
      1995-01-10,1892,1902,1892,1900
      1995-01-11,1900,1908,1899,1907
      1995-01-12,1907,1907,1901,1902
      1995-01-13,1901,1903,1901,1901
      

      (A) Oracle A Dataset (Oracle).PNG

      (B) Ethusdt
      B Data set.PNG
      As you can see the ETH plotting does not buy and does not plot. It seems this problem is impossible and would appreciate any info pointing in the right direction.

      Notes: For some reason the eth data shows dates on the bottom in the plot ( I dont know why).
      Note2: I even tried reducing the eth data down until it does plot, it seems that it plots properly when the prices where 3 digits, makes no sense.

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