#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006 input int inAmountLastOrders = 2; void OnTrade() { static int PrevTotal = 0; const int NewTotal = OrdersHistoryTotal(); if (PrevTotal < NewTotal) { const int FirstIndex = NewTotal - inAmountLastOrders; for (int i = NewTotal - 1; i >= FirstIndex; i--) if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { OrderPrint(); Print("Last (" + (string)i + ") Trade Profit : ", DoubleToString(OrderProfit(), 2)); } PrevTotal = NewTotal; } }
fxsaber:
Thanks mate it works
Does this give Last trade profit of current symbol or overall last traded pair profit?
True. The function has no filtering.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I have the following code to get profit of last two closed positions i can get the profit of last position but not the second last one any ideas on how to get profit from last two positions in mql5