-
How To Ask Questions The Smart Way. (2004)
Don't rush to claim that you have found a bug.
Questions Not To Ask
My program doesn't work. I think system facility X is broken.It is almost always your code.
-
if(OrderSelect(ticket, SELECT_BY_POS)==true){
A ticket number is not a position index.
-
You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.
Hi, I'm trying to get ticket number after sending an order
but
always returns false
what's the problem?
The best thing to do is implement the following:
if(!OrderSelect(ticket, SELECT_BY_POS){ Print("Order Select Error "+IntegerToString(GetLastError(),0)); }
then you will return an error code and you should be able to diagnose the problem with MQL4's list of Error Codes. I also tend to make this a MessageBox() function as well as a print function, so it's immediately obvious if there is a problem.
Also, you don't need the ''== true". The OrderSelect() is a bool function by default, so you don't need to further clarify if the function returns true or false. :)
![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
Hi, I'm trying to get ticket number after sending an order
but
OrderSelect
always returns false
what's the problem?