Help with Bool function comparisons with bool operation &&

 
Is there any problem with syntax of this code ? 


bool fib_high() //Needs work
   {
      { 
      if(A_low()==true && B_high()==true)
         {
         Print ("C = i", C);
         //fibhigh=A+(B-A)*fibo_retrace;
         //Print("UP ","A",",","B","Fib Hit ",fibhigh);
                  
         return(true);
         }    
                        
     }
    return(false);                 
   }
   

I cannot print or get a return.
Both functions are indeed true for testing purposes. 
I assume I am misunderstanding my use of &&. 

Please advise, thanks
 
Agent86:
Is there any problem with syntax of this code ? 



I cannot print or get a return.
Both functions are indeed true for testing purposes. 
I assume I am misunderstanding my use of &&. 

Please advise, thanks

I would suggest writing it like so:

      if( ( A_low() ) && ( B_high() ) )

//--- Not tested

But it is easier to debug if you collect the values into variables:

bool Alow = A_low();
bool Bhigh = B_high();
      if( ( Alow ) && ( Bhigh ) )

//--- Not tested
 
Agent86:
Is there any problem with syntax of this code ? 



I cannot print or get a return.
Both functions are indeed true for testing purposes. 
I assume I am misunderstanding my use of &&. 

Please advise, thanks

What do you mean you cannot get a return? The "Print" is executed only if those two conditions are true - obviously, it seems one of them (or maybe both) are false, therefore not printing out anything in the log.

EDIT: also, there's a strange "hanging" bracket after the function header and the "if". Not sure if that does something at all, but well, seems odd.

 

Or try this to be sure...

bool fib_high() //Needs work {
        Print(A_low() && B_high());             
        if(A_low() && B_high()) {
                Print ("C = i", C);
                //fibhigh=A+(B-A)*fibo_retrace;
                //Print("UP ","A",",","B","Fib Hit ",fibhigh);
                  
                return(true);                     
        }
        return(false);                 
}
   
 
Thanks ALL, this helps a lot. 
So the syntax seems ok just need to tidy it up once I find out why my return is no good. 
Thanks

My function A_high() is returning false and I did not expect that because ObjectSet sees it as true ?  I assumed I wrote the syntax wrong but really it is returning false. Thanks for that. 

But ObjectSet should not change color to clrRed then ? 

Now I'm really confused. 

if(A_high()==true) ObjectSet("B6",OBJPROP_BGCOLOR,clrRed);
else ObjectSet("B6",OBJPROP_BGCOLOR,clrBlack);

bool A_high()
   {
      { 
      if(histo()==false)
         {
         for (int i=histodowncount; val1==0; i++)
            {
            val1=iFractals(NULL, 0, MODE_UPPER, i);
            A = val1;
            if(A!=0)
               {
               Print(A, " A high Located at bar ",i);
               return(true);
               }
             }
            }
        }
    return(false);                 
   }
 
Agent86 #:
Thanks ALL, this helps a lot. 
So the syntax seems ok just need to tidy it up once I find out why my return is no good. 
Thanks

My function A_high() is returning false and I did not expect that because ObjectSet sees it as true ?  I assumed I wrote the syntax wrong but really it is returning false. Thanks for that. 

But ObjectSet should not change color to clrRed then ? 

Now I'm really confused. 

The way you have coded it, if your A_high() function is returning false, then the color will be black.

if(A_high()==true) ObjectSet("B6",OBJPROP_BGCOLOR,clrRed);
else ObjectSet("B6",OBJPROP_BGCOLOR,clrBlack); // HERE, since A_high() is returning false
 
Carlos Moreno Gonzalez #:

The way you have coded it, if your A_high() function is returning false, then the color will be black.


Thanks for the replies. 
Yes, but what is confusing is that is Object is Red "while" function is returning false.
I don't know why it's returning false when the condition is true and the Object is Red.  


Additionally this prints as expected as if true. 

Print(A, " A high Located at bar ",i);


So confused. I'll keep digging.

Thanks

 
It seems Both A_high and A_low have this exact same flaw. 

While the condition is true and the Object reacts as true, the functions returns false which is why it should be Black not Colored. 

I have no clue and cannot understand why. 

Thanks 
 
Question that might help me understand something please. 

Regarding this code: 
bool A_low()
   {  
      {
      if(histo()==true)
         {
         for (int i=histoupcount; val2==0; i++)
            {
            val2=iFractals(NULL, 0, MODE_LOWER, i);
            A = val2;
            if(A!=0)
               {
               Print(A, " A Low Located at bar ",i);
               return(true);
               }
            }
         }
       }        
    return(false);                 
   }
Trying to understand why false and Red. 

I don't see how it can be false. Can the for loop being false already cause the code to exit with a return(false); by default ? I really am stumped on this. 
It gets to the if code and Prints, so it should return(true) as the Red Object indicates. 
However, return is false. 

How is this even possible. 
Thanks for all responses. 
 
Agent86 #:
Question that might help me understand something please. 

Regarding this code: 
Trying to understand why false and Red. 

I don't see how it can be false. Can the for loop being false already cause the code to exit with a return(false); by default ? I really am stumped on this. 
It gets to the if code and Prints, so it should return(true) as the Red Object indicates. 
However, return is false. 

How is this even possible. 
Thanks for all responses. 
You seem to make assumptions without grounding them with facts so its hard to understand what is the real problem. If you want help, provide a testable piece of code that can be run and describe what you see as problem in the outcome of the script
 

What do you intend to achieve with that line?

for (int i=histoupcount; val2==0; i++)

Do you know how a for loop works?

Reason: