-- "unresolved extern variable" mt5 compile error --

 

I've got no idea what this error is about.

Here's the error message in full: <<unresolved extern variable 'xiDC2CLR'>>

Here's the code in context:
#property indicator_label4  "low_projection_line"
#property indicator_type4   DRAW_SECTION
#property indicator_color4  clrRed
#property indicator_style4  STYLE_SOLID
#property indicator_width4  2


extern color   xiDC2CLR;             // Pair 2 divergence plot line color
extern string  xsDC2_IRO_A;          // Pair 2(A) Primary: (MA,MACD,Stoch,Stoch_S,PSAR,CML,CT,CB,RML,RT,RB,ZZ,ZZLN,ZZLO,ZZHI)
extern int     xiDC2_IRO_IPRM_A;     // Period for primary indicator (int)
extern double  xdDC2_IRO_IPRM_A;     // Period for primary indicator (double)

input int            inptReach = 160;

//--- indicator buffers

double         ZigZag_buffer[];
double         averageHigh_buffer[];
double         averageLow_buffer[];
double         highProjection_buffer[];
double         lowProjection_buffer[];
int reach;


The error is flagged on only the first extern encountered. If I delete that line, I get the same error on the next one, on and on until there were no little piggies left.

Can someone tell me what's wrong with this code?

 
Millard Melnyk:

I've got no idea what this error is about.

Here's the error message in full: <<unresolved extern variable 'xiDC2CLR'>>

Here's the code in context:


The error is flagged on only the first extern encountered. If I delete that line, I get the same error on the next one, on and on until there were no little piggies left.

Can someone tell me what's wrong with this code?

The error you're encountering, "unresolved extern variable 'xiDC2CLR'", indicates that the variable xiDC2CLR is declared as an external variable but is not defined or initialized anywhere in your code.

In MQL, when you use the extern keyword to declare a variable, you are essentially indicating that the variable's value will be provided by the user or will be accessible from outside the current code file. However, you need to define or initialize these variables somewhere in your code or in an include file. Use "Input" and cancel the extern. Remember to close your statements.

You should also learn how to use debugging. i Got these excellent links from another developer, go visit them

Code debugging:  https://www.metatrader5.com/en/metaeditor/help/development/debug
Error Handling and Logging in MQL5:  https://www.mql5.com/en/articles/2041
Tracing, Debugging and Structural Analysis of Source Code, scroll down to: "Launching and Debuggin": https://www.mql5.com/en/articles/272
Code debugging - Developing programs - MetaEditor Help
  • www.metatrader5.com
MetaEditor has a built-in debugger allowing you to check a program execution step by step (by individual functions). Place breakpoints in the code...
 
Millard Melnyk:

I've got no idea what this error is about.

Here's the error message in full: <<unresolved extern variable 'xiDC2CLR'>>

Here's the code in context:


The error is flagged on only the first extern encountered. If I delete that line, I get the same error on the next one, on and on until there were no little piggies left.

Can someone tell me what's wrong with this code?

extern, from relatively recently, means something different from what you're used to:

https://www.mql5.com/en/docs/basis/variables/externvariables

Replace extern with input

Documentation on MQL5: Language Basics / Variables / Extern Variables
Documentation on MQL5: Language Basics / Variables / Extern Variables
  • www.mql5.com
Extern Variables - Variables - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladislav Boyko #:
Replace extern with input

Replace with input if this should be the indicator settings. But the strange thing is that you are not initializing these variables and below you have an input variable which you have initialized. In general, it is not clear what you are trying to do

 
Nardus Van Staden #:

The error you're encountering, "unresolved extern variable 'xiDC2CLR'", indicates that the variable xiDC2CLR is declared as an external variable but is not defined or initialized anywhere in your code.

In MQL, when you use the extern keyword to declare a variable, you are essentially indicating that the variable's value will be provided by the user or will be accessible from outside the current code file. However, you need to define or initialize these variables somewhere in your code or in an include file. Use "Input" and cancel the extern. Remember to close your statements.

You should also learn how to use debugging. i Got these excellent links from another developer, go visit them

