Is it possible to get a Arraysize function on a switch function?

 

Hi all,


i want to know if it's possible to get a ArraySize function on a Switch function?

Like that:

int tf[] = {1, 5, 15};

   double TakeProfit()
   {
      switch(tf[i])
         {
            case tf[1] : TP= 5;
            break;
            
            case tf[5] : TP= 6;
            break;
            
            case tf[15] : TP= 10;
            break;
         }
   }   

Is it possible?


Thanks all by advance :)

 
  1. Array size has nothing to do with switch
  2. case values must be CONSTANTS
  3. Your code
     Another
    int tf[] = {1, 5, 15};
       double TakeProfit(int i)
       {
          switch(tf[i])
             {
                case 1: TP= 5;
                break;
                
                case 5: TP= 6;
                break;
                
                case 15: TP= 10;
                break;
             }
           return(TP);
       }   
    int TF[] = {PERIOD_M1, PERIOD,M5, PERIOD_M15},
        TP[] = {        5,         6,         10};
    double TakeProfit(){
       for(int i=0; TF[i] != Period(); i++){}
       return(TP[i]);
    }   

 

Oh many thanks, you are so helpful.

Thanks again :)