Ask: How to get the last closed trade is loss or profit.
I would like to check a condition based on the Last closed trade. If the Last closed trade is in PROFIT...do this, if not do something else...
Example:
The Last Closed Trade Name = L1 and it Closed in profit(>0), then.....
The Last Closed Trade Name = L1 and it Closed in loss(<0), then.....
I tried the below and getting errors:
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string signalName, string fromEntrySignal)
{
if (execution.Order.OrderState == OrderState.Filled && fromEntrySignal == "L1")
{
Trade lastTrade = SystemPerformance.AllTrades.Count > 0 ? SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1] : null;
if (lastTrade != null && lastTrade.Entry.Name == "L1" && lastTrade. IsTradeClosed)
{
lastTradeProfit = lastTrade.ProfitCurrency;
}
}}
Also, tried this:
protected override void OnExecution(Execution execution)
{
if (execution.Order.OrderState == OrderState.Filled && execution.Order.Name == "L1")
{
// Update the last trade profit if the trade is closed
Trade lastTrade = SystemPerformance.AllTrades.Count > 0 ? SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1] : null;
if (lastTrade != null && lastTrade.Exit != null)
{
lastTradeProfit = lastTrade.ProfitCurrency;
}
}
}
Help Appreciated.
Thanks

Comment