You could put the profit and ticket number into an array and then sort? This would sort by profit ascending
double tickets[1,2]; ArrayResize(tickets,OrdersHistoryTotal()-1); int ct=0; for(int i=0;i<OrdersHistoryTotal();i++) if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)&&OrderType()!=6){ tickets[ct,0]=OrderProfit(); tickets[ct,1]=OrderTicket(); ct++; } ArraySort(tickets,0,0,MODE_ASCEND);
ArrayResize(tickets,OrdersHistoryTotal()-1);Do not assume history has only closed orders.
Hello
Thanks for help
When experimenting the expert does not work
You can review the code and experiment
I only want open deals
Ranking from largest to smallest profit
And the loss from the largest to the smallest arrangement
Thank you
Expert in attachments
Files:
arman_EA.mq4
19 kb
Samir Arman:
Hello
Thanks for help
When experimenting the expert does not work
You can review the code and experiment
I only want open deals
Ranking from largest to smallest profit
And the loss from the largest to the smallest arrangement
Thank you
Expert in attachments
Hi Samir.
I took the term "profit deals" to mean closed orders; after all, there's no profit - or loss - until the order is closed...;)
You'd get an error, because the array size in OrdersHistoryTotal() is one less than total orders in History, because of the "Balance" entry. Not the case in OrdersTotal().
ArrayResize(tickets,OrdersTotal()-1);
Also, you should filter out any pending orders from the array using OrderType()..
What do you mean ? That history could have open orders ? I don't get it.
Alain Verleyen: What do you mean ? That history could have
open orders ? I don't get it.
Not open orders. Closed orders. Deleted pending orders. Balance adjustments and credits.
enum Trade_Operation{ // Same as OP_xxx except a proper enumeration. TO_BUY, TO_SELL, TO_BUYLIMIT, TO_SELLLIMIT, TO_BUYSTOP, TO_SELLSTOP, TO_BALANCE, ///< (6) May occur in history pool. TO_CREDIT}; ///< (7) May occur in history pool.
William Roeder:
Not open orders. Closed orders. Deleted pending orders. Balance adjustments and credits.
Ah ok, of course. Thanks.
Not open orders. Closed orders. Deleted pending orders. Balance adjustments and credits.
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
like this picture