I am trying to find the unrealized profit/ loss for open trades. More specifically, if a trade has a loss of greater than a certain percentage of my account, I would exit the trade. This is for a Back Test with multiple trades open simultaneously.
The below code seems to get the profit or loss from the last trade, but not from necessarily an open trade. How do I get the profit/loss from an open trade?
It seems that I can look through all trades by looping Performance.RealtimeTrades.Count - 2 etc ...
Thank you,
Ken
if (Performance.AllTrades.Count > 0)
{
// Get the last completed real-time trade (at index 0)
Trade lastTrade = Performance.AllTrades[Performance.RealtimeTrades.Count - 1];
// Calculate the PnL for the last completed real-time trade
double lastProfit = lastTrade.ProfitCurrency * lastTrade.Quantity;
// Pring the PnL to the Output window
Print("The last trade's profit is " + lastProfit);
}
Comment