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/

    Orders getting executed multiple times

    General Code/Help
    3
    4
    79
    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.
    • N
      new_trader last edited by

      Hi everyone,
      I am new on backtrader. I was trying out a code on minute frequency data but it gave weird results

      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for FCX
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for BWA
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for F
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for ESS
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for AME
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for DRE
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for EXR
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for AVY
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for FE
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for FRC
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for GE
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for GM
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for GNRC
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for GPC
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for HPE
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for HST
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for ICE
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for INFO
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for INTC
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for KO
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for KSU
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for LNT
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for LKQ
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for L
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for IEX
      2019-04-08T23:59:00, ORDER ACCEPTED/SUBMITTED for LRCX
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: 464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      2019-04-08T23:59:00, SELL EXECUTED for F , Price: 9.29, Cost: -464.50, Comm 0.05
      

      I don't understand why this is happening

      Here's the code

      def notify_order(self, order):
              if order.status in [order.Submitted, order.Accepted]:
                  self.log('ORDER ACCEPTED/SUBMITTED for {}'.format(order.data._name))
                  return
      
              elif order.status in [order.Expired]:
                  self.log('BUY EXPIRED for {}'.format(order.data._name))
      
              elif order.status in [order.Completed]:
                  if order.isbuy():
                      self.log(
                          'BUY EXECUTED for %s, Price: %.2f, Cost: %.2f, Comm %.2f' %
                          (order.data._name,
                            order.executed.price,
                           order.executed.value,
                           order.executed.comm))
      
                  else:  # Sell
                      self.log('SELL EXECUTED for %s , Price: %.2f, Cost: %.2f, Comm %.2f' %
                               (order.data._name,
                                order.executed.price,
                                order.executed.value,
                                order.executed.comm))
      

      Orders are accepted for every symbol but only executed for one of them? Any help would be appreciated.

      run-out A 2 Replies Last reply Reply Quote 0
      • run-out
        run-out @new_trader last edited by

        @new_trader Please share all of your code. Thanks.

        RunBacktest.com

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

          @new_trader based on the printed time stamps, it seems that your data feed is passed to bt as a daily data feed. Import it as minute data feed with the appropriate timeframe and compression parameters, should fix the issue. At least this one.

          • 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
          N 1 Reply Last reply Reply Quote 1
          • N
            new_trader @ab_trader last edited by

            @ab_trader Hi ab_trader. I did submit it as timeframe=minute. On closed inspection, I noticed that it was submitting more sell requests before the last one was executed. I don't know how this lead to this specific behavior but after changing that, I don't think that it's an issue anymore.

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