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

Different data timeframes for Strategy and Order Execution



  • Hi all,
    I'm new to BackTrader (and Python) and perhaps this is a stupid question, but I couldn't find anywhere an example where my strategies/indicators use daily data but the orders are executed based on a intraday 1-min line. I have both lines coming from a Postgres DB into a pandas DF thus, no resampling is needed.

    Can someone, please, point me towards an example like that? I'm trying for a week myself to concoct a toy example with no luck so far...

    Cheers!



  • I don't remember any specific example on this, but you just need to refer to daily data feed in your indicators, but issue orders referencing 1 min data feed. How to use particular data feed in the indicators and orders is shown in the docs:

    Docs - Using indicators
    Docs - Orders
    Docs - Order Management and Execution



  • @ab_trader
    Thank you, but I looked at all the examples in the docs and also the blog entries, couldn't find anything similar. It does make sense though, to have your orders executed with intraday data since you can get a good idea of how your limits will fare... I'll keep looking into it...


  • administrators

    @exu said in Different data timeframes for Strategy and Order Execution:

    I'm new to BackTrader (and Python)

    One can say you are new because you provide us with the non-relevant information bits and leave out what's important. Let me try to give some examples:

    @exu said in Different data timeframes for Strategy and Order Execution:

    perhaps this is a stupid question

    No. We have all been new in many things and have had to ask.

    @exu said in Different data timeframes for Strategy and Order Execution:

    I have both lines coming from a Postgres DB into a pandas DF thus, no resampling is needed.

    This is not relevant. Even if you were resampling the platform doesn't know it when working with the data feeds (actually, it doesn't make any effort to find out if one data feed is a resampled version of another one)

    @exu said in Different data timeframes for Strategy and Order Execution:

    but I couldn't find anywhere an example where my strategies/indicators use daily data but the orders are executed based on a intraday 1-min line

    The target for order execution doesn't know what your timeframes are and timeframes are not relevant for choosing the target. That line of thought is also what keeps you from not finding an example.

    What would have been important, so that anyone can quickly and easily pinpoint your problem:

    • How you add the data feeds to the system (if the data feeds come from a database, a socket or a file is not important, how they are added is important)
    • How you create the orders (how you invoke buy/sell) and how you indicate which is the target for the order

    Your solution:

    • Docs - Strategy - See the methods buy and sell and how you specify the target

    One example:

    • Blog - Multi Example

      All data feeds have the same timeframe, but it shows you how targets are chosen. As pointed out above: the timeframe is not relevant for choosing a target.

      (The source code is also in the repository)



  • lol @backtrader please never change.

    @exu I'm doing what you're doing, different time frames for strategy and order execution. When you place the order, the data should be the lower timeframe (called self._price in my code below):

                orderparams = dict(
                    data = self._price,
                    price=price,
                    exectype=bt.Order.Limit,
                    stopexec=bt.Order.StopTrail,
                    trailamount=self.p.trailing_points,
                    limitexec=None
                )
    
                if signal == 1:
                    self._order = self.buy_bracket(
                        **orderparams
                    )
                else:
                    self._order = self.sell_bracket(
                        **orderparams
                    )
    


  • Thanks @sohail ! I should have started the question with a full example of what I'm trying to achieve, but i just don't have one yet. Oh well...


Log in to reply
 

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