Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. tx_562
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    T
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 7
    • Best 1
    • Groups 0

    tx_562

    @tx_562

    1
    Reputation
    33
    Profile views
    7
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    tx_562 Unfollow Follow

    Best posts made by tx_562

    • RE: AttributeError: module 'backtrader' has no attribute 'DataResampler'

      I figured it out, it looks like "DataResampler" was changed to "resampledata"

      read more here: https://www.backtrader.com/blog/posts/2016-03-07-release-1.2.1.88/release-1.2.1.88/

      The documentation here is possibly out of data -->https://www.backtrader.com/docu/data-resampling/data-resampling/

      The code I used for resampling 1-minute data into 6 hour data (6 hours = 360 mins):

      cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=360) # to weeks

      posted in General Code/Help
      T
      tx_562

    Latest posts made by tx_562

    • RE: CrossOver value for boll.lines.top (lines object) always returns 0

      @run-out Thank you! Looks like 'high' is giving me the proper values. Would the 'self.data.close' price be the 'current price' if I'm running replaydata?

      posted in General Code/Help
      T
      tx_562
    • CrossOver value for boll.lines.top (lines object) always returns 0

      Running into an error where bt.ind.CrossOver(self.data.close, self.boll.lines.top) will always return 0, despite multiple crosses, however,
      bt.ind.CrossOver(self.data.close, self.boll) returns -1, 0, and 1 values properly. It doesn't seem to return any values from the 'lines' object?

      def __init__(self):
          self.boll = bt.ind.BollingerBands(period=3, devfactor=2)
          self.tcrx = bt.ind.CrossOver(self.data.close, self.boll.lines.top)
      
      def next(self):
          print(self.tcrx[0])
      
      posted in General Code/Help
      T
      tx_562
    • RE: What are different between bta-lib, ta-lib and internal BackTrader indicators?

      @run-out said in What are different between bta-lib, ta-lib and internal BackTrader indicators?:

      The last library is the very newly minted bta-lib. This was created by the maker of backtrader as a handy library for doing technical analysis when using pandas dataframes. In a nutshell, you can put in a OHLCV dataframe and BTA-LIB will spit out the indicator. It works quite well and is easier to use that the original ta-lib library.

      Does bta-lib interact with the backtrader framework? Or is it meant to be used seprately?

      posted in bta-lib
      T
      tx_562
    • Conditional If statement not executing under the next(self)

      I can't seem to get my conditional if statement to work!

      It works properly with ONE condition (both seem to work), however nothing happens once I introduce TWO comparisons with the AND operator.

      def next(self):
          if not self.position:
              if self.data.close[0] >= self.mov[0] and self.data.close[0] >= self.boll.lines.top[0]:
                  print(self.data.close[0], self.datetime.date(ago=0), self.datetime.time(ago=0))
          else:
              print('nothing to print! ')
      

      I don't get an error, but nothing seems to output. Not even the else statement.

      posted in General Code/Help
      T
      tx_562
    • RE: AttributeError: module 'backtrader' has no attribute 'DataResampler'

      I figured it out, it looks like "DataResampler" was changed to "resampledata"

      read more here: https://www.backtrader.com/blog/posts/2016-03-07-release-1.2.1.88/release-1.2.1.88/

      The documentation here is possibly out of data -->https://www.backtrader.com/docu/data-resampling/data-resampling/

      The code I used for resampling 1-minute data into 6 hour data (6 hours = 360 mins):

      cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=360) # to weeks

      posted in General Code/Help
      T
      tx_562
    • RE: AttributeError: 'str' object has no attribute 'toordinal'

      I had a similar attribute error and I was also using Jupyter Notebook

      posted in General Code/Help
      T
      tx_562
    • AttributeError: module 'backtrader' has no attribute 'DataResampler'

      Hey everyone!

      running into an issue here attempting to load backtrader on Python 3.8.2:

      AttributeError: module 'backtrader' has no attribute 'DataResampler'

      My file has a unique name that wouldn't collide with other names, any idea what is going on here?

      Thanks!

      import os, sys, argparse
      import pandas as pd
      import backtrader as bt
      import backtrader.feeds as btfeeds
      import backtrader.indicators as btindicators
      import datetime
      import matplotlib as plt
      import math
      
      %matplotlib inline
      
      cerebro = bt.Cerebro()
      cerebro.broker.setcash(1000)
      
           
      class GoldenCross(bt.Strategy):
          params = (('fast', 50), ('slow', 200), ('order_percentage', 0.95), ('ticker', 'ETHUSD'))
          
          def __init__(self):
              self.fast_moving_average = bt.indicators.SMA(self.data.close, period=self.params.fast, plotname='50 dma')
      
              self.slow_moving_average = bt.indicators.SMA(self.data.close, period=self.params.slow, plotname='200 dma')
              
              self.crossover = bt.indicators.CrossOver(self.fast_moving_average, self.slow_moving_average)
              
              def next(self):
                  if self.position.size == 0:
                      if self.crossover > 0:
                          self.buy(size=1000)
                          
                  elif self.position.size > 0:
                      if self.crossover < 0:
                          print('SELL {} shares of {} at {}'.format(self.size, self.params.ticker, self.data.close[0]))
                          self.close()
                              
      data = btfeeds.GenericCSVData(
          dataname=r'C:\Users\steve\Desktop\ethusd.csv',
      
          fromdate=datetime.datetime(2020, 1, 1),
          todate=datetime.datetime(2020, 5, 17),
      
          nullvalue=0.0,
          dtformat=('%Y-%m-%d %H:%M:%S'),
          datetime=0,
          high=3,
          low=4,
          open=2,
          close=5,
          volume=7,
          openinterest=-1
      )
      
      # Handy dictionary for the argument timeframe conversion
      tframes = dict(
          daily=bt.TimeFrame.Days,
          weekly=bt.TimeFrame.Weeks,
          monthly=bt.TimeFrame.Months)
      
      # Resample the data
      data_resampled = bt.DataResampler(
          dataname=data,
          timeframe=tframes[args.timeframe],
          compression=args.compression)
          
          
      cerebro.adddata(data_resampled)
      cerebro.addstrategy(GoldenCross)
      cerebro.run()
      
      cerebro.plot()
      
      posted in General Code/Help
      T
      tx_562