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/

    Using my own pre-calculated indicators

    General Discussion
    4
    5
    3060
    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.
    • J
      JMT last edited by

      I have a Pandas dataframe which contains my Open, High, Low, Close, Volume columns at minutely resolution. I will load this custom data-set into Backtrader. In addition, I have my own indicators/signals pre-calculated for every minutely time-step.

      Having already skimmed the Platform Concepts (https://www.backtrader.com/docu/concepts.html) in the documentation, I haven't been able to see how best to load my own pre-calculated signals.

      Please could someone point me to the correct place in the documentation, or share a code snippet? Sorry if this is a duplicate topic, happy to be pointed to the best original topic also.

      Thank you very much in advance.

      1 Reply Last reply Reply Quote 0
      • vbs
        vbs last edited by

        I am quite new to this myself but two ideas:

        • either use your precalculated data to fake a regular data feed and add it to the strategy. E.g. put your indicator values to the feed's closes value or something
        • or implement a simple indicator that just loads the precalculated data from a file (csv?). I am not aware that such an indicator already exists
        1 Reply Last reply Reply Quote 0
        • H
          hobart-liu last edited by

          check the link below
          https://www.backtrader.com/docu/datafeed.html

          this is my test code

          class MyDataFeed(btfeeds.GenericCSVData):
          
              lines = ('aaa','bbb','ccc')
          
              params = (
                  ('nullvalue', 0.0),
                  ('dtformat', ('%Y-%m-%d %H:%M:%S')),
          
                  ('datetime', 0),
                  ('time', -1),
                  ('open', 1),
                  ('close', 2),
                  ('high', 3),
                  ('low', 4),
                  ('volume', 5),
                  ('aaa', 6),
                  ('bbb', 7),
                  ('ccc', 8)
                  ('openinterest', -1),
                  ('timeframe', bt.TimeFrame.Minutes)
              )
          

          (BTW, I am learning this framework too.)

          1 Reply Last reply Reply Quote 0
          • J
            JMT last edited by

            Thanks guys - I did infact solve this precisely as you suggested.

            I'm having trouble getting this to work with Pandas but works fine with GenericCSVData.

            More information is here:
            https://www.backtrader.com/docu/extending-a-datafeed.html

            1 Reply Last reply Reply Quote 0
            • P
              Paska Houso last edited by

              For PandasData you probably want to see this thread and the mention of the datafields attribute.

              • https://community.backtrader.com/topic/158/how-to-feed-backtrader-alternative-data/
              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors