this warning ==> "the return value of 'OrderSelect' function should be checked"
is giving me concern. how do i get rid of this warning? what is causing it in the new build of mt4?
Hi guys, I want to ask about the new MQL4 tutorial.
Is it fine if I download the MQL5 Book instead because the MQL4 CHM book is not updated and I heard now both MQL5 and MQL4 are quite the same.
Please give me suggestion...
I don't want to read the documentation like that, I want to read the offline version for my tablet.
this warning ==> "the return value of 'OrderSelect' function should be checked"
is giving me concern. how do i get rid of this warning? what is causing it in the new build of mt4?
It is a warning, as it says. Your EA or script will run without the issue being fixed. Some MetaQuotes examples give this warning when compiled too.
However, such warnings are a good thing, as they tell you that the code is not ideal.In this case the warning is telling you that the code should be improved to check the return value from the function call in case the call failed. If the call fails then the process, loop, function, whatever, should not try to continue or the next part of the process which tries to use the selected order will fail.
OrderSelect returns true if it worked, or false if it didn't. So your code needs to be something like this:
if (OrderSelect(xxxxx)) {
// OrderSelect worked - it returned true. Do whatever
}else{
// OrderSelect failed - it returned false
return; // or do whatever else is appropriate to the code/logic of your EA
}
or alternatively
if (!OrderSelect(xxxxx))
// OrderSelect failed - it returned false
return; // or do whatever else is appropriate to the code/logic of your EA
// OrderSelect worked. do whatever
Hi,
I am using below code to get the sum of floating pl of existing currency pair. below code is not summing up of more than 1 order. what is wrong with my code ?
please advise/guide/suggest
double totprof=0; int w,total=OrdersTotal(); //---- for(w=0; w<total; w++) { if(!OrderSelect(w,SELECT_BY_POS)) continue; if(OrderType()==OP_BUY || OrderType()==OP_SELL) continue; if(OrderSymbol() == Symbol()) continue; totprof+=OrderProfit()+OrderCommission()+OrderSwap(); }
- This thread is about checking for errors. You should have opened your own. Don't hijack other peoples threads with off topic posts.
- If you find a buy or sell order you continue. Pending orders never have profit.
-
Using OrdersTotal directly and/or no Magic number filtering on your
OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual
trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article Common Errors in MQL4 Programs and How to Avoid Them has been published:
Some older programs can return errors in the new version of the MQL4 of compiler.
To avoid critical completion of programs, the previous version compiler handled many errors in the runtime environment. For example, division by zero or array out of range are critical errors and usually lead to application crash. Such errors occur only in some states for certain values of variables. Read this article to know how to handle such cases.
The new compiler can detect actual or potential sources of errors and improve code quality.
In this article, we discuss possible errors that can be detected during compilation of old programs and ways to fix them.