Download MetaTrader 5

Help me understand a warning.

To add comments, please log in or register
d.bignotti
105
d.bignotti  

I'm trying to run this function, is made for custom priceseries, basically input are:

-Price applied to (close,low,high ect)

-index of shift 

-open,close,high,low from OnCalculate


this is the function. 

enum Applied_Price       // Type of constant
  {
   Price_Close,          // Close
   Price_Open,           // Open
   Price_High,           // High
   Price_Low,            // Low
   Price_Median,         // Median Price (HL/2)
   Price_Typical,        // Typical Price (HLC/3)
   Price_Weighted,       // Weighted Close (HLCC/4)
   Price_Simple,         // Simple Price (OC/2)
   Price_Quarter,        // Quarted Price (HLOC/4) 
   Price_Trendfollow,    // TrendFollow_1 Price 
   Price_Trendfollow05   // TrendFollow_2 Price 
  };

//+X================================================================X+   
//| PriceSeries() function                                           |
//+X================================================================X+ 
double PriceSeries
 (
  Applied_Price appliedprice, // Price constant
  uint   bar, // Index of shift relative to the current bar for a specified number of periods back or forward
  const double& Open [],
  const double& Low  [],
  const double& High [],
  const double& Close[]
 )
//PriceSeries(appliedprice, bar, open, low, high, close)
//+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+
 {
//----+
  switch(appliedprice) 
   {
    //----+ Price constant from enum Applied_Price
    case  0: return(Close[bar]);
    case  1: return(Open [bar]);
    case  2: return(High [bar]);
    case  3: return(Low  [bar]);
    case  4: return((High[bar] + Low[bar])/2.0);
    case  5: return((Close[bar] + High[bar] + Low[bar])/3.0);                                                                 
    case  6: return((2*Close[bar] + High[bar] + Low[bar])/4.0);
        
    //----+                            
    case  7: return((Open[bar] + Close[bar])/2.0);
    case  8: return((Open[bar] + Close[bar] + High[bar] + Low[bar])/4.0);     
    //----                                
    case 9: 
            {
             if(Close[bar] > Open[bar])return(High[bar]);
             else
              {
               if(Close[bar] < Open[bar])
                    return(Low[bar]);
               else return(Close[bar]);
              } 
            }
    //----         
    case 10: 
            {
             if(Close[bar] > Open[bar])return((High[bar] + Close[bar])/2.0);
             else
              {
               if(Close[bar] < Open[bar])
                    return((Low[bar] + Close[bar])/2.0);
               else return(Close[bar]);
              } 
             break;
            }
    //----
    default: return(Close[bar]);
   }
//----+
return(0);
 }

 

But i do get this error:

 

 error

 

Can't figure it out. 

Keith Watford
Moderator
10369
Keith Watford  

double PriceSeries
 (
  Applied_Price appliedprice, // Price constant
  uint   bar, // Index of shift relative to the current bar for a specified number of periods back or forward
  const double& Open [],
  const double& Low  [],
  const double& High [],
  const double& Close[]
 )

You cannot use pre-defined variables for user variable names

Why would you want to, the values are available to the function anyway. 

whroeder1
15331
whroeder1  
  1. Exactly. Either use the predefined arrays explicitly or define your arrays like OnCalculate

  2. Don't hard code numbers. If you make any change to the enum, your code breaks.
    enum Applied_Price       // Type of constant
      {
       Price_Close,          // Close
       Price_Open,           // Open
    :
      switch(appliedprice){
        case  0: return(Close[bar]);
        case  1: return(Open [bar]);
     :
    Write self documenting code
    enum Applied_Price       // Type of constant
      {
       Price_Close,          // Close
       Price_Open,           // Open
    :
      switch(appliedprice){
        case  Price_Close: return Close[bar];
        case  Price_Open:  return Open [bar];
     :

d.bignotti
105
d.bignotti  
Thank You, i'll try to work around with your suggestion..
To add comments, please log in or register