Strange error compiling indicator

 

Hello forum,

I'm totally new to MQL, but no to programming.

I downloaded an Indicator (divergence.mq5) from the codebase and I get two errors on an input variable initialized with an enum value.

The code:


//+----------------------------------------------+
//|  declaration of enumerations                 |
//+----------------------------------------------+
enum PRICEMODE
  {
   MODE_CLOSE,    // Close                                        <-- First error
   MODE_HIGHLOW   // High/Low
  };

input PRICEMODE f=MODE_CLOSE;    //price field


...

      if(f==MODE_CLOSE)                                           <-- Second error
        {                          
         xu[bar]=close[bar];
         xd[bar]=close[bar];
        }
...

The errors have the same message

 ambiguous access, can be one of:

   0. enumeration value 'MODE_CLOSE' 0 0

   1. enumeration value 'MODE_CLOSE' divergence.mq5 44 4

Any help will be greatly appreciated.

Thank you. 

 


 

MODE_CLOSE is currently part of an existing enumeration and is a reserved word in MQL — Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes

You can not reuse or redefine it. So use a new name for your enumeration elements.

//+----------------------------------------------+
//|  declaration of enumerations                 |
//+----------------------------------------------+
enum PRICEMODE
  {
   PRICEMODE_CLOSE,    // Close
   PRICEMODE_HIGHLOW   // High/Low
  };

input PRICEMODE f=MODE_CLOSE;    //price field

...

      if(f==PRICEMODE_CLOSE)   
        {                          
         xu[bar]=close[bar];
         xd[bar]=close[bar];
        }
...

Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
  • www.mql5.com
Chart Timeframes - Chart Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

The problem is that MODE_CLOSE exists: https://www.mql5.com/en/docs/constants/chartconstants/enum_timeframes

Just rename it.

As you are not new to programming here you can search: https://www.mql5.com/en/search#!module=mql5_module_documentation

and here is a list of all functions with short explanation for a kind of keyword search: https://www.mql5.com/en/docs/function_indices

Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
  • www.mql5.com
Chart Timeframes - Chart Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

MODE_CLOSE is currently part of an existing enumeration and is a reserved word in MQL — Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes

You can not reuse or redefine it. So use a new name for your enumeration elements.


Thank you Fernando, have good day.
 
Carl Schreiber #:

The problem is that MODE_CLOSE exists: https://www.mql5.com/en/docs/constants/chartconstants/enum_timeframes

Just rename it.

As you are not new to programming here you can search: https://www.mql5.com/en/search#!module=mql5_module_documentation

and here is a list of all functions with short explanation for a kind of keyword search: https://www.mql5.com/en/docs/function_indices

Hi Carl, thanks for the replay. You are right, I should have searched MQL's references before, but I tough it was about the time to make some friends over here.

Also I said that I'm not new to programming because a lot of traders ask programming question too and sometimes they started to code because of trading, so it may be frustrating explain some simple concepts to those with very little experience.

Have a good weekend.  

 
robdabank #: Thank you Fernando, have good day.
You are welcome!