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

Setting holding period

  • Hi, I'm new to backtrader and have been looking for solutions on preset holding period while backtesting.

    Here is what I'm looking to achieve:

    Suppose I have a strategy that says, go long a stock if condition A happens and go short a stock if condition B happens. For each position, the holding period of the trade is 1 month.

    Is there an easy way to do that?


  • administrators

    The logic in the strategy has to remember when a position was entered, probably in notify_order by checking the date from the notified order

    • order.executed.dt which can be translated to a datetime instance like this for example:`

    And then checking when the data hits a month later, where you can get instances with for example.

Log in to reply