notify_trade is not correctly recognize trade close when a trade is closed by stop loss or stop trail
sanmao last edited by
guys, I have two trades in my back test, the first is long, and the second is short. Both closed by stop trail and get profits. Buy notify_trade just recognize the two as one trade and loss money.
I don't know how to fix it.
def notify_trade(self, trade): if not trade.isclosed: return self.log('OPERATION PROFIT, GROSS %.2f, NET %.2f' % (trade.pnl, trade.pnlcomm))
Here is log
Starting Portfolio Value: 10000.00 2015-03-18, BUY @price: 2.55 2015-03-25, stopTrail @price: 2.60 2015-06-24, SELL @price: 2.99 2015-06-29, stopTrail @price: 2.77 2015-06-29, OPERATION PROFIT, GROSS -176.28, NET -176.28
This wall all discussed and clarified in this other post by the same author: https://community.backtrader.com/topic/1362/stop-trail-order-executed-but-position-not-change