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

How to do intraday trading in backtrader ?



  • Suppose I just want to do intraday trading then how can I do it using timers or filters.I can do it any way by handling the datetime object and check if current time falls within the intraday timing then only i will execute the buy or sell signals but I want some smart way or inbuilt functionality to do it.
    And how to forcefully execute or close all the open orders if these signals(buy,sell) crossed the intraday time limit ?


  • administrators

    @ry-93 said in How to do intraday trading in backtrader ?:

    Suppose I just want to do intraday trading then how can I do it using timers or filters

    By using intraday data (i.e.: sub-day timeframe)

    @ry-93 said in How to do intraday trading in backtrader ?:

    I can do it any way by handling the datetime object and check if current time falls within the intraday timing then only i will execute the buy or sell signals but I want some smart way or inbuilt functionality to do it.

    Each data feed carries a timestamp which can be converted to a datetime.datetime and/or datetime.time instance to let you know what the current time is in Python format. For example

    cur_dt = self.data.datetime.datetime(0)  # get current datetime
    cur_tm = self.data.datetime.time(0)  # get current time
    

    You may of course get the time component from thedatetimeobject if you prefer.

    @ry-93 said in How to do intraday trading in backtrader ?:

    And how to forcefully execute or close all the open orders if these signals(buy,sell) crossed the intraday time limit ?

    Keep a reference to the orders you have issued, check the time and when your deadline is met, issue a cancel on the orders which have not been executed yet (i.e.: not remove from your list, because they have been notified as Completed)