Use of Barsince(barsince)

#1
Hello,
Could you someone please explain the use of barsince in the below code?

Con = C < Ref( C, -4);
Buy9Bars = BarsSince(BarsSince(Con));Buy9Signal = Buy9Bars == 9;

Thanks
Bala
 
#2
Hello,
Could you someone please explain the use of barsince in the below code?

Con = C < Ref( C, -4);
Buy9Bars = BarsSince(BarsSince(Con));Buy9Signal = Buy9Bars == 9;

Thanks
Bala
better you would have posted the complete code, if exists.

Barssince (barssince) is redundant. Though it gave different value in the commentary window but seems senseless.

ROC(c) is similar example which gives weird value.
Better we ignore it.
 
#3
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;
 
#4
Here is explanation for barsince...

BarsSince provides how many bars have passed since the condition was most recently true (not since the condition was *first* true as suggested earlier in
the thread).

If the condition is true for the current bar, then BarsSince will return 0,
meaning zero bars have passed since last the condition was true.
 
Last edited:
#5
Here is explanation for barsince...

BarsSince provides how many bars have passed since the condition was most recently true (not since the condition was *first* true as suggested earlier in
the thread).

If the condition is true for the current bar, then BarsSince will return 0,
meaning zero bars have passed since last the condition was true.
Thanks
But how to use for since the condition was first true? I don't know how to use for the first condition with true with barssince?
Best regard