int CountPending() { int Pending=0; for(int d=OrdersTotal()-1;d>=0;d--) { if(OrderSelect(d,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) if(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP) if(OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT) Pending++; } return(Pending); }
If it is a buy stop or a sellstop it will never be a buy limit or a sell limit. Your function always returns zero. Fix and simplify:
int CountPending() { int Pending=0; for(int d=OrdersTotal()-1;d>=0;d--) if( OrderSelect(d,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==MagicNumber &&(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT) && OrderSymbol()==Symbol() ){ Pending++; } return(Pending); }
William Roeder #:
If it is a buy stop or a sellstop it will never be a buy limit or a sell limit. Your function always returns zero. Fix and simplify:
Minor mistakes, I'll just remove the stop functions.
int CountPending() { int Pending=0; for(int d=OrdersTotal()-1;d>=0;d--) { if(OrderSelect(d,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) if(OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT) Pending++; } return(Pending); }
As for the multiple orders I solved it by adding this function:
void BuyGridLimit() { for(int y=OrdersTotal()-1;y>=0;y--) { if(OrderSelect(y,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) { if(Ask<=BuyGridTrade) { int BuyLimitTrade=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-PriceLimit*Pips(),0,0,0,"Test",MagicNumber,0,clrDarkOrange); BuyGridTrade=Ask-PriceLimit*Pips(); } } } } void SellGridLimit() { for(int x=OrdersTotal()-1;x>=0;x--) { if(OrderSelect(x,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) { if(Bid>=SellGridTrade) { int SellLimitTrade=OrderSend(Symbol(),OP_SELLLIMIT,0.01,Bid+PriceLimit*Pips(),0,0,0,"Test",MagicNumber,0,clrDarkCyan); SellGridTrade=Bid+PriceLimit*Pips(); } } } }
Thank you William
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
How to avoid opening multiple limit orders instead of one at a time?