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/

    Having trouble with multi setup

    General Code/Help
    1
    2
    31
    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
      t3chap last edited by

      Re: how to test multi data

      I saw this in an old post and am trying to get it to work correctly.

      I'm trying to generate ADX and ATR values for my symbols. I create a list with the symbols in it.

      I don't have the whole thing built; I was trying to build step-by-step but I must be doing something wrong as the ADX and ATR seems to be calculated for the first symbol in the list . The data shows that it is different in the graph but the indicators don't for some reason.
      Can anyone point me in the right direction?

      import backtrader as bt
      import pandas as pd
      import barchart_data as bd
      
      class ADX_C(bt.Strategy):
          params = {"n": 25}
          def __init__(self):
              """initialize the strategy"""
              self.adx = dict()
              self.atr = dict()
              
              for dat in self.datas:      
                  self.adx[dat] = bt.indicators.ADX(period = self.params.n, plot=True)
                  self.atr[dat] = bt.indicators.ATR(period = self.params.n, plot=True)
      
      
      
      symbols=["ZROZ","XMPT"]
      min_per_bar=1440
      begin_date = '2019-01-01'
      end_date = '2020-06-11'
      
      cerebro = bt.Cerebro()
      
      for s in symbols:
          data = bd.BarchartData(s,min_per_bar).data_by_dates(begin_date,end_date)
          bt_data = bt.feeds.PandasData(dataname=data, name = s)
          cerebro.adddata(bt_data, name = s)
          
          
      cerebro.addstrategy(ADX_C)
      cerebro.run()
      cerebro.plot(iplot=True, volume=False, width=50, height=30, dpi=600)
      
      1 Reply Last reply Reply Quote 0
      • T
        t3chap last edited by

        I feel like an idiot; I finally figured out that I wasn't passing data to the bt.indicators.ADX and ATR statements. Apparently the system uses the first data for any subsequent calls if you don't send it new data.

          self.adx[dat] = bt.indicators.ADX(dat, period = self.params.n, plot=True)
        self.atr[dat] = bt.indicators.ATR(dat, period = self.params.n, plot=True)
        

        Is the correct formulation of those two lines.

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