Backtrader Community

    • 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/

    Get historical data dynamically before cerebro.run()

    Indicators/Strategies/Analyzers
    1
    1
    83
    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.
    • Federico Bld
      Federico Bld last edited by

      I have to lunch strategies with serveral feeds with different timeframes.
      I didn't find the way to get "minpediod" to calculate "hist_start_date" variable.

      # My formula shuld be look like:
      minutes_of_one_candle = get_compression_in_minutes_from_timeframe(assetTimeframe,assetCompression)
      minperiod = # I don't know how to retrieve the "minperiod" from the strategy with custom 
      timeAgoInMinutes = minperiod * minutes_of_one_candle 
      

      Follows the complete code

      
      strategies_list = [sma_200minperiod_strategy,
                         ema_5minperiod_strategy]
      assets = [
          ['ticker1', 1, 'minutes',]
          ['ticker2', 30, 'minutes',]
          ['ticker3', 1, 'hours',]
          ['ticker4', 1, 'days',]
      ]
      for strategy in strategies_list:
          cerebro.addstrategy(strategy=strategy, **get_strategyParams(strategy))
      
          for assetName in assets:
              dataname =assetName[0]
      
              assetTimeframe = get_bt_TimeFrame(assetName[2])
              assetCompression = get_bt_compression(assetName[1])
              assetCompression_in_Minutes = get_compression_in_minutes(assetTimeframe , assetCompression)
      
              minutes_of_one_candle = get_compression_in_minutes_from_timeframe(assetTimeframe,assetCompression)        
              minperiod = # I don't know how to retrieve the "minperiod" from the strategy with custom parameters
              timeAgoInMinutes = minperiod * minutes_of_one_candle         
      
              hist_start_date = datetime.utcnow() - timedelta(minutes=timeAgoInMinutes)
      
              data = store.getdata(
                                   dataname=dataname,
                                   timeframe=assetTimeframe,
                                   compression=assetCompression,
                                   fromdate=hist_start_date,  # <========
                                   ohlcv_limit=250,
                                   drop_newest=True)
      
              cerebro.adddata(data)
      

      How can I get minperiod to set fromdate = hist_start_date before cerebro.run()?

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