OrderSelect() returns false but GetLastError() returns 0

 

GetLastError() returns 0 which means NO ERROR. So, why does OrderSelect() failed?

Did anyone encounter this problem?

 
goldfire:

GetLastError() returns 0 which means NO ERROR. So, why does OrderSelect() failed?

Did anyone encounter this problem?

No error means no problem. The return 'false' of OrderSelect() means that OrderSelect does not select anything.

Can you show us the OrderSelect() code, please use SRC button to show the code, it will be much more easier to explain with your code.

:D

 
goldfire:

GetLastError() returns 0 which means NO ERROR. So, why does OrderSelect() failed?

Did anyone encounter this problem?

I may well be that you are clearing the error by using GetLastError() and then reading it again using GetLastError() . . . and thus getting Error 0
 
goldfire:

GetLastError() returns 0 which means NO ERROR. So, why does OrderSelect() failed?

Did anyone encounter this problem?



I don't understand question

__________________
Watch What to Expect When You’re Expecting Online Free
 
daffodil1003:


I don't understand question

You wouldn't because you are a SPAMMING scum bag . . . now FOAD
 
onewithzachy:

No error means no problem. The return 'false' of OrderSelect() means that OrderSelect does not select anything.

Can you show us the OrderSelect() code, please use SRC button to show the code, it will be much more easier to explain with your code.

:D


Thanks for answer. My code is a little long, so i paste the piece where the error occurs

// this function used to close all opening long positions.
// It's copied from an Turtle System and some modification is made.
bool stdCloseLongPos(int magicNumber, string comments="") {
   int totalOrders=OrdersTotal();
   int orderScroll;
   bool state = true;
   for(orderScroll=0;orderScroll<totalOrders;orderScroll++) {
      if (OrderSelect(orderScroll,SELECT_BY_POS,MODE_TRADES)) {
         if((OrderSymbol()==Symbol())
            && (OrderMagicNumber()==magicNumber)
            && (OrderType()==OP_BUY)
            && (OrderComment()==comments)
           ) {
            if (!OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue)) {
               stdExceptProc(OrderTicket(), "OrderClose", GetLastError());
            }
         }
      } else {
         stdExceptProc(orderScroll, "OrderSelect", GetLastError());
         state = false;
      }
   }
   return(state);
}

// stdExceptProc is an exception processing function
void stdExceptProc(int ticket, string opType, int errno) {
   FileWrite(fhLog, TimeToStr(TimeCurrent()), TimeToStr(Time[0]),
             "!ERROR ", ticket, opType, errno);
             
   if ((opType!="OrderSelect") && (opType!="OrderSend")) {
      FileWrite(fhLog, TimeToStr(TimeCurrent()), TimeToStr(Time[0]),
                       "    ",
                       OrderTicket(),
                       OrderOpenTime(),
                       OrderType(),
                       OrderLots(),
                       OrderOpenPrice(),
                       OrderStopLoss(),
                       OrderTakeProfit(),
                       OrderCloseTime(),
                       OrderClosePrice(),
                       OrderCommission(),
                       OrderSwap(),
                       OrderProfit(),
                       OrderComment(),
                       OrderMagicNumber(),
                       OrderExpiration());
   }
   return;
}
 
RaptorUK:
I may well be that you are clearing the error by using GetLastError() and then reading it again using GetLastError() . . . and thus getting Error 0

I checked my code and I thinke GetLastError() is invoked only once... See my code above.
 
The most obvious error is that your stdExceptProc function cannot work in that situation because you call it when the OrderSelect fails. Therefore all the trade data you print is not from the order that failed but from the previous selection.
 

The next most obvious error is that your orderScroll loop is the wrong way around. You need to count down or you will miss orders since you are closing them as you go through the loop.

And of course you must set state to false if the OrderClose fails.

 
goldfire:

I checked my code and I thinke GetLastError() is invoked only once... See my code above.

To RaptorUK: I read your article

https://forum.mql4.com/48352

and I think I got what's wrong.. I will have a try. Thanks a lot.

 
dabbler:

The next most obvious error is that your orderScroll loop is the wrong way around. You need to count down or you will miss orders since you are closing them as you go through the loop.

And of course you must set state to false if the OrderClose fails.


Yeah, u r right. I got it, thank u very much.
Reason: