Switching code / trigger code

 
I do not post the full code, to make question very easy to understand.

Two cycles should go in order: A-B-A-B...

In others words: Cycle A should be activated only once,
Then goes cycle B, and everything repeats...
It is not working.

Logic code below:

y= 0

if x =0 then x= 1
(do A...)


================

x=0

if y =0, then y = 1
(do  B...)


 

Try 

else if(...)
 
  1. Drop x and rename y to bool isA. You only have two conditions A or B. B is !isA.
    You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
    X and y are meaningless, but if(isA) is a complete question. Once you do that, Marco's suggestion will make sense to you.

  2. Make sure isA is static or global.
 
Thank you.

Updating, as this is a little more complex:
x is for switching to A or B
y is for preventing to run A or B more than once before switching to another.


if upperTrendlineBrokenOnce= false then 
(do A...)
upperTrendlineBrokenOnce= true //run only once

lowerTrendlineBrokenOnce= false //switching to A


================


else if lowerTrendlineBrokenOnce=false, then 
(do  B...)

lowerTrendlineBrokenOnce = true //run only once

upperTrendlineBrokenOnce=false //switching to B