problem about switch case

 

hey guys, i have a simple code that i to want make a bool custom function that looks for 2 simple patterns and if there is a pattern, takes true value (and print hello) and if not False, but when i want to code it with switch cases it gives me error. i only want it to take a number and bring it to custom function and play with it with cases.


void OnTick()
  {
  int x=1; // i will add a for loop for this variable later
   if(check(x))
     Print("hello");
  }
 
bool check(int x)
  {  double open1=iOpen(Symbol(),PERIOD_D1,1); double close1=iClose(Symbol(),PERIOD_D1,1);  double high1=iHigh(Symbol(),PERIOD_D1,1);
     double low1=iLow(Symbol(),PERIOD_D1,1);   double range=high1-low1;
     double body;
   
   switch(x)
   {
   case 1:
   {
    if(close1>open1) {      //this 4 line says if candle had long talis take true value
      body=close1-open1;
       if(halfrange > body)
         return(true);
     }
     }
   case 2:
   {
   if(open1>close1) {       //this 4 line says if candle had long talis take true value
      body=open1-close1;    
      if(halfrange > body)
         return(true);
     }
     }
   return(false);
   }
 
  1. Don't post pictures of code, they are too hard to read.

    Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. You have braces between your cases. They are unnecessary/redundant. And are confusing you.

  3. When your code reaches case 2 from case 1, it will continue into case 2. You have no break statement to stop case 1.

  4. Your return false (line 31) is still part of case 2. You have no end of switch brace.
 
William Roeder:
  1. Don't post pictures of code, they are too hard to read.

    Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. You have braces between your cases. They are unnecessary/redundant. And are confusing you.

  3. When your code reaches case 2 from case 1, it will continue into case 2. You have no break statement to stop case 1.

  4. Your return false (line 31) is still part of case 2. You have no end of switch brace.
my bad, sorry. problem solved. thanks william
 
William Roeder #:
  1. Don't post pictures of code, they are too hard to read.

    Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. You have braces between your cases. They are unnecessary/redundant. And are confusing you.

  3. When your code reaches case 2 from case 1, it will continue into case 2. You have no break statement to stop case 1.

  4. Your return false (line 31) is still part of case 2. You have no end of switch brace.
I add that “return true” is wrong into a void function no?

In reference to the "break" I can omit it whether  I put "return" (obviously the switch will be inside an int i double function)
 

If it is an error of the compiler it tells what is wrong, in what line, and where in that line. Check it there.

Or at leat mark point in you code and tell us the error message.

What number you want to return an play with?

Reason: