This line needs an added bit.
if(OrderSelect( ticketb, SELECT_BY_TICKET )==true)
This will return true even if the trade is in the history. Add this:
if(OrderSelect( ticketb, SELECT_BY_TICKET )==true) { if(OrderCloseTime()==0) { //The rest of the code } }
You are misusing OrderSelect(). You are tring to select the ticket number instead of the order pool array index. Once you've selected the correct location, you can then retriev e the ticket number from that location.
In the section for closing, you should loop through the order pool from (high to low), select the ticket and then close.
have a read of these
https://www.mql5.com/en/forum/127908/page2#358436
https://book.mql4.com/trading/orderclose
Also, the for loop for closing orders in the book is wrong. Use...
for(int i=OrdersTotal()-1; i>=0; i--) { if (OrderSelect(i,SELECT_BY_POS)==true) { // Check criteria and close } }
hth
V
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
it doesnt close orders something wrong with my OrderClose any idea?
thanks