Backtrader Community

    • 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 with a day valid never gets executed? #220

    General Code/Help
    5
    25
    8667
    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.
    • Y
      ypyean last edited by

      Thanks for the detail explanation, after I set cash value, it works perfectly. Thanks again.

      1 Reply Last reply Reply Quote 0
      • B
        Batman last edited by

        I had a similar problem and resolved by canceling the pending order every and then recreating it. This way there's no "weekend problem" when the order for next day is more than one day ahead.

        '''

        def next(self):
        
            self.cancel(self.order)
            
            ...        
                    
            if not self.position:
                self.order = self.buy(price = buy_price, exectype = bt.Order.Limit)
            else:
                self.order = self.close(price = sell_price, exectype = bt.Order.Limit)
        

        '''

        1 Reply Last reply Reply Quote 0
        • R
          rishabmah5 last edited by

          I am using the following code to buy at the high of a bar and cancel it if it does not get filled the next day.

          eofthisday = dt.datetime.combine(self.data.datetime.date(),dt.time(23, 59,59, 9999))
          eofnextday = eofthisday + dt.timedelta(days=1)
          self.order = self.buy(exectype=bt.Order.Stop, size=100, price=self.data.high[0], valid=eofnextday)
          

          For some reason, the program is only half working. Below is a buying log of the program

          BuyingLog.PNG

          On 2016-04-28 (the first signal), the high of the next day was not higher than that of 2016-04-28, and it should be cancelled. But when the signal came on 2016-04-29, the high of 2016-05-02 (the next day) was higher than that of 2016-04-29, but the program did not buy until 2016-06-06. Could someone please explain what I am doing wrong?

          R run-out 2 Replies Last reply Reply Quote 0
          • R
            rishabmah5 @rishabmah5 last edited by

            @rishabmah5 I meant 2016-05-05

            1 Reply Last reply Reply Quote 0
            • run-out
              run-out @rishabmah5 last edited by

              @rishabmah5 It would be significantly more helpful if you supplied OHLC data for each bar, if we are going to analyze OHLC to answer the question.

              RunBacktest.com

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