OrderModify error 4108

 

Hey guys,

I am fairly new to the MT4 and just recently started writing some code.

With this code I am getting 4108 error with comment being invalid unknown ticket #.. for OrderModify, even with correct order id and so on..

I would very much appreciate any kind of help

Thanks a lot

if(OrderSelect(openOrderID,SELECT_BY_TICKET)==true)
      {
          int orderType = OrderType();// Short = 1, Long = 0          
          if(orderType == 0)//long position
          {
               if( NormalizeDouble(OrderOpenPrice() - OrderStopLoss(),Digits) < NormalizeDouble(Ask - OrderOpenPrice(),Digits)){
                  
                  Print("Order ID: " + openOrderID); 
                  Print("Order ticket: " + OrderTicket());
                  double newStopLoss = OrderOpenPrice();
                  bool res = OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,OrderTakeProfit(),0);
                  if(!res)
                     Print("Error in OrderModify. Error code=",GetLastError());
                  else
                     Print("Order modified successfully.");             
               }
          else //if short
          {
               if( NormalizeDouble(MathAbs(OrderOpenPrice() - OrderStopLoss()),Digits) < NormalizeDouble(OrderOpenPrice() - Bid,Digits)){
                  
                  Print("Order ID: " + openOrderID);
                  Print("Order ticket: " + OrderTicket());
                  double newStopLoss = OrderOpenPrice();
                  bool res = OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,OrderTakeProfit(),0);
                  if(!res)
                     Print("Error in OrderModify. Error code=",GetLastError());
                  else
                     Print("Order modified successfully.");
               } 
            }
          }
      }
 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. if(OrderSelect(openOrderID,SELECT_BY_TICKET)==true)

    You select by ticket, but don't test if the ticket has already closed, been deleted, or not yet open. (Latter two are pending order types.)

    If it has been closed, then you can't modify it, no such ticket open.

 
William Roeder:
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. You select by ticket, but don't test if the ticket has already closed, been deleted, or not yet open. (Latter two are pending order types.)

    If it has been closed, then you can't modify it, no such ticket open.

Hi William,

I am sorry if I am asking stupid questions, but when the if is written this way:

if(OrderSelect(openOrderID,SELECT_BY_TICKET) && OrderCloseTime() == 0)

The tester simply assumes that the order is closed since the beginning, even when checked right after the first tick, which I really don't understand..

Is there any reason for this behavior? Could you please show me as to how to solve this issue?

 
Liore: The tester simply assumes that the order is closed since the beginning,

Prove that.

 

Okay guys,

Thanks a lot for your help, I have finally been able to find and solve this issue, it was caused by incorrect placement of brackets

Stupid mistake, but hey, lesson learned :)

Anyway, thanks again