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/

    Profit and SL on same tick in backtesting - optimal solution?

    General Discussion
    3
    6
    97
    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.
    • J
      jeanpaul last edited by

      Hi,
      I was wondering how backtrader deals with situations where both Profit and SL are hit on the same bar during backtesting. FIFO only works of course if a better timeframe resolution is added; for example if my profit as well as my SL hit on the same 4h-bar during backtesting, the optimal solution would be to look at 2h, or even something like 1-min charts, to see what was hit first.

      Is there such an implementation in the backtrader, which I might have missed?

      I found a similar question, but not an adequat answer:
      Re: What happens when a profit and sto order are filled in the same bar?

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

        Backtrader (similar to real life broker) doesn't make any tricks. It uses FIFO which applicable in any situation. You just need to think about it more.

        • 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
        1 Reply Last reply Reply Quote 0
        • vladisld
          vladisld @jeanpaul last edited by

          @jeanpaul said in Profit and SL on same tick in backtesting - optimal solution?:

          FIFO only works of course if a better timeframe resolution is added

          As @ab_trader said, FIFO works in any case. If multiple orders are filled on the same bar, multiple notifications will be received (notify_order) on this bar - still in FIFO order.

          1 Reply Last reply Reply Quote 0
          • J
            jeanpaul last edited by

            ok, I think I m not making myself clear. Let s say the close price of this 4h bar is 100. Now I go long, with a take profit at 105, and a stop loss at 99. On the next bar, the high is 106 and the low is 98. Which one closed my order, and why?

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

              @jeanpaul order issued first will close your position, next order will open new position. If it will not be cancelled in time.

              • 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
              1 Reply Last reply Reply Quote 0
              • J
                jeanpaul last edited by

                hey guys,

                I found the solution for my question. I didnt realize that I can have multiple timeframes in parallel. This solves my issue of course.

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