Can someone explain why adding "||" options kills original trigger

 

Hello gurus,

my original line of code which triggers entry nicely in Strategy Tester as follows : 

  //my trigger for ENTRY
        ...
        && (gCurrentPrice > gPbarEntryLow )
        && noOfLadders <0...etc.

when i run it again after adding || options to increase number of potential trigger points as follows kills the trigger itself and nothing gets done. (no ENTRY)

  //same Entry with options added
        ...
	&& (gCurrentPrice > gPbarEntryLow
         || DeM5Proc == "DeMSHORT" 
         || ( DeM5Score ==-1 && gCurrentPrice > botBB2 )
         )
        && noOfLadders <0...

Thanks in advance for any guidance! 

 

Try putting parenthesis to each one of the separate options, in some cases the boolean conditions can get combined in "unexpected" ways

  //same Entry with options added
      ...
      && (
            (gCurrentPrice > gPbarEntryLow) ||
            (DeM5Proc == "DeMSHORT") ||
            ( (DeM5Score ==-1) && (gCurrentPrice > botBB2) )
         )
      && (noOfLadders <0)
      ...

If it doesn't work yet, then revise the logic (simplify, make parts into functions...) and the values of each variable in case the error is there

 
Manuel Alejandro Cercos Perez #:

Try putting parenthesis to each one of the separate options, in some cases the boolean conditions can get combined in "unexpected" ways

If it doesn't work yet, then revise the logic (simplify, make parts into functions...) and the values of each variable in case the error is there

thank you manuel for quick assistance.

i tried grouping in parenthesis as you have shown and it still does not work.

strangely enough, after a few revisions and i finally reverted back to the original line, even that suddenly is not triggering anymore! ( i do not see any other changes i've done) ...frustrating...

anyway, in my limited coding knowledge, i cant think of a way to make "parts into functions" to simplify. could you share me some pointers? 

 
JimSingadventure #:

thank you manuel for quick assistance.

i tried grouping in parenthesis as you have shown and it still does not work.

strangely enough, after a few revisions and i finally reverted back to the original line, even that suddenly is not triggering anymore! ( i do not see any other changes i've done) ...frustrating...

anyway, in my limited coding knowledge, i cant think of a way to make "parts into functions" to simplify. could you share me some pointers? 

Moving big chunks of code that are part of the same functional unit or serve the same purpose into a separate function helps make your code clearer. I believe that's what Manuel means. For example, even though it's just a very silly example, but hopefully you can see the difference...:

  //same Entry with options added
      ...
      && (
            (gCurrentPrice > gPbarEntryLow) ||
            (DeM5Proc == "DeMSHORT") ||
            ( (DeM5Score ==-1) && (gCurrentPrice > botBB2) )
         )
      && (noOfLadders <0)
      ...


...could be expressed as:

  // same Entry with options added
      ...
      && IsConditionOK() && noOfLadders < 0
      ...

  // evaluates a complex expression and returns true or false
      bool IsConditionOK(void) {
        return(
            (gCurrentPrice > gPbarEntryLow) ||
            (DeM5Proc == "DeMSHORT") ||
            ((DeM5Score ==-1) && (gCurrentPrice > botBB2))
        );
      }

Even now it makes a difference when it comes to clarity - just imagine when you have thousands of lines of code and long and complex expressions. Structuring and compartmentalizing your code is not only easy to read, but it's also a good programming habit.

Hope that helps.

 
No need for a function call. Just set a variable.
bool IsConditionOK = 
            gCurrentPrice > gPbarEntryLow
         || DeM5Proc == "DeMSHORT"
         || (DeM5Score ==-1 && gCurrentPrice > botBB2);
 
Carlos Moreno Gonzalez #:

Moving big chunks of code that are part of the same functional unit or serve the same purpose into a separate function helps make your code clearer. I believe that's what Manuel means. For example, even though it's just a very silly example, but hopefully you can see the difference...:


...could be expressed as:

Even now it makes a difference when it comes to clarity - just imagine when you have thousands of lines of code and long and complex expressions. Structuring and compartmentalizing your code is not only easy to read, but it's also a good programming habit.

Hope that helps.

thanks carlos, understand that but my question remains that by changing the conditions to a function, it still does not solve the original problem of "||" conditions being unexpectedly combined (as pointed out by manuel) to make the options kill the single trigger.

appreciate the shortcut by william but the problem of || remains.

 
JimSingadventure #:

thanks carlos, understand that but my question remains that by changing the conditions to a function, it still does not solve the original problem of "||" conditions being unexpectedly combined (as pointed out by manuel) to make the options kill the single trigger.

appreciate the shortcut by william but the problem of || remains.

But your issue has nothing to do with the condition. You said yourself that after removing the additional condition and putting it back the way it was before it didn't work either. Your problem is somewhere else, the new expression just adds some extra conditions to the original one, but that original should still work. Again, your problem is somewhere else. Use break points and use the debugging window to see the value of each variable in order to figure out what's going on.

 
 
Carlos Moreno Gonzalez #:

But your issue has nothing to do with the condition. You said yourself that after removing the additional condition and putting it back the way it was before it didn't work either. Your problem is somewhere else, the new expression just adds some extra conditions to the original one, but that original should still work. Again, your problem is somewhere else. Use break points and use the debugging window to see the value of each variable in order to figure out what's going on.

ok, i'll try to learn how to use breakpoints in debug mode...thanks for suggestion.

 
Soewono Effendi #:
You might want to read this:



yes, thanks.

Reason: