User Defined Function

To add comments, please log in or register
chua le
383
chua le  
 while(pos>=0)
 {
 
 // ******** SLmin Function ********** 
  double Func_SLmin (iCxu)        
  {                     
  j=0;
  SLmin=3000;
  while(iLow(Symbol(),PERIOD_H1,j)<iCxu)
  {
  if (iLow(Symbol(),PERIOD_H1,j)<SLmin ) SLmin=iLow(Symbol(),PERIOD_H1,j);
  //Print (Symbol()+"SLmin = "+SLmin);                          
  j++;
  }
  return (SLmin);   
  }                               
  // ******** SLmin Function **********
   
 // ******** SLmax Function **********    
  
  double Func_SLmax (iCxd)       
  {                                      
  j=0;
  SLmax=0; 
  while(iHigh(Symbol(),PERIOD_H1,j)>iCxd)
  {
  if (iHigh(Symbol(),PERIOD_H1,j)>SLmax) SLmax=iHigh(Symbol(),PERIOD_H1,j);
  //Print (Symbol()+"SLmax = "+SLmax);                         
  j++;
  }     
  return (SLmax);
  } 
 // ******** SLmax Function **********  

Hi,


I insert the user defined function in the main loop  (while(pos>=0)and has the following 3 errors:

 'Func_SLmin' - function declarations are allowed on global, namespace or class scope only

 expressions are not allowed on a global scope

 'double' - comma expected.


Kindly help


William Roeder
20217
William Roeder  
while(pos>=0)
 {
 
 // ******** SLmin Function ********** 
  double Func_SLmin (iCxu)        
  {                     

You defined two functions inside a while loop. Move them outside all functions (like at the bottom of the file.)

chua le
383
chua le  
while(pos>=0)
 {
  
  

    

 pos--;
 

 }
 return(0);  
 }
   

 // ******** SLmin Function ********** 
  double Func_SLmin (iCxu)        
  {                     
  j=0;
  SLmin=3000;
  while(iLow(Symbol(),PERIOD_H1,j)<iCxu)
  {
  if (iLow(Symbol(),PERIOD_H1,j)<SLmin ) SLmin=iLow(Symbol(),PERIOD_H1,j);
  //Print (Symbol()+"SLmin = "+SLmin);                          
  j++;
  }
  return (SLmin);   
  }                               
  // ******** SLmin Function **********
   
 // ******** SLmax Function **********    
  
  double Func_SLmax (iCxd)       
  {                                      
  j=0;
  SLmax=0; 
  while(iHigh(Symbol(),PERIOD_H1,j)>iCxd)
  {
  if (iHigh(Symbol(),PERIOD_H1,j)>SLmax) SLmax=iHigh(Symbol(),PERIOD_H1,j);
  //Print (Symbol()+"SLmax = "+SLmax);                         
  j++;
  }     
  return (SLmax);
  } 
 // ******** SLmax Function **********    

hi,


I put outdie the while loop but still have the following  3 errors:


expressions are not allowed on a global scope

'double' - comma expected

'Func_SLmax' - function not defined


Kindly help, thanks


William Roeder
20217
William Roeder  

We can't see your broken code. There are no mind readers here and our crystal balls are cracked.

  1. We have no idea what line your "comma expected" is on including the few lines above that.
  2. We have no idea what line your function call is.
chua le
383
chua le  
int start()
 {
 int counted_bars=IndicatorCounted();
 //---- check for possible errors
 if (counted_bars<0) return(-1);
 //---- last counted bar will be recounted
 if (counted_bars>0) counted_bars--;
 int pos=Bars-counted_bars;
 
 //---- main calculation loop
while(pos>=0)
 {
 if (iTime(Symbol(),PERIOD_H4,0)!=PH40308U0) 
     {  
 if (X=1 )
         {     
 iCxu=iCH40;      
 SLmin= Func_SLmin (iCxu); 
 PH40308U0=iTime(Symbol(),PERIOD_H4,0);  
         }      
 }
 

 if (iTime(Symbol(),PERIOD_H4,0)!=PH40308D0) 
 {   
 if (X=2 )
        {                
 iCxd=iCH40;   
 SLmax= Func_SLmax (iCxd);          // Line 188
 PH40308D0=iTime(Symbol(),PERIOD_H4,0);               
        }
 }
 pos--; 
 }
 return(0);  
 }
   

 // ******** SLmin Function ********** 

  double Func_SLmin (iCxu)         //(Line 247)
  {                     
  j=0;
  SLmin=3000;
  while(iLow(Symbol(),PERIOD_H1,j)<iCxu)
  {
  if (iLow(Symbol(),PERIOD_H1,j)<SLmin ) SLmin=iLow(Symbol(),PERIOD_H1,j);
  //Print (Symbol()+"SLmin = "+SLmin);                          
  j++;
  }
  return (SLmin);   
  }                               
  // ******** SLmin Function **********
   
 // ******** SLmax Function **********    
  
  double Func_SLmax (iCxd)       // Line 263
  {                                      
  j=0;
  SLmax=0; 
  while(iHigh(Symbol(),PERIOD_H1,j)>iCxd)
  {
  if (iHigh(Symbol(),PERIOD_H1,j)>SLmax) SLmax=iHigh(Symbol(),PERIOD_H1,j);
  //Print (Symbol()+"SLmax = "+SLmax);                         
  j++;
  }     
  return (SLmax);
  } 
 // ******** SLmax Function **********    

hi,

I include the part of the codes  to make it clearer.

It has 3 errors as indicated. Is it the right way to put the user defined function outside the while loop as above?


expressions are not allowed on a global scope (Line 247)

'double' - comma expected  at line  (Line 263)

'Func_SLmax' - function not defined (Line 188)


Kindly help, many thanks

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
chua le
383
chua le  
ok I managed to resolve the issue as I forget to provide int and double in front of variables. Thanks
To add comments, please log in or register