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/

    Limit order execution on high price on the next bar

    General Code/Help
    3
    4
    684
    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.
    • A
      Alexander Lifanov last edited by

      Hi
      I create order as buy_brackets and on the next bar the high price is higher than my limit price of order but it doesn't execute.

      2018-10-01T13:15:00, Open: 0.00003940. High: 0.00003965. Low: 0.00003918. Close: 0.00003920
      2018-10-01T13:15:00, 	Buy. Price: 0.00003920. Limit: 0.00003936. Stop: 0.00003904
      2018-10-01T13:20:00, Open: 0.00003933. High: 0.00003941. Low: 0.00003915. Close: 0.00003923
      2018-10-01T13:25:00, Open: 0.00003925. High: 0.00003927. Low: 0.00003910. Close: 0.00003911
      2018-10-01T13:30:00, Open: 0.00003910. High: 0.00003921. Low: 0.00003908. Close: 0.00003913
      2018-10-01T13:35:00, 	OPERATION PROFIT, GROSS -0.00000016, NET -0.00000016
      2018-10-01T13:35:00, Open: 0.00003911. High: 0.00003911. Low: 0.00003900. Close: 0.00003907
      
      

      Where have I mistake ?

      A B 2 Replies Last reply Reply Quote 0
      • A
        ab_trader @Alexander Lifanov last edited by ab_trader

        @alexander-lifanov seems the mistake is in your code.

        • 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
        A 1 Reply Last reply Reply Quote 0
        • A
          Alexander Lifanov @ab_trader last edited by

          @ab_trader there is the code

          current = self.datas[0]
          
          limitprice = (1. + 2 * .005) * current.close[0]
          stopprice = (1. - .005) * current.close[0]
          
          self.log(f'\tBuy. Price: {current.close[0]:.8f}. Limit: {limitprice:.8f}. Stop: {stopprice:.8f}')
          self.buy_bracket(
           data=self.data,
           price=current.close[0],
           limitprice=limitprice,
           stopprice=stopprice
          )
          
          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators @Alexander Lifanov last edited by

            @alexander-lifanov said in Limit order execution on high price on the next bar:

            Where have I mistake ?

            In your understanding about when orders execute (in backtrader and in real-life). Please read: Docs - Order Management and Execution

            @alexander-lifanov said in Limit order execution on high price on the next bar:

            2018-10-01T13:15:00, Open: 0.00003940. High: 0.00003965. Low: 0.00003918. Close: 0.00003920
            2018-10-01T13:15:00, 	Buy. Price: 0.00003920. Limit: 0.00003936. Stop: 0.00003904
            

            You create an order at 13:15, which can first be executed with the next bar
            @alexander-lifanov said in Limit order execution on high price on the next bar:

            2018-10-01T13:20:00, Open: 0.00003933. High: 0.00003941. Low: 0.00003915. Close: 0.00003923
            

            The next set of prices ...

            @alexander-lifanov said in Limit order execution on high price on the next bar:

            2018-10-01T13:25:00, Open: 0.00003925. High: 0.00003927. Low: 0.00003910. Close: 0.00003911
            

            Cannot match your Limit sell order because the price for it is 0.00003936 which is higher than the high

            Just follow the logic and understand when and why your order executes.

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