8tango:
Forum on trading, automated trading systems and testing trading strategies
William Roeder, 2011.09.28 15:58
-
The MOMENT you have multiple charts or manual trading, that code will be not be selecting the EA's order but something else. Likewise if you have deposits and withdrawals
Since the order of the list is NOT documented, i.e. could change in future versions, the paranoid among us go through all orders.
If you're not paranoid just find the last order and exit the loop.
for(int pos=OrdersHistoryTotal(); pos >= 0; pos--) if ( OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) // Only orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. && OrderType() <= OP_SELL // Avoid cr/bal forum.mql4.com/32363#325360 ){ Print(" Last Order Ticket = ",OrderTicket()); break; }
- Why do you need to do it more than once? Remember the last OrderCount() in a static. If it has changed find the last history and remember what you need.
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
Hi,
I have this function below which check the status (Profit or Loss) of the last closed order:
But when I use it into an EA (code below) with many orders closed it doesn't work correctly, the "LastOrder" string variable display only the status of the first closed order but not the next closed order, what is wrong into my code?
Thank you for your help.