Problem with OrderDelete {invalid ticket for orderdelete function}

 

Hello,

Probably a noob question but couldn't find and answer browsing the forum. I basicly have this setup :

void CheckForOpen()

resSL=OrderSend(Symbol(),OP_BUYSTOP, Lots, High[1]+1+Spread,1, High[1] - 5, High[1]+1+Spread + 5,"",MAGICMA,0, Blue); 


This part above is fine. Then when an order is there it goes here :

void CheckForClose()

if (Ask >= TPLevelLong)
         {
          OrderDelete(resSL);
          Trading = 0;
         } 

 But it looks like that resSL = 0 (using the print(resSL) ) and it cannot delete the order...

What is wrong ?

Thanks!
Greg 

 
Greg_:

Hello,

Probably a noob question but couldn't find and answer browsing the forum. I basicly have this setup :

 But it looks like that resSL = 0 (using the print(resSL) ) and it cannot delete the order...

What is wrong ?

Do you check that the OrderSend() worked ?  how does CheckForClose() work when you first start the EA before OrderSend() has been called and while resSL is still at it's default of zero ?  is resSL a locally declared variable or globally declared ?  if the pending order is activated you can't delete it you have to close it,  how do you check it isn't activated yet ?
 
  1. Did you check the open worked? What are Function return values ? How do I use them ? - MQL4 forum
  2. resSL = 0
    You didn't save the ticket number you opened in a globally declared variable, or didn't find the pending order in a orderSelect loop.
  3. You declared resSL in CheckForClose() thus hiding the global
 

Thanks for your quick answer. Yes the OrderSend worked fine, it is just the closing.

Maybe it's a variable thing... I did declare "int resSL;" on the top of the code and also in both CheckForOpen() and CheckForClose().... Maybe i only need to declare it on the top of the code ?

That might be the issue as indicated in your point 3. WHRoeder :)

Thanks!!

 
Greg_:

Thanks for your quick answer. Yes the OrderSend worked fine, it is just the closing.

How do you know ?  did you check the return value ?
Reason: