Don't you mean . . .
for(int i=OrdersTotal()-1; i>=0; i--) { if( OrderSelect(i, SELECT_BY_POS) ) {
If you know the ticket number just use it . . . if you don't, you can't.
Don't you mean . . .
If you know the ticket number just use it . . . if you don't, you can't.
no i don't mean that...i've used SELECT_BY_POS before which is straight forward. I've got an EA on 5 currency pairs..so there could be 5 open trades at any one time.
I've opened trades with command below..so 'yes' i know the ticket number but does OrderSelect(ticket,SELECT_BY_TICKET)==true) by itself automatically select the correct ticket# without having to loop through all of the open orders?
ticket = OrderSend(Symbol(),OP_BUY,lots,Ask,slippage,0,0,"EAname",0,0,Green);
I've opened trades with command below..so 'yes' i know the ticket number but does OrderSelect(ticket,SELECT_BY_TICKET)==true) by itself automatically select the correct ticket# without having to loop through all of the open orders?
And if you stop and restart the EA where does it get the ticket number from ?
To answer your question, yes . . .
OrderSelect(ticket,SELECT_BY_TICKET);
. . . will select the order whose ticket number is ticket . . . . assuming you are looking to select an open order and not a closed one, if you wanted a closed one you have to specify the MODE_HISTORY pool.
And if you stop and restart the EA where does it get the ticket number from ?
To answer your question, yes . . .
. . . will select the order whose ticket number is ticket . . . . assuming you are looking to select an open order and not a closed one, if you wanted a closed one you have to specify the MODE_HISTORY pool.
thanks for the confirmation - I'm writing variables (including ticket#) to file if pc crashes or I stop the EA.
thanks for the confirmation - I'm writing variables (including ticket#) to file if pc crashes or I stop the EA.
Hi Raptor,
I thought i'd sussed this SELECT_BY_TICKET function...but..just wrote a quick script to test it out. I used if(OrderSelect(ticket,SELECT_BY_TICKET)==True) Print(blah blah; - I deliberately entered a 'closed' ticket# and it selected it from Account History!! (without me adding MODE_HISTORY).
Please can you explain what is happening?
thanks
Please can you explain what is happening?
thanks
Yep, you need to red the Documentation . . . ;-)
" pool - Optional order pool index. Used when the selected parameter is SELECT_BY_POS. It can be any of the following values:"
You are selecting by Ticket so you don't need to specify the pool - MODE_TRADES or MODE_HISTORY.
The ticket number is unique, it will be in the Trades pool or the History pool . . . both pools have their own index number, so if you are selecting by Index number you need to specify the pool, if you don't MODE_TRADES is assumed.Yep, you need to red the Documentation . . . ;-)
" pool - Optional order pool index. Used when the selected parameter is SELECT_BY_POS. It can be any of the following values:"
You are selecting by Ticket so you don't need to specify the pool - MODE_TRADES or MODE_HISTORY.
The ticket number is unique, it will be in the Trades pool or the History pool . . . both pools have their own index number, so if you are selecting by Index number you need to specify the pool, if you don't MODE_TRADES is assumed.![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have been using the following code to select an open order in the client terminal:
I have an EA running on several currency pairs but only allowed one trade per currency pair.
Do i really need to use the loop to find the current order (ticket#) if there are multiple orders in the terminal from other currency pairs?
Is the loop only needed for SELECT_BY_POS?
This is not clear from the documentation.
thanks all.