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/

    Sell executed 'notify_trade' showing orignal purchase value

    General Code/Help
    2
    2
    858
    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.
    • C
      cwse last edited by

      Hi,

      I have a 'notify_trade' step in my strategy which prints buy / sell log per some standard backtrader tutorials. However I noticed the "Sell executed" log is actually returning the original buy cost, instead of what the trade sell value was. the following is my code within notify_trade:

              if order.status in [order.Completed, order.Canceled, order.Margin]:
                  if order.isbuy():
                      self.log('BUY EXECUTED: %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: %s, Price: %.2f, Cost: %.2f, Comm %.2f' %(order.data._name,
                                                                                                  order.executed.price,
                                                                                                  order.executed.value,
                                                                                                  order.executed.comm))
      

      I would expect the "SELL EXECUTED" cost component would show the sell value, given it references to the current sell instance of order.executed.value. How can I modify this to get what I am after?

      Thanks,
      CWE

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

        That's probably no code from notify_trade (or else a lot is missing), because you are checking an order from what seems code from a sample notify_order

        Two different orders are being processed which may or may not be related at all. Since the price and size components are unknown, it is difficult to evaluate what it's actually being delivered and what the expectation would be.

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