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/

    Keep getting error module 'backtrader' has no attribute 'Timeframe'

    General Code/Help
    2
    2
    242
    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.
    • B
      BMccoy last edited by

      Hello

      I keep getting the following error module 'backtrader' has no attribute 'Timeframe'

      I am trying to plot using intraday data and not many really good samples out there. Plotting daily data is fine
      Code is as follows

      import os, sys, argparse
      import backtrader as bt
      import backtrader.analyzers as btanalyzers
      import matplotlib
      from datetime import datetime
      import backtrader.feeds as btfeeds

      data = bt.feeds.GenericCSVData(
      dataname='C:/Users/brand/NQ21.csv',
      datetime=0,
      fromdate=datetime(2021, 1, 3),
      timeframe=bt.TimeFrame.Minutes,
      dtformat=('%Y-%m-%d %H:%M:%S'),
      open=1,
      high=2,
      low=3,
      close=4,
      )
      class Mystrat(bt.Strategy):

      def __init__(self):
          self.the_highest_high_4 = bt.ind.Highest(self.data.high, period=4)
          self.the_lowest_low_4 = bt.ind.Lowest(self.data.low, period=4)
      

      cerebro = bt.Cerebro()

      data = bt.feeds.YahooFinanceData(dataname = 'NQ20.csv')
      cerebro.adddata(data)

      cerebro = bt.Cerebro()
      cerebro.adddata(data, timeframe=bt.Timeframe.Minutes, compression=5)
      cerebro.addstrategy(Mystrat)
      cerebro.run()
      cerebro.plot(style='bar')

      run-out 1 Reply Last reply Reply Quote 0
      • run-out
        run-out @BMccoy last edited by

        @bmccoy said in Keep getting error module 'backtrader' has no attribute 'Timeframe':

        Timeframe

        Try TimeFrame

        RunBacktest.com

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