Macro defininition

 

Morning all

I have an EA with an `include.mqh` file attached, all working as expected, however I getting the `macro redefinition` warning when compiling the EA.

The include file is as follows;

#define __SLEEP_AFTER_EXECUTION_FAIL 400

   void <fuction>{
   
      if(<variable>){
                                                   
        <do a function> 

	Sleep(__SLEEP_AFTER_EXECUTION_FAIL);
            
      }

The EA is as follows

#define  __SLEEP_AFTER_EXECUTION_FAIL 400

Having read some posts on here, the general consensus is not to define the `__SLEEP_AFTER_EXECUTION_FAIL 400` in the function, only declare this in the Global declarations in the EA, except I get the "undeclared identifier" error when compiling. I put the declaration back into the function (the include file), and I get the "macro redefinition" warning.

It's sending me in a loop ....

How would I solve the "maco redefinition" warning?

 
TheHonestPrussian:

Morning all

I have an EA with an `include.mqh` file attached, all working as expected, however I getting the `macro redefinition` warning when compiling the EA.

The include file is as follows;

The EA is as follows

Having read some posts on here, the general consensus is not to define the `__SLEEP_AFTER_EXECUTION_FAIL 400` in the function, only declare this in the Global declarations in the EA, except I get the "undeclared identifier" error when compiling. I put the declaration back into the function (the include file), and I get the "macro redefinition" warning.

It's sending me in a loop ....

How would I solve the "maco redefinition" warning?

One way:

//#define __SLEEP_AFTER_EXECUTION_FAIL 400

   void <fuction>{
   
      if(<variable>){
                                                   
        <do a function> 
        #ifdef __SLEEP_AFTER_EXECUTION_FAIL
        Sleep(__SLEEP_AFTER_EXECUTION_FAIL);
        #endif
            
      }
 

You may write the following stuff in your EA code:

#ifndef __SLEEP_AFTER_EXECUTION_FAIL 
#define __SLEEP_AFTER_EXECUTION_FAIL 400
#endif

It is a conditional compilation.

Documentation on MQL5: Language Basics / Preprocessor / Conditional Compilation (#ifdef, #ifndef, #else, #endif)
Documentation on MQL5: Language Basics / Preprocessor / Conditional Compilation (#ifdef, #ifndef, #else, #endif)
  • www.mql5.com
Conditional Compilation (#ifdef, #ifndef, #else, #endif) - Preprocessor - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Laszlo Tormasi #:

One way:

Awesome, thanks

Reason: