x=OrderSend(Symbol(),OP_SELL,LotSize,Bid,5,0,0,NULL,0,0,clrBlue);
If the order send is successful, then x= the ticket number
If x==-1 the order send was not successful
if(OrderSelect(OrderTicket(),SELECT_BY_TICKET)==true)
You can only use OrderTicket() or the others, after you select an order. If you have the ticket number use that with SELECT_BY_TICKET. Note: selecting by ticket works whether the order is open or closed.
Otherwise, you must perform a OrderSelect loop (SELECT_BY_POS,) filtering by magic number and symbol, to find the EA's order from others. See Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
See also Loops and Closing or Deleting Orders - MQL4 forum
You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
You should always be able to read your code out loud and have it make sense in English. In this case if(OrderSelect(...)) reads as "if order was selected."

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Guys, I am working on mql4 for almost 1 year and I have learnt so much thing from your comments. however I couldn't understand OrderTicket . When I open a trade how could I know the number of Ticket. When ea opens trades, each trade will have different ticket number and then I am not able to modify this trades.
This is what I am doing:
Any documentation, link or comment will be appreciated. Thanks a lot.