why it does not close the order? help please its my first EA
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
it doesnt close orders something wrong with my OrderClose any idea?
thanks