Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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

    General Code/Help
    4
    6
    1267
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • exu
      exu last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        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

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        exu 1 Reply Last reply Reply Quote 2
        • exu
          exu @ab_trader last edited by

          @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...

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

            @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)

            1 Reply Last reply Reply Quote 2
            • ?
              A Former User last edited by A Former User

              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
                              )
              
              exu 1 Reply Last reply Reply Quote 2
              • exu
                exu @Guest last edited by

                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...

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors