Sell executed 'notify_trade' showing orignal purchase value
cwse last edited by
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"
costcomponent 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?
That's probably no code from
notify_trade(or else a lot is missing), because you are checking an
orderfrom what seems code from a sample
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.