The Simplest of Questions

 

I am a beginner programmer and have not been programming for more than a year and want to create a new EA.

I have really a simple question about a line of code that is causing an error in my program. It seems that the format I use is not acceptable.

Can anyone guide me to the correct format this "if" statement with and "||" must take?

Thank you very much.

if (Stoch2 < 50 && Stoch1 > 50 && Stoch < 50) || (Stoch3 < 50 && Stoch2 > 50 && Stoch1 > 50 && Stoch < 50) SellArray[3] = true;
    else SellArray[3] = false;
 
ernest02:

I am a beginner programmer and have not been programming for more than a year and want to create a new EA.

I have really a simple question about a line of code that is causing an error in my program. It seems that the format I use is not acceptable.

Can anyone guide me to the correct format this "if" statement with and "||" must take?

It's a simple  (  )  braces issue.  Don't be afraid to add space to help you see this kind of problem clearly . . .

 

if (  Stoch2 < 50 && Stoch1 > 50 && Stoch < 50  )   ||  (  Stoch3 < 50 && Stoch2 > 50 && Stoch1 > 50 && Stoch < 50  ) SellArray[3] = true;
    else SellArray[3] = false;

// should be  . . .

if ( ( Stoch2 < 50 && Stoch1 > 50 && Stoch < 50  )   ||  (  Stoch3 < 50 && Stoch2 > 50 && Stoch1 > 50 && Stoch < 50 )  ) SellArray[3] = true;
    else SellArray[3] = false;
 
RaptorUK:

It's a simple  (  )  braces issue.  Don't be afraid to add space to help you see this kind of problem clearly . . .

 

THANKS A LOT FOR THAT SPEEDY RESPONSE!!!
 
RaptorUK: It's a simple  (  )  braces issue.  Don't be afraid to add space to help you see this kind of problem clearly . . .

Proper names: Parentheses ( ) Braces { } Brackets [ ] Chevrons < >

Adding spaces helps
if( (Stoch2 < 50 && Stoch1 > 50 && Stoch < 50) || ( Stoch3 < 50 && Stoch2 > 50 && Stoch1 > 50 && Stoch < 50) ) SellArray[3] = true;
    else SellArray[3] = false;
Or use multiple lines for different conditions
if( (               Stoch2 < 50 && Stoch1 > 50 && Stoch < 50)   
||  (Stoch3 < 50 && Stoch2 > 50 && Stoch1 > 50 && Stoch < 50)
  )  SellArray[3] = true;
else SellArray[3] = false;
Split conditions and self document
bool condition1 =                Stoch2 < 50,
     condition2 = Stoch3 < 50 && Stoch2 > 50,
     either     = condition1 || condition2; // Use better names
if( Stoch1 > 50 && Stoch < 50 && either)    // Stoch/Stoch1 were common to either so I split that out.
  )  SellArray[3] = true;
else SellArray[3] = false;
Then use booleans properly
bool condition1 =                Stoch2 < 50,
     condition2 = Stoch3 < 50 && Stoch2 > 50,
     either     = condition1 || condition2; // Use better names
SellArray[3] = ( Stoch1 > 50 && Stoch < 50 && either);
 
WHRoeder:

Proper names: Parentheses ( ) Braces { } Brackets [ ] Chevrons < >


In the UK   (  )  = brackets.  { } = curly brackets,  [ ] = square brackets  I tried to be a bit more universal with braces 
 

I hadn't finished reading https://en.wikipedia.org/wiki/Brackets and editing yet :(.

In modern American usage this is usually the square bracket and in modern British usage this is usually the parenthesis.

In American usage, parentheses are usually considered separate from other brackets, and calling them "brackets" at all is unusual

I hadn't yet read the UK usage. You Brits, why can't you speak English? :) We shouldn't be using US or UK specifics.

Parentheses or round brackets, vs. square brackets, vs. curly brackets or braces, makes it clear internationally.

Reason: