I originally took some inspiration from JoyDeep on working a manual profit/loss system into my code. It works well, but I think I have it placed too early before a reversal trade is performed.
So, I'm working in a COBC = false, unmanaged environment. I have profit or loss calculated right before closing an order with the following code:
private void StartLong_Reversal()
{
if (longOrder == null)
{
// Capture the profit and/or loss of this trade before executing the next market order.
trade_ProfitLoss_Current = Math.Round(Position.GetProfitLoss(Close[0], PerformanceUnit.Currency),2);
trade_ProfitLoss_Totals = trade_ProfitLoss_Totals + trade_ProfitLoss_Current;
// Update individual profit/loss totals
if (trade_ProfitLoss_Current > 0) {trade_ProfitLoss_GrossProfit = Math.Round(trade_ProfitLoss_GrossProfit + trade_ProfitLoss_Current,2); }
else if (trade_ProfitLoss_Current < 0) {trade_ProfitLoss_GrossLoss = Math.Round(trade_ProfitLoss_GrossLoss + trade_ProfitLoss_Current,2); }
// Capture the trend of the current trade for the output window
trade_PreviousTrend = 1;
// Sell your current long shares to go short later.
longOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Market, numberofShares, 0, 0, "", "trendingLong");
longOrder_reversal = true; // Activate the longOrder_reversal flag for processing in iExecution
ResetAllVariables(); // Reset all applicable variables
}
}
What I'm wondering is, should these two paragraphs of code....:
// Capture the profit and/or loss of this trade before executing the next market order.
trade_ProfitLoss_Current = Math.Round(Position.GetProfitLoss(Close[0], PerformanceUnit.Currency),2);
trade_ProfitLoss_Totals = trade_ProfitLoss_Totals + trade_ProfitLoss_Current;
// Update individual profit/loss totals
if (trade_ProfitLoss_Current > 0) {trade_ProfitLoss_GrossProfit = Math.Round(trade_ProfitLoss_GrossProfit + trade_ProfitLoss_Current,2); }
else if (trade_ProfitLoss_Current < 0) {trade_ProfitLoss_GrossLoss = Math.Round(trade_ProfitLoss_GrossLoss + trade_ProfitLoss_Current,2); }
FYI, the reason I'm doing this and NOT using the Performance class of variables is that I couldn't get RealTime totals from each trade to output. So I went with manually tracking everything within the script and it's going great... except for this one part.
I'm also not against using the Performance class If anyone has some sample code or references you could point me too. I'd be more than happy to try out some alternative ways of getting this done.
Thanks in advance for any replies!
Yours,
Spider

Comment