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



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



  • 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


  • 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.)



  • 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



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