For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Indicators outside of strategy?

  • I am looking to train a machine learning model prior to feeding it into a strategy, which requires being able to generate the indicators on a Pandas DataFrame prior to running the backtest or adding data to the strategy (since I need indicator values on out of sample data). Is there any way to do this? I know you can do this with ta-lib, but do not see any way to do this with the BT indicators. BT has some indicators that ta-lib does not. Thanks!

  • Hi Eric,
    You can implement your strategy with all your indicators. In the next() function, you can spool the OHLCV + all your indicators for every bar (or store these values into a structure) and write all these to a file at the end of your backtest (self.stop() method)


  • administrators

    The indicators are tightly coupled to support things like managing different timeframes, remain synchronized to the data, play well with replay and resample.

    Using them outside of a strategy is not possible. You can follow the path recommended by @lampalork or wait a bit until things get settled with bta-lib:

  • @lampalork Thats a good idea, thank you!

Log in to reply