I need some help with making sure orders are not being placed for the same Magic Number && Symbol && Direction for the purpose of having several EA's running and not interfering with each other. I will have an EA running for multiple symbols etc. If true, don't trade again until the current order is closed or if false, allow the trade be placed with an if (CheckForOpenOrders()= false) to trigger ordersend step. Any help is appreciated!
- Simple CCI with MA Filter EA
- Can magic numbers be used for more than one order?
- Somebody please help, my EA doesn't open multiple orders at once
Function:
bool CheckForOpenOrders(int order_type, int magic_number) { for(int i=OrdersTotal()-1; i>=0; i--) { if(!OrderSelect(i,SELECT_BY_POS)) continue; if(OrderSymbol() != _Symbol) continue; if(OrderMagicNumber() != magic_number) continue; if(OrderType() == order_type) return(true); } return(false); }
Call:
if(!CheckForOpenOrders(OP_SELL,MagicNumber)) OrderSend(_Symbol,OP_SELL,...
honest_knave:
Thanks so much!! I amended slightly it to suit my code as per below (One for buy and one for sell) and works perfectly.Function:
Call:
bool CheckForOpenOrdersLong() { for(int b=OrdersTotal()-1; b>=0; b--) { if(!OrderSelect(b,SELECT_BY_POS)) continue; if(OrderSymbol() != _Symbol) continue; if(OrderMagicNumber() != MagicNumber) continue; if(OrderType() == OP_BUY) return(true); } return(false); }
Michael Mosley:
Thanks so much!! I amended slightly it to suit my code as per below (One for buy and one for sell) and works perfectly.
Thanks so much!! I amended slightly it to suit my code as per below (One for buy and one for sell) and works perfectly.
Glad you got it sorted. You can have 2 functions in you prefer, or the function I wrote can actually be used for both (by changing the order type in the call)
i.e.
if(!CheckForOpenOrders(OP_SELL,MagicNumber)) OrderSend(_Symbol,OP_SELL,...
if(!CheckForOpenOrders(OP_BUY,MagicNumber)) OrderSend(_Symbol,OP_BUY,...
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