I have several EA’s running on my platform on multiple currency pairs. I thought would simple to code EA that would not open a 2nd order if one was already opened on the platform.
Anyone have any ideas why the code doesn’t work.
//+------------------------------------------------------------------+
//| Check orders open |
//+------------------------------------------------------------------+
bool CheckOpenOrders()
{
for(int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()== "EURUSD") return(true);
if(OrderSymbol()== "GBPUSD") return(true);
if(OrderSymbol()== "AUDUSD") return(true);
if(OrderSymbol()== "USDCAD") return(true);
if(OrderSymbol()== "NZDUSD") return(true);
if(OrderSymbol()== "EURAUD") return(true);
if(OrderSymbol()== "XNGUSD") return(true);
if(OrderSymbol()== "EURCAD") return(true);
if(OrderSymbol()== "AUDNZD") return(true);
if(OrderSymbol()== "XAGUSD") return(true);
if(OrderSymbol()== "XBRUSD") return(true);
if(OrderMagicNumber()==magic)
Print("An Order is already Open");
return(true);
}
return(false);
}
-Check you broker symbols name if it's exactly 6 string. Not like EURUSDc, or EURUSDm, or something like that.
- User brackets on OrderSelect() function:
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()== "EURUSD") return(true); if(OrderSymbol()== "GBPUSD") return(true); if(OrderSymbol()== "AUDUSD") return(true); if(OrderSymbol()== "USDCAD") return(true); if(OrderSymbol()== "NZDUSD") return(true); if(OrderSymbol()== "EURAUD") return(true); if(OrderSymbol()== "XNGUSD") return(true); if(OrderSymbol()== "EURCAD") return(true); if(OrderSymbol()== "AUDNZD") return(true); if(OrderSymbol()== "XAGUSD") return(true); if(OrderSymbol()== "XBRUSD") return(true); }
- make sure that all of your eas have the same magic number
- 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 several EA’s running on my platform on multiple currency pairs. I thought would simple to code EA that would not open a 2nd order if one was already opened on the platform.
Anyone have any ideas why the code doesn’t work.
//+------------------------------------------------------------------+
//| Check orders open |
//+------------------------------------------------------------------+
bool CheckOpenOrders()
{
for(int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()== "EURUSD") return(true);
if(OrderSymbol()== "GBPUSD") return(true);
if(OrderSymbol()== "AUDUSD") return(true);
if(OrderSymbol()== "USDCAD") return(true);
if(OrderSymbol()== "NZDUSD") return(true);
if(OrderSymbol()== "EURAUD") return(true);
if(OrderSymbol()== "XNGUSD") return(true);
if(OrderSymbol()== "EURCAD") return(true);
if(OrderSymbol()== "AUDNZD") return(true);
if(OrderSymbol()== "XAGUSD") return(true);
if(OrderSymbol()== "XBRUSD") return(true);
if(OrderMagicNumber()==magic)
Print("An Order is already Open");
return(true);
}
return(false);
}