Pass actions to execute into strategy



  • Imagine that strategy should sometimes listen to outer world, which could say when to buy or sell. Signals come with array of order object with fields: ticker, size, date, action (buy/sell).

    Strategy should load array of orders before start, execute them in their times and do nothing untill last order will be executed.

    How to pass array of order objects into Strategy?
    Using params? It's now params.
    Using maybe datas array?



  • You can build an indicator with necessary lines and trade based on it.


  • administrators

    This was outlined here: Community - Importing orders #219

    Your options:

    • The data feed contains the extra data. You then read it directly from the data feed

    • With separate data you load it into an indicator and check if the timestamp of the data feed matches the next timestamp of the action to be executed. And the indicator may signal with 1 (Buy) and -1 (sell), plus potentially extra lines for size, price and some other things.

    • As you point out ... you can pass it as a parameter to the strategy and do the check with the trading logic.

    The indicator solution seems the cleanest, because it does isolate data and logic.



  • Done! Thanks for ideas!


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.