What I am trying to is keep track of a trades Profit and Loss per round trade, not per fill. For example If I buy 3 contracts and when they are sold 2 are filled on one lot and 1 at another price. I want to store the PnL in a DataSeries for this trade as one trade (the 3 contracts).
My code is recording PnL for each lot not the round trade. HELP!
protected override void OnExecution(IExecution execution)
{
// Check to make sure there is at least one trade in the collection
if (Performance.RealtimeTrades.Count > 0)
{
// Get the last completed real-time trade (at index 0)
Trade Trade1 = Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1];
// Calculate the PnL for the last completed real-time trade
double lastProfit = Trade1.ProfitCurrency * Trade1.Quantity;
Print("Last PnL*" + PnL[1] + " Current PnL: " + PnL[0] + " LP " + lastProfit);
if(lastProfit != PnL[1]) {PnL[0] = lastProfit; Print("PnL " +PnL[0]);}
Print("The last trade's profit is " + lastProfit);
Last PnL*0 Current PnL: 0 LP -379.999999999973
PnL -379.999999999973
The last trade's profit is -379.999999999973
Last PnL*0 Current PnL: -379.999999999973 LP -379.999999999973
PnL -379.999999999973
The last trade's profit is -379.999999999973
Last PnL*0 Current PnL: 0 LP -170.000000000005
PnL -170.000000000005
The last trade's profit is -170.000000000005
Last PnL*0 Current PnL: -170.000000000005 LP -179.999999999995
PnL -179.999999999995
The last trade's profit is -179.999999999995
Any help pointing me in the right direction would be very helpful!!
Cheers,
SodyTexas

Comment