Jump to content

Recommended Posts

Posted

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...