I need to check if a specific market order is open or not and return a Boolean result
It returns "not all control paths return a value"
bool IsMOrderOpen(){ for(int h = OrdersTotal() - 1; h >= 0 ; h--) if (OrderSelect(h, SELECT_BY_POS, MODE_TRADES)) if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) return true; what are you returning here when you do not find any filtered orders? } // End of function
What is returned when one of the if statements is false, and when OrdersTotal() = 0 ?
Good attempt...I have a lot of fun this morning
He only wants the solution, not interested to learn.
I need to check if a specific market order is open or not and return a Boolean result
It returns "not all control paths return a value"
You were almost there. You just needed to check the order-type. In MT4, OP_BUY and OP_SELL are < 2 so...
bool IsMOrderOpen() { for(int h=OrdersTotal()-1; h>=0; h--) if(OrderSelect(h,SELECT_BY_POS)&&OrderSymbol()==_Symbol&&OrderMagicNumber()==Magic) if(OrderType()<2) return(true); return false; }
You were almost there. You just needed to check the order-type. In MT4, OP_BUY and OP_SELL are < 2 so...
Of course I'm interested in learning, the fact that I couldn't find an answer to his question returns my anger on him, I've to recognize ... happy you had a fun too.
I can't understand the logic for the two consecutive return, and what's the difference between Symbol() and _Symbol ?
Thank you
bool IsMOrderOpen() { for(int h=OrdersTotal()-1; h>=0; h--) if(OrderSelect(h,SELECT_BY_POS)&&OrderSymbol()==_Symbol&&OrderMagicNumber()==Magic) if(OrderType()<2) return(true); return false; }
Of course I'm interested in learning, the fact that I couldn't find an answer to his question returns my anger on him, I've to recognize ... happy you had a fun too.
I can't understand the logic for the two consecutive return, and what's the difference between Symbol() and _Symbol ?
Thank you
1. the second return, is the return from the function (it has to return a bool - true or false so you have to make sure that every decision inside your code returns something weather it is entered or not) when the if condition is false and thus not return the first one (or the for loop is not enrered at all because OrdersTotal() = 0)
2. you can read in the docs that they are the same.
Of course I'm interested in learning, the fact that I couldn't find an answer to his question returns my anger on him, I've to recognize ... happy you had a fun too.
I can't understand the logic for the two consecutive return, and what's the difference between Symbol() and _Symbol ?
Thank you
Symbol() and _Symbol yield the same result, but _Symbol is a pre-defined variable and Symbol() is a function call.
This is the same code with brackets... Does this help you see the logic?
bool IsMOrderOpen() { for(int h=OrdersTotal()-1; h>=0; h--) { if(OrderSelect(h,SELECT_BY_POS)&&OrderSymbol()==_Symbol&&OrderMagicNumber()==Magic) { if(OrderType()<2) { return(true); // if order is market return true } } } return false; // no market orders have been found; return false; }
Thanks guys you covered everything I want it.
Thanks guys you covered everything I want it.
And what have you learnt ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need to check if a specific market order is open or not and return a Boolean result
It returns "not all control paths return a value"