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/

    order.execute.price vs order.execute.value

    General Code/Help
    2
    5
    676
    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.
    • M
      maxpaton last edited by

      Taking the QuickStart section as an example, assuming the a stake size of 1, how is order.executed.price different from order.executed.value? In the Quickstart section it logs order.executed.value as 'cost'.

      When I use it in work of my own in the same way, order.executed.value ('cost') is sometimes the same value as order.executed.price ('price'), and other times it differs slightly...

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

        @maxpaton said in order.execute.price vs order.execute.value:

        and other times it differs slightly

        How? What are you expecting? Can you give us a code example?

        M 1 Reply Last reply Reply Quote 0
        • M
          maxpaton @backtrader last edited by

          @backtrader Sorry, I have realised the mistake I was making. But, would it be possible just to tell me how order.execute.value is calculated in the notify trade() method?

          Here is the code:

          def notify_order(self, order):
              if order.status in [order.Submitted, order.Accepted]:
                  return
              
              if order.status in [order.Completed]:
                  if order.isbuy():
                      self.log('BUY EXECUTED, Price: %.2f, Cost: %.2f, Comm: %.2f' %
                               (order.executed.price,
                                order.executed.value,
                                order.executed.comm))
                      
                      self.buyprice = order.executed.price
                      self.buycomm = order.executed.comm
                               
                  else:
                      self.log('SELL EXECUTED, Price: %.2f, Cost: %.2f, Comm: %.2f' % 
                               (order.executed.price,
                                order.executed.value,
                                order.executed.comm))
                      
                  self.bar_executed = len(self)
                      
              elif order.status in [order.Cancelled, order.Margin, order.Rejected]:
                  self.log('Order Cancelled/Margin/Rejected')
          B 1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators @maxpaton last edited by backtrader

            @maxpaton said in order.execute.price vs order.execute.value:

            how order.execute.value is calculated in the notify trade() method?

            Let's assume you mean notify_order. The value is calculated by the commission scheme which is assigned for the given asset and takes into consideration if you are using stock-like assets or future-like assets. You can customize it if you wish by adding your own commission schemes.

            The default is just the size * price for stocks.

            See for example: Docs - Extending Commissions

            There are some other pages on the topic

            P.S.
            That code doesn't help. You are not telling us nothing, but that you are printing things out and not what the problem is.

            M 1 Reply Last reply Reply Quote 0
            • M
              maxpaton @backtrader last edited by

              @backtrader Yes I did mean notify_order, thanks. I agree, not sure why I added the code, as all I wanted to know was how order.executed.value is calculated.

              Cheers

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
              $(document).ready(function () { app.coldLoad(); }); }