if (((Num1> Num2 && Num3> Num4) || (Num5> Num6 && Num7> Num8)) && Num9> Num10)
Yes.
Pesonally, I lay them out something like below. I find it easier to keep track of brackets when it's broken up and I can also comment out a particular argument if I need without having to re build the statement
if ( var1>var2 && (var3<var4 || var3>=var5) && (var6>var8 || (var7>var8|| var7>var9)) // && var10>var11 )
Also the successive &&'s can be split into nested if's to improve the backtesting speed if its an issue.
A simple start with the OP's example would be to pull the Num9>Num10 expression out as the first if of the nest:
if(Num9>Num10) { if(Num1>Num2) { if(Num3>Num4) { Do some stuff... } } else if(Num5>Num6) { if(Num7>Num8) { Do some stuff... } } }
That way no cpu cycles are wasted computing expressions that for an already known invalid logic tree.
Thank you Philip, you explain very well.
K-ernet wrote >>
if (((Num1> Num2 && Num3> Num4) || (Num5> Num6 && Num7> Num8)) && Num9> Num10)
When you get complicated booleans, for readability I prefer to use variables:
//if (((Num1> Num2 && Num3> Num4) || (Num5> Num6 && Num7> Num8)) && Num9> Num10) bool maUp = (EMA5 > EMA8 && EMA8 > EMA 13), anotherUp = (Num5 > num6 && Num7 > Num8), eitherUp = maUp || anotherUp, lastly = (Num9 > Num10); if ( eitherUp && lastly ) ...Properly named booleans can make your code much more readable, and if the final logic test doesn't read right, you probably have a mistake.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello all,
I have this question, if is possibile to resolve... Can i make in a IF operation made more level in one parenthesis??? Example:
if (((Num1> Num2 && Num3> Num4) || (Num5> Num6 && Num7> Num8)) && Num9> Num10)
Num1-2-3-4 data and Num5-6-7-8 is possible to separate to their function? Like a math expression:
if {[(Num1> Num2 && Num3> Num4) || (Num5> Num6 && Num7> Num8)] && Num9> Num10}