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
GetLastError() returns 0 which means NO ERROR. So, why does OrderSelect() failed?
Did anyone encounter this problem?
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
I don't understand question
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; }
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.
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.
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.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
GetLastError() returns 0 which means NO ERROR. So, why does OrderSelect() failed?
Did anyone encounter this problem?