Calling Trade.pnl within next()
I have a very beginner question here that I am trying to figure out.
I am trying to get a unrealized PnL per position each time next() goes through another line in its data feed. Can someone point out how I would call trade.pnl within next()?
Thanks in advance
You cannot call
pnlis an attribute of a
Tradeinstance and can be queried but not called
Tradeinstances are notified in
notify_trade. You can keep a reference to the notified instance
Tradeinstances are not updated with each price change, they are updated with orders (i.e.: opening a position, increasing/reducing a position, closing a position).
You can track the value of an asset with
getvalue(Docs - Broker) and use the difference to the original to assess the profit and loss.
@backtrader thanks so much for the tip!