Hello,
I thought monitor all open and pending orders, but I can not find the method to detect if Achat_1 with Magic Number X or Achat_1 with Magic Number Y is close
Below the way I try but if someone can guide me a little, thanks
Not sure I get you correctly, but do you have to know Achat_1 with MagicX or Achat_2 with MagicY is closed?
Could you not just filter for open/market orders and if any is active delete whatever order you need to delete?
if ( (OrderCloseTime()!=0) //could be if(OrderType()==OP_BUY){DeleteAllPendingBuyOrders();} //OrderType OP_BUY out of pool MODE_TRADES is a market order.
You may want to include a filter for the given magicnumbers too.
if ( ! OrderSelect(Position_Index, SELECT_BY_POS, MODE_TRADES)) continue; if ( (OrderCloseTime()!=0) && ???
If you are selecting by TICKET, the MODE is ignored. You get the ticket which may be open, pending or closed, so you need to check OrderCloseTime. When you are selecting by POSITION/ mode_TRADES, OrderCloseTime will always be zero.if(OrderSelect(Achat_1, SELECT_BY_TICKET) == true) { if ( ((OrderCloseTime()!=0) && (Total_Orders > 0)) || ((OrderCloseTime()==0) && (OrderType() == OP_BUYLIMIT) && (MACD_Current < MACD_Signal_Current) && (Bars != BarsCount)) )
This is almost unreadable and therefor not understandable.- Always move unchanging things outside loops. In this case macd and barsCount have nothing do with the order selected.
if (MACD_Current < MACD_Signal_Current && Bars != BarsCount && OrderSelect(Achat_1, SELECT_BY_TICKET) ){ if ( (OrderCloseTime()!=0 && Total_Orders > 0) || (OrderCloseTime()==0 && OrderType() == OP_BUYLIMIT) )
Use Self documentating code, Simplify using functions.if (MACD_Current < MACD_Signal_Current && Bars != BarsCount && OrderSelect(Achat_1, SELECT_BY_TICKET) ){ bool hasClosedWithOtherPending = OrderCloseTime()!=0 && Total_Orders > 0, isStillPending = OrderCloseTime()==0 && OrderType() == OP_BUYLIMIT; if (hasClosedWithOtherPending || isStillPending) DeleteAllPendingBuyOrders();
You would never write if ( (2+2==4) == true) would you? Then don't write if (bool == true) it's redundant. if (bool) and if(!bool) is sufficient especially if you use readable var names.Redundant tests Result = OrderDelete(OrderTicket()); if(Result == TRUE) Print("Suppression du BUY Limit effectué : ", OrderTicket()); if(Result != TRUE) Print("Erreur lors de la Suppression du BUY Limit : ", OrderTicket());
Simplified if (OrderDelete(OrderTicket()) Print("Suppression du BUY Limit effectué : ", OrderTicket()); else Print("Erreur lors de la Suppression du BUY Limit : ", OrderTicket(), "?",GetLastError());
What are Function return values ? How do I use them ? - MQL4 forum Check your return codes AND print out the error code so you find out WHY.else { Print( "Erreur lors de la sélection du Buy Limit à supprimer ", GetLastError()); break; }
You have not called a function since the orderSelect, so what use is GetLastError here?- Don't use bars or volume, unreliable. Always use time[]
Hello,
Thanks for your answers.
What do you think of this code?
If Achat_1 was closed in this EA or if Achat_1 is open in other EA (1, 2, 3 or 4), all pending orders are closed
Total_Orders = OrdersTotal(); if ( (OrderSelect(Achat_1, SELECT_BY_TICKET) == true) && (OrderCloseTime()!=0) && (OrderMagicNumber() == Colombanaise_MACD_Magic_Number) && (Total_Orders > 0) || (OrderSelect(Achat_1, SELECT_BY_TICKET) == true) && (OrderCloseTime()==0) && (OrderMagicNumber() == Other_EA_Magic_Number_1) && (Total_Orders > 0) || (OrderSelect(Achat_1, SELECT_BY_TICKET) == true) && (OrderCloseTime()==0) && (OrderMagicNumber() == Other_EA_Magic_Number_2) && (Total_Orders > 0) || (OrderSelect(Achat_1, SELECT_BY_TICKET) == true) && (OrderCloseTime()==0) && (OrderMagicNumber() == Other_EA_Magic_Number_3) && (Total_Orders > 0) || (OrderSelect(Achat_1, SELECT_BY_TICKET) == true) && (OrderCloseTime()==0) && (OrderMagicNumber() == Other_EA_Magic_Number_4) && (Total_Orders > 0) ) { for(int i = Total_Orders - 1; i >= 0 ; i --) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { Cmd = OrderType(); if(Cmd != OP_BUY && Cmd != OP_SELL && OrderMagicNumber()==Colombanaise_MACD_Magic_Number) { Result = OrderDelete(OrderTicket()); if(Result == TRUE) Print("Suppression du BUY Limit effectué : ", OrderTicket()); if(Result != TRUE) Print("Erreur lors de la Suppression du BUY Limit : ", OrderTicket()); break; } } else { Print( "Erreur lors de la sélection du Buy Limit à supprimer ", GetLastError()); break; } } }
Other question, a EA open and close orders automatically.
In my example, Achat_1 is open, then close, and a other Achat_1 is open and close......
How the system differentiates Achat_1 closed at 15pm with a other Achat_1 closed at 16pm.
When I asked whith this code, my question is of course the last order closed
(OrderSelect(Achat_1, SELECT_BY_TICKET) == true) && (OrderCloseTime()!=0)
Last question, is it a problem if several EA have the same name Achat_1 ?
Thanks, Emmanuel
WHRoeder,
sorry, I post without see your comment.
I'll read it
Emmanuel
Last question, is it a problem if several EA have the same name Achat_1 ?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
Sorry for my bad English, I'm Frenchy...., I'll try to be clear
In my code, when conditions replies, the OP_BUYLIMIT (Achat_1) is open and a I place a new OP_BUYLIMIT pending. If Achat_2 is active, a new OP_BUYLIMIT (Achat_3) is pending. There is additional code between these lines, useless for understanding I suppose.
When the gain is reached, the pending (Achat_x) OP_BUYLIMIT is delete
This all works fine, however, I am running several EA simultaneously with the same principle.
I would like to have more active EA, but when a Buy is active, all OP_BUYLIMIT of all EA are delete to have only one at a time active trade open
I thought monitor all open and pending orders, but I can not find the method to detect if Achat_1 with Magic Number X or Achat_1 with Magic Number Y is close
Below the way I try but if someone can guide me a little, thanks
Emmanuel