last_order_profit(int magic)
As in your other topic, is there a point here?
for(int i=OrdersHistoryTotal();i >= 0;i--){ OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); if (OrderMagicNumber() == magic) break;You are assuming that history is orders, it isn't. Go through all orders and remember the last closed one and it's profit (=OrderProfit()+OrderSwap()+OrderCommission())