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/

    Nothing happens when running cerebro

    General Code/Help
    2
    2
    76
    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.
    • Arta Asadi
      Arta Asadi last edited by

      Hi, I have written my code just like strategy example but it won't run anything. Please help me.
      Strategy code:

      class TestStrategy2(bt.Strategy):
      
          def log(self, txt, dt=None):
              ''' Logging function for this strategy'''
              dt = dt or self.datas[0].datetime.date(0)
              print('%s, %s' % (dt.isoformat(), txt))
      
          def __init__(self):
              # Keep a reference to the "close" line in the data[0] dataseries
              self.dataclose = self.datas[0].close
      
          def next(self):
              # Simply log the closing price of the series from the reference
              self.log('Close, %.2f' % self.dataclose[0])
      

      Datafeed:

      class PandasData(bt.feed.DataBase):
          #linesoverride = True  # discard usual OHLC structure
          # datetime must be present and last
          #lines = ('Signal',)
          params = (
              #('dtformat', '%Y-%m-%d'),
              #('datetime', -1),
              #('time', None),
              ('open', 1),
              ('high', 2),
              ('low', 3),
              ('close', 4),
              ('volume', 5),
              #('Signal', 6),
              ('timeframe', bt.TimeFrame.Days),
              ('compression', 1),
              ('openinterest', None)
          )
          # datafields = bt.feeds.PandasData.datafields + ([
          #     ('Signal')]
          # )
      
      

      Running:

      ready_data = PandasData(dataname=strategy_data2)
      cerebro = bt.Cerebro()
      cerebro.adddata(ready_data)
      cerebro.addstrategy(TestStrategy2)
      cerebro.broker.setcash(1000000000.0)
      cerebro.run()
      

      in the jupyter it gives this:

      [<__main__.TestStrategy at 0x150489c3ba8>]
      

      but running in normal file gives nothing. At least I want it to log the close, so, I can make that cerebro is working on my data.
      Please help me. Thanks

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        Your data feed has not datetime parameter.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }