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

Backfilling - Live Trading

  • When using the back-filling option for live trading, Backtrader will still request historical data for the instrument you are trading. This is great for filling up your indicators minperiod

    However, Backtrader will also open and close orders as it loops through the historical data.

    Just wondering how others are working around this? I have created a self.start_date attribute during __init__() ( and then I simply return from next() if the data date is not > than the start_date

    Just curious if anyone is using a different, more elegant solution?

    Also my solution can run into problems it you are not in the same timezone as your data feed provider. To workaround this, I have had to add some further hacky time zone conversion. i.e:

    self.start_date =

  • @ThatBlokeDave said in Backfilling - Live Trading:

    However, Backtrader will also open and close orders as it loops through the historical data.

    It seems you are blaming the devil instead of your code, which is the executor (unless the platform has achieved self-consciousness)

    Live feeds deliver a data.LIVE status notification when backfilling is over and real-time data is delivered. You can find it at least here:

    The sources for the ibtest sample show how to tackle that.

  • @Paska-Houso

    Not blaming anything. Just reporting what I am seeing.

    Thanks for the pointer - I will take a look.

  • Not intended to criticize, it just seemed funny that the platform would be opening and closing orders without any external intervention.

  • @Paska-Houso

    No worries. I probably was not clear. I was not sure how to stop next() being called before the live data. Naturally the code to open a position is in my next() method. :)

    Anyway, I will take a look at your suggestion. I do appreciate it.

Log in to reply

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