Question on Counting Loop

Hi every Amibroker experts,

I am trying to build a function (with a loop) to count my condition (e.g. C>Ref(C,-1) ). I want that it always resets to zero when the condition isn’t true and when it is true it should start again from zero.

How can I make it?

Thanks a lot!

closeabove = C>Ref(C,-1);
closebelow = C<=Ref(C,-1);
cond = IIF(closeabove,BarsSince(closebelow),0);
Plot(cond, "cond", colorDefault, styleOwnScale);

2 Likes

Hello,

You would not need a loop to do that.

x=BarsSince(C < Ref(C,-1));
Plot(C,"",colorBlack,styleLine);
Plot(x,"count",colorRed,styleHistogram);

Try this.

1 Like

Thanks a lot Anthony and awilson. This has solved my problem. It is much more simpler than I think. good luck on trading