Download MetaTrader 5

Compilation Error - undeclared identifier: trying to pass values from implementation file to class

To add comments, please log in or register
pvo2
64
pvo2  

Hi,

In writing an EA containing an implementation file and a separate class, I've developed a method (i.e. getBarLow) within the class designed to retrieve the lowest of the no. of bar lows to be used as a breakout entry. The parameters of the method is the no. of breakout days that is sourced from the main implementation file in the form of a user input (i.e. input in BreakoutDays) and the intention is for the method to pass the parameter to separate functions (i.e. iLow and iLowest days) to then work out the low breakout point. However, I am getting a compilation error message explaining that it the BreakoutDays parameter is an undeclared identifier - which I assume means a parameter I have yet to declare. I tried an alternative by declaring separate variables within the getBarLow method to pass the BreakoutDays from the main implementation file and then pass the values from the new variables to the iLowest function but did not yield a different result. 

Is anyone able to provide an alternative way to solve this?

I have attached both the mq5 and mqh files together with the compilation error screenshot which should help explain the issue.

Thanks.

Peter 

pvo2
64
pvo2  
pvo2:

Hi,

In writing an EA containing an implementation file and a separate class, I've developed a method (i.e. getBarLow) within the class designed to retrieve the lowest of the no. of bar lows to be used as a breakout entry. The parameters of the method is the no. of breakout days that is sourced from the main implementation file in the form of a user input (i.e. input in BreakoutDays) and the intention is for the method to pass the parameter to separate functions (i.e. iLow and iLowest days) to then work out the low breakout point. However, I am getting a compilation error message explaining that it the BreakoutDays parameter is an undeclared identifier - which I assume means a parameter I have yet to declare. I tried an alternative by declaring separate variables within the getBarLow method to pass the BreakoutDays from the main implementation file and then pass the values from the new variables to the iLowest function but did not yield a different result. 

Is anyone able to provide an alternative way to solve this?

I have attached both the mq5 and mqh files together with the compilation error screenshot which should help explain the issue.

Thanks.

Peter 

    I've managed to solve the undeclared identifier issue by doing the following:

    1. Removed the count parameter from the iLowest parameter list and replaced it with pBreakoutDays such that it can receive pBreakoutDays value from the function call
    2. Declared a count variable in the main code and assigned pBreakoutDays to it such that it now fits with the remaining code.

    See code below. However, now it gives me a "missing default value for parameter" error. Does the parameter need a default value if it is receiving a value from the function call??

     

    int iLowest(string symbol, int tf, int type=MODE_LOW, int pBreakoutDays, int start=0)
    {
       int count;                                                                             // <<------------ Declared count variable and replaced count from the parameter list with pBreakoutDays
       count = pBreakoutDays;                                                                 // <<------------ Assigned pBreakoutDays to count
       if(start <0) return(-1);
       ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
       
       if(count==0) count=Bars(symbol,timeframe);   
       
       if(type==MODE_LOW)
       {         
          double Arr[];
          if(CopyLow(symbol,timeframe,start,count,Arr)>0)  return((count-ArrayMinimum(Arr)-1)+start);
          else return(-1);
       }
       else if(type==MODE_HIGH)
       {
          double Arr[];
          if(CopyHigh(symbol,timeframe,start,count,Arr)>0) return((count-ArrayMinimum(Arr)-1)+start);
          else return(-1);
       }
       if(type==MODE_OPEN)
       {   
          double Arr[];
          if(CopyOpen(symbol,timeframe,start,count,Arr)>0) return((count-ArrayMinimum(Arr)-1)+start);
          else return(-1);
       }
       else if(type==MODE_CLOSE)
       {
          double Arr[];
          if(CopyClose(symbol,timeframe,start,count,Arr)>0) return((count-ArrayMinimum(Arr)-1)+start);
          else return(-1);
       }   
       else if(type==MODE_VOLUME)
       {
          long Arr[];
          if(CopyTickVolume(symbol,timeframe,start,count,Arr)>0) return((count-ArrayMinimum(Arr)-1)+start);
          else return(-1);
       }      
       else if(type==MODE_REAL_VOLUME)
       {
          long Arr[];
          if(CopyRealVolume(symbol,timeframe,start,count,Arr)>0) return((count-ArrayMinimum(Arr)-1)+start);
          else return(-1);
       }         
       else return(-1);
    }
    Alain Verleyen
    Moderator
    33810
    Alain Verleyen  
    pvo2:

      I've managed to solve the undeclared identifier issue by doing the following:

      1. Removed the count parameter from the iLowest parameter list and replaced it with pBreakoutDays such that it can receive pBreakoutDays value from the function call
      2. Declared a count variable in the main code and assigned pBreakoutDays to it such that it now fits with the remaining code.

      See code below. However, now it gives me a "missing default value for parameter" error. Does the parameter need a default value if it is receiving a value from the function call??

       

      The parameter needs a default value as it's preceded by another parameter with a default value. Or, you can move it before "type" parameter".
      Alain Verleyen
      Moderator
      33810
      Alain Verleyen  
      pvo2:

      Hi,

      In writing an EA containing an implementation file and a separate class, I've developed a method (i.e. getBarLow) within the class designed to retrieve the lowest of the no. of bar lows to be used as a breakout entry. The parameters of the method is the no. of breakout days that is sourced from the main implementation file in the form of a user input (i.e. input in BreakoutDays) and the intention is for the method to pass the parameter to separate functions (i.e. iLow and iLowest days) to then work out the low breakout point. However, I am getting a compilation error message explaining that it the BreakoutDays parameter is an undeclared identifier - which I assume means a parameter I have yet to declare. I tried an alternative by declaring separate variables within the getBarLow method to pass the BreakoutDays from the main implementation file and then pass the values from the new variables to the iLowest function but did not yield a different result. 

      Is anyone able to provide an alternative way to solve this?

      I have attached both the mq5 and mqh files together with the compilation error screenshot which should help explain the issue.

      Thanks.

      Peter 

      You can't use a variable as default value of a function's parameter.
      To add comments, please log in or register