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 Custom Indicators

    General Code/Help
    2
    3
    2114
    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.
    • H
      hnasser last edited by

      Hello all,

      Does anyone know where in the docs I can find support for using custom indicators pre-calculated ?
      What I am trying to do is use a csv file with the standard OHLCV columns but with another column (or two or three) which have pre-determined values and which will drive the trading/backtesting of the strategy.
      For example, the indicator value would be +15 at the close of one bar which would drive a position at the opening of the next one etc etc.
      Coding the strategy new in BackTrader would be quite cumbersome and so I'm looking to avoid it.
      Ideally I would be able to push this and start trading live using BackTrader using hourly signals but one thing at a time I guess !!

      Thanks

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

        One of the design goals of backtrader was to be able to quickly prototype things and that's why one can define and redefine what's in the data sources and things derived from the data sources.

        If your data already contains the information in the csv format, you simply need to extend one of the CSV data feeds to load your extra column and it will be available to you.

        This topic is therefore of course covered in the documentation: Extending a Data Feed

        You still need to tell CSVGenericData where your fields are. Have a look for it at Data Feed Reference

        There is a blog post documenting the birth of GenericCSVData: Blog Post

        In addition and maybe to full simulate an indicator you can wrap the extra data value in an indicator:

        class MyIndicator(bt.Indicator):
            lines = ('myline',)
        
            def __init__(self):
                self.lines.myline = self.data.myvaluename
        

        Where myvaluename is the name you will assign to the extra data value present in your feed.

        1 Reply Last reply Reply Quote 2
        • H
          hnasser last edited by

          Thank you @backtrader for your prompt response - this is fantastic.
          I will have a go today.

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