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/

    How to add Indicator over resampled data? E.g. 10-day sma for minute data

    Indicators/Strategies/Analyzers
    2
    2
    1251
    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.
    • X
      xnox last edited by

      Hello,

      I'm trying to use btrun, and code a generic strategy which I can control with btrun. My data is typically minute bars, however, in the strategy, I would like to use a 10-day indicator. How can I do this in the strategy? Or btrun options?

      If I script against celebro directly, I would add data0 as usual, then call resampledata to generate resampled data1, and then in the strategy add sma indicator with period=10 against data1.

      Somehow, I wish any indicator could be added with data resampling, e.g.
      self.sma = bt.indicators.SimpleMovingAverage(self.data, resample=bt.TimeFrame.Days, period=self.params.sma)

      I've now tweaked btrun locally to always add data first, and then add resampled one too. Such that I get the minute and daily data feeds for indicators to work on, but this seems extra work.

      I guess I could do sma over 1440... but that assumes 24h trading with no missing minutes and is not the same as resampling to days first, and then doing 10-day sma.

      Regards,

      Dimitri.

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @xnox last edited by

        @xnox said in How to add Indicator over resampled data? E.g. 10-day sma for minute data:

        I'm trying to use btrun, and code a generic strategy which I can control with btrun. My data is typically minute bars, however, in the strategy, I would like to use a 10-day indicator. How can I do this in the strategy? Or btrun options?

        If the only data feed in the strategy is has a Minutes/x timeframe/compression specification, you cannot have an indicator calculating in days.

        self.sma = bt.indicators.SimpleMovingAverage(self.data, resample=bt.TimeFrame.Days, period=self.params.sma)

        That's not possible. An indicator can run several levels deep and only be accessing data which has not datetime information. An indicator is a dumb math calculator.

        I guess I could do sma over 1440... but that assumes 24h trading with no missing minutes and is not the same as resampling to days first, and then doing 10-day sma.

        You need to resample the minutes-data-feed to Days/1 and then create the indicator on that data feed.

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