New article: Common Errors in MQL4 Programs and How to Avoid Them

 

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.

  1. Compilation Errors
  2. Runtime Errors
  3. Compiler Warnings

Fixing errors

 

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?

 

#property show_inputs

if this is in your code it can prevent your EA from being attached to a chart, I fixed by deleting this and recompiling hopefully the compiler can flag this as an error in the future

 
ayogbenga2003:

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?

Check the return value . . . that is what it is for: What are Function return values ? How do I use them ?
 
ayogbenga2003:

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?

You double post has been removed.
 
TrailingStop Not work in new mt4!!!
 
gaborka1:
TrailingStop Not work in new mt4!!!

There is no mql4 function specific to trailing stop, and if you are talking about the feature included on MT4 terminal, you are off-topic.

By the way, I just check and MT4 Trailing Stop is working fine for me in build 628.

 

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.

 
ayogbenga2003:

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();
      }
 
  1. This thread is about checking for errors. You should have opened your own. Don't hijack other peoples threads with off topic posts.
  2. If you find a buy or sell order you continue. Pending orders never have profit.

  3. 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
Reason: