Switch Operator

 
Hello. Hope you are well. I am trying to use figures from a switch operator elsewhere in the program but i am having a hard time figuring out how to do it. To properly explain, here is part of the code:
            break;
         case Peak: // search for peak
            if(LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<last_low && HighMapBuffer[shift]==0.0)
              {
               first++;
               ZigZagBuffer[last_low_pos]=0.0;
               last_low_pos=shift;
               last_low=LowMapBuffer[shift];
               ZigZagBuffer[shift]=last_low;
               res=1;
               datetime date_one=find_time_of_low(last_low);
              }
            if(HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0)
              {
               second++;
               last_high=HighMapBuffer[shift];
               last_high_pos=shift;
               ZigZagBuffer[shift]=last_high;
               extreme_search=Bottom;
               res=1;
               datetime date_two=find_time_of_high(last_high);
              }
            break;

         case Bottom: // search for bottom
            if(HighMapBuffer[shift]!=0.0 && HighMapBuffer[shift]>last_high && LowMapBuffer[shift]==0.0)
              {
               third++;
               ZigZagBuffer[last_high_pos]=0.0;
               last_high_pos=shift;
               last_high=HighMapBuffer[shift];
               ZigZagBuffer[shift]=last_high;
               datetime date_three=find_time_of_high(last_high);
              }
            if(LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0)
              {
               fourth++;
               last_low=LowMapBuffer[shift];
               last_low_pos=shift;
               ZigZagBuffer[shift]=last_low;
               extreme_search=Peak;
               datetime date_four=find_time_of_low (last_low);
              }
            break;
         default:
            return(rates_total);
        }
     }


The variables I am trying to use outside the switch operator are the datetime values. But when i try to use them, i get an "undeclared identifier" error. Do you know how I could go about it? Thanks in advance.

 
michealm:
Hello. Hope you are well. I am trying to use figures from a switch operator elsewhere in the program but i am having a hard time figuring out how to do it. To properly explain, here is part of the code:


The variables I am trying to use outside the switch operator are the datetime values. But when i try to use them, i get an "undeclared identifier" error. Do you know how I could go about it? Thanks in advance.

you have declared them locally so they will only be available inside the function where they are created.

see here  https://www.mql5.com/en/docs/basis/variables/local

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                                                            |...
 
Paul Anscombe:

you have declared them locally so they will only be available inside the function where they are created.

see here  https://www.mql5.com/en/docs/basis/variables/local

it worked. Thanks!
Reason: