Navigation

    Backtrader Community

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

    Topics created by marsario

    • M

      YahooFinance
      General Discussion • yahoofinance typeerror filenotfound • • marsario

      1
      0
      Votes
      1
      Posts
      126
      Views

      No one has replied

    • M

      Store data from Indicators for later use
      Indicators/Strategies/Analyzers • • marsario

      4
      0
      Votes
      4
      Posts
      174
      Views

      run-out

      @marsario There have been a lot of conversations on this topic. Here is one I remember. https://community.backtrader.com/topic/2240/how-to-speed-up-almost-100-times-when-add-data-and-preload-data?_=1626988579575

      Try a thorough search through the community, I'm sure this topic has been bantied about a lot.

    • M

      math.log with linebuffer._LineDelay object
      Indicators/Strategies/Analyzers • • marsario

      9
      0
      Votes
      9
      Posts
      291
      Views

      run-out

      @marsario said in math.log with linebuffer._LineDelay object:

      self.lines.mean[0]= bt.Sum(self.change_sum)/len(self.weights)

      I think you are close. This line:

      self.lines.mean[0]= bt.Sum(self.change_sum)/len(self.weights)

      The self.change_sum is already a sum from the previous line. It's cummulative. So I think this line should read:

      self.lines.mean[0]= self.change_sum[0]/len(self.weights)

      Also, in your first line.

      self.close_log[0] = math.log(self.datas[0].close[0])

      Import math and try that. self.datas[0].close[0] is a scalar and math.log should work.

    • M

      YahooFinanceCSVData & "NVDA": not working
      General Code/Help • • marsario

      5
      0
      Votes
      5
      Posts
      264
      Views

      run-out

      @marsario I think you have a null string in your data and backtrader is unable to figure out what to do with it. Have a look at your file and search for an empty string. Backtrader needs a number/date or something else it knows what to do with.

    • M

      Custom indicator, how datas work in init
      Indicators/Strategies/Analyzers • • marsario

      5
      0
      Votes
      5
      Posts
      581
      Views

      M

      @run-out Amazing! Thanks a lot! All clear!

    • M

      AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Indicat' object has no attribute '_addobserver'
      Indicators/Strategies/Analyzers • • marsario

      2
      0
      Votes
      2
      Posts
      554
      Views

      M

      I just realized that I only created an indicator, but no strategy and they are two totally different things lol. All clear

    • M

      Multiple datafeeds with different start dates
      General Discussion • • marsario

      5
      0
      Votes
      5
      Posts
      651
      Views

      A

      iirc it should be enough if you first load the company with the earliest start date. It was long time ago, but I didn't do any special work with the index to backtest thru multiple tickers.

    • M

      Similar to Exponential Moving Average
      Indicators/Strategies/Analyzers • • marsario

      4
      0
      Votes
      4
      Posts
      122
      Views

      run-out

      Sorry I haven't seen that indicator. But it shouldn't be unreasonable to code. Let us know how your efforts go.

    • M

      Changing tickets orders leads to different results
      General Discussion • • marsario

      10
      0
      Votes
      10
      Posts
      175
      Views

      run-out

      @marsario I know that backtrader can be frustrating when you first start. Trust me I know. However, I would argue, after looking some more at your code, that you must first learn to walk before you run. And you are already trying to run.

      You need to take a step back and work through some of the examples.

      But if you insist on tackling a multi data/multi indicator dictionary strategy to start, here are a few more tips.

      Add in these loggers they will give you more information:

      def notify_order(self, order): self.log( "Order ref: {} / Type {} / Status {}".format( order.ref, "Buy" * order.isbuy() or "Sell", order.getstatusname() ) ) if order.status == order.Completed: self.holdstart = len(self) # if not order.alive() and order.ref in self.orefs: # self.orefs.remove(order.ref) def notify_trade(self, trade): """Provides notification of closed trades.""" dt = self.data.datetime.datetime() if trade.isclosed: print( "{} {} Closed: PnL Gross {}, Net {},".format( dt, trade.data._name, round(trade.pnl, 2), round(trade.pnlcomm, 1), ) )

      You don't need the try/except clause.

      When you add the loggers above, you will see you are getting margin notice. This means there's not enough cash. This is because you are trying to buy 100% of the cash value of the account and TSLA is rising. You need to use a percentage of the account. You could use Cheat On Open, but again, that's a bit advanced.

      The following makes no sense in backtrader.

      best_mo_data.open[1]

      The numbering goes 0, -1, -2, etc.

      IMHO, you need to read the docs and work on simpler examples.

      Good luck.

    • 1 / 1