r_a_u_l Posted February 1, 2012 Report Posted February 1, 2012 hi i have this code sequence: ////////////// if (NewOrdersPlacedS) { if (flagS == TRUE) { for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) { if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberS) { if (OrderType() == OP_SELL) { ErrorS = OrderModify(OrderTicket(), AveragePriceS, OrderStopLoss(), PriceTargetS, 0, Red); if (ErrorS == -1) ShowERROR (ErrorS,0,0); NewOrdersPlacedS = FALSE; } } } } } } ///////////////// i want the code to do the following: -- if (ErrorS == -1) ShowERROR (ErrorS,0,0); -- try again every 5 seconds until order is modified can anyone guide me alter the code? best regards, raul
iwjw Posted February 1, 2012 Report Posted February 1, 2012 Could be something like this: ErrorS=-1; int err=0; while(ErrorS==-1) { ErrorS = OrderModify(OrderTicket(), AveragePriceS, OrderStopLoss(), PriceTargetS, 0, Red); err=GetLastError(); if (ErrorS == -1) { ShowERROR (ErrorS,0,0); if(err==130) break; Sleep(5000); } } I would propose that you change the datatype of ErrorS into boolean because Ordermodify returns true/false and that's a bit cleaner. Second I would look for error 130 (invalid stops) and break the loop....otherwise it could never come back if the error doesn't have something to do with the STOPLEVEL
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now