Thank you. Here is the major part of the code.
Con = C < Ref( C, -4);
Buy9Bars = BarsSince(BarsSince(Con));
Buy9Signal = Buy9Bars == 9;
Con = Ref(C, -9) >= Ref(C, -13);
Buy9Req = Buy9Signal AND Con;
Con1 = (H >= Ref(L, -3)) OR ( Ref(H, -1) >= Ref(L, -3));
Con2 = (H >= Ref(L, -4)) OR ( Ref(H, -1) >= Ref(L, -4));
Con3 = (H >= Ref(L, -5)) OR ( Ref(H, -1) >= Ref(L, -5));
Con4 = (H >= Ref(L, -6)) OR ( Ref(H, -1) >= Ref(L, -6));
Con5 = (H >= Ref(L, -7)) OR ( Ref(H, -1) >= Ref(L, -7));
Buy9Intr = Buy9Req AND (Con1 OR Con2 OR Con3 OR Con4 OR Con5);
Con = C > Ref( C, -4);
Sell9Bars = BarsSince(BarsSince(Con));
Sell9Signal = Sell9Bars == 9;
Con = Ref(C, -9) < Ref(C, -13);
Sell9Req = Sell9Signal AND Con;
Con1 = (L <= Ref(H, -3)) OR ( Ref(L, -1) <= Ref(H, -3));
Con2 = (L <= Ref(H, -4)) OR ( Ref(L, -1) <= Ref(H, -4));
Con3 = (L <= Ref(H, -5)) OR ( Ref(L, -1) <= Ref(H, -5));
Con4 = (L <= Ref(H, -6)) OR ( Ref(L, -1) <= Ref(H, -6));
Con5 = (L <= Ref(H, -7)) OR ( Ref(L, -1) <= Ref(H, -7));
Sell9Intr = Sell9Req AND (Con1 OR Con2 OR Con3 OR Con4 OR Con5);
if(StrToNum(NumToStr(Buy9Intr))) Sell9Intr = False;
if(StrToNum(NumToStr(Sell9Intr))) Buy9Intr = False;
BuySignal = Flip(Buy9Intr, Sell9Intr);
Con = C < Ref(L, -2);
Buy13Count = Sum(Con AND BuySignal, BarsSince(Buy9Intr));
Buy13Signal = Buy13Count == 13;
Con = C > Ref(H, -2);
Sell13Count = Sum(Con AND NOT BuySignal, BarsSince(Sell9Intr));
Sell13Signal = Sell13Count == 13;