Undeclared identifier in Include File

 

Hi I'm getting 100+ errors about undeclared identifiers in my include file, despite including the include file in my EA, i don't get any warning because I declared all of these ' undeclared identifiers ' as global variables in the EA.

How do i get rid of the errors in the include file?

 
Your topic has been moved to the section: Expert Advisors and Automated Trading — Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
luccc: Hi I'm getting 100+ errors about undeclared identifiers in my include file, despite including the include file in my EA, i don't get any warning because I declared all of these ' undeclared identifiers ' as global variables in the EA. How do i get rid of the errors in the include file?
It is somewhat difficult to answer without any code to serve as an example for the issue.
 
Fernando Carreiro #:
It is somewhat difficult to answer without any code to serve as an example for the issue.

so this is in the include file:

int getHammerSignal(){
     
   //Green Buying Hammer
     if(closePrice1 > openPrice1){                                                                       //Green Candlestick
         if((highPrice1 - closePrice1)* minWicktoWickRatio < (openPrice1 - lowPrice1)){                  //Upper Wick vs lower wick
            if((bodySize1)* minWicktoBodyRatio < (openPrice1 - lowPrice1)){                              //Upper Wick vs body
               createObject(time1, lowPrice1, 233, 1, clrGreen, " Hammer");
               return 1;
            }
         }  
     }
       
   //Red Buying Hammer   
     if(closePrice1 < openPrice1){
         if((highPrice1 - openPrice1)* minWicktoWickRatio < (closePrice1 - lowPrice1)){
            if((bodySize1)* minWicktoBodyRatio < (closePrice1 - lowPrice1)){
               createObject(time1, lowPrice1, 233, 1, clrGreen, " Hammer");
               return 1;
            }
         }
     }
     
   //Green Selling Hammer
     if(closePrice1 > openPrice1){
         if((openPrice1 - lowPrice1)* minWicktoWickRatio < (highPrice1 - closePrice1)){
            if((bodySize1)* minWicktoBodyRatio < (highPrice1 - closePrice1)){
               createObject(time1, highPrice1, 234, -1, clrRed, " Hammer");
               return -1;
            }
         }  
     }
       
   //Red Selling Hammer   
     if(closePrice1 < openPrice1){
         if((closePrice1 - lowPrice1)* minWicktoWickRatio < (highPrice1 - openPrice1)){
            if((bodySize1)* minWicktoBodyRatio < (highPrice1 - openPrice1)){
               createObject(time1, highPrice1, 234, -1, clrRed, " Hammer");
               return -1;
            }
         }  
     }
      
    return 0;     
   
   }
   


this is in the EA:


#include <Trade/Trade.mqh>
#include <Include101.mqh>
CTrade trade;   


//+-------------------------------------------------------------------------------------------------------+
//|  Global Variables                                                                                                    |
//+-------------------------------------------------------------------------------------------------------+
   datetime time1 = iTime(_Symbol, PERIOD_CURRENT, 1);

   double closePrice1 = iClose(_Symbol, PERIOD_CURRENT, 1);
   double openPrice1 = iOpen(_Symbol, PERIOD_CURRENT, 1);
   double highPrice1 = iHigh(_Symbol, PERIOD_CURRENT, 1);
   double lowPrice1 = iLow(_Symbol, PERIOD_CURRENT, 1);
   double bodySize1 = MathAbs(closePrice1 - openPrice1);
   double candleSize1 = MathAbs(highPrice1 - closePrice1);
   
   double closePrice2 = iClose(_Symbol, PERIOD_CURRENT, 2);
   double openPrice2 = iOpen(_Symbol, PERIOD_CURRENT, 2);
   double highPrice2 = iHigh(_Symbol, PERIOD_CURRENT, 2);
   double lowPrice2 = iLow(_Symbol, PERIOD_CURRENT, 2);
   double bodySize2 = MathAbs(closePrice2 - openPrice2);
   double candleSize2 = MathAbs(highPrice2 - closePrice2);

No errors in the EA, only in the include file

 
luccc #: so this is in the include file: this is in the EA: No errors in the EA, only in the include file

You are including the file before the variables are declared.

Place the "#include <Include101.mqh>" after the global variable declarations.

 
Fernando Carreiro #:

You are including the file before the variables are declared.

Place the "#include <Include101.mqh>" after the global variable declarations.

its still not working

 
luccc #: its still not working

Without seeing the full code to test ourselves, it is difficult to say what you are doing wrong.

However, it terms of code design, you should not me making functions that depend on global variables.

To make your library functions truely portable and self contained, you should be declaring parametrised functions, with arguments you can pass onto them.

EDIT: One more thing that is wrong ...

Global variables should not be initialised with function calls, especially if those functions are for market data which continuously change or that may even not be available when you program starts.

Those values should be attributed at run-time during the event processing, not in global variable declarations.

Reason: