Profile Picture

Hostorical pnl for a symbol on Newbar

Posted By allen80 6 Years Ago
Posted Monday September 24 2012

on new bar, when trading a symbol, I want to know the PNL history of it's last positions.

for example just like Close.current i want PNL[t-1] for last position closed for current symbol, or PNL[t-5] etc just like any other index.

I really need this. how can I find it?
Posted Tuesday September 25 2012
PositionManager.GetClosedPositions will return a list of closed positions. Then search on the list for the symbol you are looking for. The api reference help file has further details.

Posted Tuesday September 25 2012
ok thanks but is it ordered in order of last closed? i.e. i can get the pnl for the last 4 traded positions sorted in a list in order when they were closed up to most recent? thanks again!
Posted Tuesday September 25 2012
I'm not sure how the positions are sorted but you can sort via the Position.Info.CloseDate. There are several other properties in the Position class that may be of benefit to you. The api reference provides further details.


Edited: Tuesday September 25 2012 by alpha23
Posted Wednesday September 26 2012
I would keep a running total of the profit and loss for each symbol. You can store the current value in a UserSeries each NewBar to allow you to get previous values. The easiest thing to do would be to update the running total each time a position is closed. You could do that in the OrderFilled method with code like this:

if (position.State == PositionState.Closed)
totalPnL += position.RealizedProfit;

If you want to keep track of unrealized PnL, or realized PnL for positions which aren't fully closed, the code would be more complicated.


Similar Topics

Reading This Topic

2005-2018 © RightEdge Systems