In the past this code did not throw errors
I understand the return value and wondered what changed to cause errors where none existed prior ?
Can anyone see fault with my highlighted solution code below. It's not throwing errors but is there a flaw in doing this ?
Old code commented and highlighted in grey. My new code highlighted in orange.
Or should I make the if condition above the entire comparisons first ?
Please advise thanks
Thanks
for(i = total - 1; i >= 0; i--) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break; if(OrderSymbol()==Symbol()&&OrderMagicNumber()==12334566)//Input your ea'smagic here { if(OrderType() == OP_BUY) { if(faster_1 < slower_1) { result = OrderClose(OrderTicket(), OrderLots(), Bid,3, White); if(result == false) { Print("Order", OrderTicket()," failed to close Error ",GetLastError()); return; } } } if(OrderType() == OP_SELL) { if(faster_1 > slower_1) { result = OrderClose(OrderTicket(), OrderLots(), Ask,3, White); if(result == false) { Print("Order", OrderTicket()," failed to close Error ", GetLastError()); return; } } } } }
Try something like this....not tested!
Hello, this is my first answer here :) i'll try my best to help.
i'm not a pro so don't expect the best here :D, but anyways, what i've seen people do for this warning is the same as you did.
you don't need to write it like this:
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
because the return value of OrderSelect() is either true of false, the better way to write it is:
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) //this will be true if the order is selected.
so, the part where you've coded:
result = OrderClose(OrderTicket(), OrderLots(), Ask,3, White); if(result == false) { Print("Order", OrderTicket()," failed to close Error ", GetLastError()); return; }
can be done simpler with:
if ( !(OrderClose(OrderTicket(), OrderLots(), Ask,3, White)) ) { //print error }
this way, if it fails, it prints error, if it succeeds, it closes/selects the order. so basically, the return value is checked.
I hope this help.
the pros feel free to correct me if i'm wrong.
Hello, this is my first answer here :) i'll try my best to help.
i'm not a pro so don't expect the best here :D, but anyways, what i've seen people do for this warning is the same as you did.
you don't need to write it like this:
because the return value of OrderSelect() is either true of false, the better way to write it is:
so, the part where you've coded:
can be done simpler with:
this way, if it fails, it prints error, if it succeeds, it closes/selects the order. so basically, the return value is checked.
I hope this help.
the pros feel free to correct me if i'm wrong.
if(!OrderClose(OrderTicket(), OrderLots(), Bid,3, White)) { Print("error"); return; }
correct one...
if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(),3, White)) { Print("error"); return; }
and use of OrderClosePrice instead of Bid or Ask
if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))break; //If not true, operation breaks...no need to use 'true' or 'false'no need to use 'true' or 'false'
correct one...
and use of OrderClosePrice instead of Bid or Ask
no need to use 'true' or 'false'Thanks all
Hello, this is my first answer here :) i'll try my best to help.
i'm not a pro so don't expect the best here :D, but anyways, what i've seen people do for this warning is the same as you did.
you don't need to write it like this:
because the return value of OrderSelect() is either true of false, the better way to write it is:
so, the part where you've coded:
can be done simpler with:
this way, if it fails, it prints error, if it succeeds, it closes/selects the order. so basically, the return value is checked.
I hope this help.
the pros feel free to correct me if i'm wrong.
Sorry for the delay, and thanks.
I still get confusing that !OrderSelect() when false is the equivalent to if(OrderSelect() == true)
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
In the past this code did not throw errors
I understand the return value and wondered what changed to cause errors where none existed prior ?
Can anyone see fault with my highlighted solution code below. It's not throwing errors but is there a flaw in doing this ?
Old code commented and highlighted in grey. My new code highlighted in orange.
Or should I make the if condition above the entire comparisons first ?
Please advise thanks
Thanks