Code debugging:  https://www.metatrader5.com/en/metaeditor/help/development/debug
Error Handling and Logging in MQL5:  https://www.mql5.com/en/articles/2041
Tracing, Debugging and Structural Analysis of Source Code, scroll down to: "Launching and Debuggin": https://www.mql5.com/en/articles/272

Thanks man, but sorry, wrong track. Here's the code you stated is missing (it's in OnInit):

//+------------------------------------------------------------------+
//| External parameters initialization                               |
//+------------------------------------------------------------------+
//
   xiDC2CLR = DarkOrange;
   xsDC2_IRO_A = "MA";
   xiDC2_IRO_IPRM_A = 15;
   xdDC2_IRO_IPRM_A = 15;


Your explanation doesn't account for why I only get the error on the first in the list, and why when I delete that declaration, it suddenly throws the same error on the next statement (now the first) which compiled fine as long as it wasn't the first one.

As far as debugging, I've done a bunch of it in the past, but you can't debug what you can't compile -- unless MT5 does that differently, too.

 
Vladislav Boyko #:

extern, from relatively recently, means something different from what you're used to:

https://www.mql5.com/en/docs/basis/variables/externvariables

Replace extern with input

Thanks, I'll give that a try. But that doesn't explain why I'm getting that compile error. 

 
Vladislav Boyko #:

Replace with input if this should be the indicator settings. But the strange thing is that you are not initializing these variables and below you have an input variable which you have initialized. In general, it is not clear what you are trying to do

Yeah, sometimes it's not clear to me either. Just what happens when switching to a different environment and don't know the rules yet.

When I declared the variables as extern and tried to initialize them in the declaration, the compiler told me that's a no-no, too. So I declared them as you see and initialized them in OnInit.

Yeah, changing the to input variables worked, thanks.

It's been some years, but as I remember, MT4 wouldn't let you programmatically change the value of an input variable, but it would an extern, so I always used externs for validating and defaulting user input.

 
Millard Melnyk #:

Thanks man, but sorry, wrong track. Here's the code you stated is missing (it's in OnInit):

Your explanation doesn't account for why I only get the error on the first in the list, and why when I delete that declaration, it suddenly throws the same error on the next statement (now the first) which compiled fine as long as it wasn't the first one.

This will need some looking into. I am not even sure what to make of this, if i read through the code i cant see what you are trying to achieve? Maybe another dev can assist. Im out

 
Millard Melnyk #:

Yeah, sometimes it's not clear to me either. Just what happens when switching to a different environment and don't know the rules yet.

When I declared the variables as extern and tried to initialize them in the declaration, the compiler told me that's a no-no, too. So I declared them as you see and initialized them in OnInit.

Yeah, changing the to input variables worked, thanks.

It's been some years, but as I remember, MT4 wouldn't let you programmatically change the value of an input variable, but it would an extern, so I always used externs for validating and defaulting user input.

input color   xiDC2CLR         = DarkOrange; // Pair 2 divergence plot line color
input string  xsDC2_IRO_A      = "MA";       // Pair 2(A) Primary: (MA,MACD,Stoch,Stoch_S,PSAR,CML,CT,CB,RML,RT,RB,ZZ,ZZLN,ZZLO,ZZHI)
input int     xiDC2_IRO_IPRM_A = 15;         // Period for primary indicator (int)
input double  xdDC2_IRO_IPRM_A = 15.0;       // Period for primary indicator (double)

extern now means different from what it meant in MT4 a few years ago.

https://www.mql5.com/en/docs/basis/variables/inputvariables
The input storage class defines the external variable. The input modifier is indicated before the data type. A variable with the input modifier can't be changed inside mql5-programs, such variables can be accessed for reading only. Values of input variables can be changed only by a user from the program properties window. External variables are always reinitialized immediately before the OnInit() is called.

 
Vladislav Boyko #:

extern now means different from what it meant in MT4 a few years ago.

So, this is to say that there is no way to alter user input anymore, am I correct? Yeah, that would be a step backwards.

 
Millard Melnyk #:

So, this is to say that there is no way to alter user input anymore, am I correct? Yeah, that would be a step backwards.

of course there is a way just map it...

input int user_input1 = 55;


int input1 = user_input1;


Reason: