For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Calling Trade.pnl within next()
-
Hello,
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
trade.pnl
pnl
is an attribute of aTrade
instance and can be queried but not calledTrade
instances are notified innotify_trade
. You can keep a reference to the notified instance
But
Trade
instances 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!