sanders4069:
Trying to check if I have active pending orders prior to creating new orders. Sure there is some simple problem here.
Edit: And I should mention that when I run it the EA continues to place orders, one after another. That is why I know it is returning false.
Any ideas?
try this:
bool activeOrders(int type, string argSymbol, int argMagicNumber) { for(int Counter = 0; Counter <= OrdersTotal()-1; Counter++) { OrderSelect(Counter, SELECT_BY_POS); if(OrderMagicNumber() == argMagicNumber && OrderSymbol() == argSymbol) { if(OrderType() == type) { return(true); } } } return(false); }
Dingetje:
try this:
Wow. Guess that did it, thanks for taking a look.
- Always test return codes (OrderSelect)
bool activeOrders(int type, string argSymbol, int argMagicNumber) { for(int Counter = OrdersTotal()-1; Counter >= 0; Counter--) if( OrderSelect(Counter, SELECT_BY_POS) && OrderMagicNumber() == argMagicNumber && OrderSymbol() == argSymbol && OrderType() == type) return(true); return(false); }
- Always count down in the presence of multiple orders (multiple charts or multiple EAs)
if(activeOrders(OP_SELLSTOP, Symbol(), magicNumber) ==false)
You may want to test OP_SELL as well - Once the sell stop opens it becomes a sell.
WHRoeder:
- Always test return codes (OrderSelect)
- Always count down in the presence of multiple orders (multiple charts or multiple EAs)
- You may want to test OP_SELL as well - Once the sell stop opens it becomes a sell.
Thank you so much for the reply, I am always looking for ways to improve my code.
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
Trying to check if I have active pending orders prior to creating new orders. Sure there is some simple problem here.
Edit: And I should mention that when I run it the EA continues to place orders, one after another. That is why I know it is returning false.
Any ideas?