For instance, I may have 5 entries on BarsArray[0] and 5 entries on BarsArray[1]. I want to get the Realized Profit/Loss when each trade closes.
My first thought was to use onPositionUpdate() with position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]); But, I am confused here. ..
My first questions:
1) Is the position object associated with a given BarsArray (i.e. only 5 of the 10 entries) or all entries across that contract (BarsArray[0] and BarsArray[1]) ; all 10 entries?
2) Does the GetUnrealizedProfitLoss have the Realized Profit Loss in the following scenario
OnPositionUpdate(...) { if (position.MarketPosition == MarketPosition.Flat && marketPosition == MarketPosition.Flat) { profit = position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]); } }
OnExecutionUpdate(...) { if (execution.Order.OrderState == OrderState.Filled && (execution.Order.OrderAction == OrderAction.Sell || execution.Order.OrderAction == OrderAction.BuyToCover) ) { //get the closed trade profit/loss profitLoss = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency; }
Or do I have to calculate profit based on entry and exit price?
Thanks,
Comment