Hi, I am having issues with this function above.
For some reason the function after the 'and' operand is not called.
The 'Long_Secondary_Confirmation' function itself does work fine, it's just when in this position in an 'if statement' it fails to call.
Similarly when i switch the two functions around to have the code in the following format, the 'Long_Primary_Confirmation' function fails to call.
There are no errors in the code when compiled either
Any help or explanation for this would be greatly appreciated! :)
Hey.
Its impossible there are no errors unless you are compiling on MT4 and you dont have #property strict
bool Long_Confirmation() { if(Long_Primary_Confirmation() == true && Long_Secondary_Confirmation() == true) return(true); return(false); } bool Long_Primary_Confirmation(){return(true);} bool Long_Secondary_Confirmation(){return(true);}
Your code | if(Long_Primary_Confirmation() == true && Long_Secondary_Confirmation() == true) return(true); return(false); |
Simplified | return Long_Primary_Confirmation() && Long_Secondary_Confirmation(); |
Your code | |
Simplified |
mahahahahaha
Hi, I am having issues with this function above.
For some reason the function after the 'and' operand is not called.
The 'Long_Secondary_Confirmation' function itself does work fine, it's just when in this position in an 'if statement' it fails to call.
Similarly when i switch the two functions around to have the code in the following format, the 'Long_Primary_Confirmation' function fails to call.
There are no errors in the code when compiled either
Any help or explanation for this would be greatly appreciated! :)
First off, comparing your boolean functions to true and false is redundant. For the sake of readablity and style you shouldn't do it. Instead do:
if (boolFunc())
...
if (!boolFunc())
...
Next, conditional expressions stop evaluating as soon as any part of the conditional can be ultimately cause the entire conditional to be evaluated to a falsy result. That's why your second condition is never called, and that's exactly how it's supposed to work. If for some reason you need them both to be called then you need to store the result of the calls to variables first and then use them in the conditional. Putting it all together and refactoring for readability the results would be
bool longConfirmation() { bool conf1 = longPrimaryConfirmation(); bool conf2 = longSecondaryConfirmation(); return conf1 && conf2; }
First off, comparing your boolean functions to true and false is redundant. For the sake of readablity and style you shouldn't do it. Instead do:
Next, conditional expressions stop evaluating as soon as any part of the conditional can be ultimately cause the entire conditional to be evaluated to a falsy result. That's why your second condition is never called, and that's exactly how it's supposed to work. If for some reason you need them both to be called then you need to store the result of the calls to variables first and then use them in the conditional. Putting it all together and refactoring for readability the results would be
Thanks a lot!
That's very insightful and a huge help!
Hi, I am having issues with this function above.
For some reason the function after the 'and' operand is not called.
The 'Long_Secondary_Confirmation' function itself does work fine, it's just when in this position in an 'if statement' it fails to call.
Similarly when i switch the two functions around to have the code in the following format, the 'Long_Primary_Confirmation' function fails to call.
There are no errors in the code when compiled either
Any help or explanation for this would be greatly appreciated! :)
If the first condition is false the second is not checked. That is the reason why your second function is not called.
Run test1() and you will not get a zero divide error what proofs that after a==0 what is false the condition check is aborted.
Run test2() and you will get a zero divide error because the first condition is true and the second conditions produces the zero divide error.
void test1(){ int a = 1; int b = 0; if(a == 0 && 1/b == 1) Print("bla"); } void test2(){ int a = 0; int b = 0; if(a == 0 && 1/b == 1) Print("bla"); }
If the first condition is false the second is not checked. That is the reason why your second function is not called.
Run test1() and you will not get a zero divide error what proofs that after a==0 what is false the condition check is aborted.
Run test2() and you will get a zero divide error because the first condition is true and the second conditions produces the zero divide error.
On a separate example, may i ask why in my code below, the first line control condition (alertswitch is not equal to 3) is already false since global variable alertswitch has already been set to 3, yet when i run, it ignores the first statement and continue on evaluating the rest below it? (i want to evaluate this only once and not repeatedly in a loop)...even if BBConv....has been written without brackets, it should not be evaluated right? what am i missing?
if () {}... else if ( alertswitch != 3 && alertswitchPrevious != 3 && FramaCurrentPrice < botBB1 && BBConvDivergence == "NEUTRAL" || BBConvDivergence == "STRONG-LONG" && TotalScore >=2 ) { alertswitch = 3; alertcomment = "Frama-Extreme"; Check =1; //this goes to a switch statement with Check variable '1'. } else if ( alertswitch !=5) {do this instead ....Check = 5}
On a separate example, may i ask why in my code below, the first line control condition (alertswitch is not equal to 3) is already false since global variable alertswitch has already been set to 3, yet when i run, it ignores the first statement and continue on evaluating the rest below it? (i want to evaluate this only once and not repeatedly in a loop)...even if BBConv....has been written without brackets, it should not be evaluated right? what am i missing?
don't double post you will likely get ignored..
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I am having issues with this function above.
For some reason the function after the 'and' operand is not called.
The 'Long_Secondary_Confirmation' function itself does work fine, it's just when in this position in an 'if statement' it fails to call.
Similarly when i switch the two functions around to have the code in the following format, the 'Long_Primary_Confirmation' function fails to call.
There are no errors in the code when compiled either
Any help or explanation for this would be greatly appreciated! :)