I am trying to delete several buylimits orders when the Stochastics are in the overbought area but the code seems not to work. Where is the problem?
- Need advice - How to manage multiple orders opened in the same time?
- Deleting or closing a pending buylimit
- Delete Pending Orders when a market order is closed
Also
for(int i=0;i<Total;i++)
should be
for(int i=Total-1;i>=0;i--)
otherwise you may delete order 0, then move on to order 1, but because order 0 has been deleted, order 1 is now order 0.
You also have return(0) before the 2nd run of the loop
GumRai:
Loops and Closing or Deleting Orders
Also
should be
otherwise you may delete order 0, then move on to order 1, but because order 0 has been deleted, order 1 is now order 0.
pro_:
Remove break. This code will probably delete the first order and stop.
Remove break. This code will probably delete the first order and stop.
Thank you. Let me try that
GumRai:
You also have return(0) before the 2nd run of the loop
You also have return(0) before the 2nd run of the loop
Thank you for your help
GumRai:
You also have return(0) before the 2nd run of the loop
Is this correct now?You also have return(0) before the 2nd run of the loop
void start() { double DValue; int Total,cmd; bool result; Total=OrdersTotal(); DValue=iStochastic(Symbol(),0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0); for(int i=Total-1;i>=0;i--) { if(DValue>=80) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { cmd=OrderType(); if(cmd==OP_BUYLIMIT) { OrderPrint(); result=OrderDelete(OrderTicket()); if(result!=TRUE) Print("LastError = ", GetLastError()); } return(0); } else { Print( "Error when order select ", GetLastError()); break; } } return(0); } }
Can't be sure, but see comments in the code
void start() { double DValue; int Total,cmd; bool result; Total=OrdersTotal(); DValue=iStochastic(Symbol(),0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0); for(int i=Total-1;i>=0;i--) { if(DValue>=80) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { cmd=OrderType(); if(cmd==OP_BUYLIMIT) { OrderPrint(); result=OrderDelete(OrderTicket()); if(result!=TRUE) Print("LastError = ", GetLastError()); } //return(0); Why this return? The function will end after selecting one trade } else { Print( "Error when order select ", GetLastError()); break; } } } return(0); //putting the return here will allow the loop to complete }
Ok, Gumrai fixed the return(0) problem you had. I would also remove the second break. Because now it will stop at the first error. If the goal is to remove ALL pending orders, you would probably want it to continue removing the other orders regardless of the error it got on one of them, and not simply stop, right? As for the rest - don't see anything contradicting the intended logic.
GumRai:
Can't be sure, but see comments in the code
Can't be sure, but see comments in the code
Thank you. Its now working right

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