How to use the bars of today for looping

i need to use the bars for a looping function .

TN=091500 ;
T = TimeNum();
BB =(T-TN)/100;

Need to use this BB inside a for loop .

Refer to the manual

You need to use Array Subscript operator [] to access elements at specified index, like BB[ i ] where i is an integer from 0 to (BarCount - 1)

But i am getting the below error


Looking at your code and doubt, i suggest you to go through this very carefully.

There is an example at the bottom as well.

BB is an Array and Barcount is Scalar. Also, what are you trying to achieve by comparing with BarCount ?
BarCount can change.

I have checked the articles . Now the bar count is not a problem. The array BB has to be used again in the loop which as shown in the pic is not possible.

So I m trying to find ways to define within the loop.

The above code is used to find how many bars on a single day is above vwap .


first of all all your loop code is incorrect. Also Filter within loop makes no sense.

Secondly you do not need single loop at all for what you do.

newday = dn != Ref(dn, -1);
BB = newday;// tn == 91500;//

j = SumSince(BB, Close_price > VV);
k = SumSince(BB, Close_price < VV);
m = SumSince(BB, Close_price == VV);


Are you suggesting something like this is enough to the desired results .

Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));
StartBar = ValueWhen(TimeNum() == 091500, BarIndex());
TodayVolume = Sum(V,Bars_so_far_today);
IIf (BarIndex() >= StartBar, VWAP = Sum (C * V, Bars_so_far_today ) / TodayVolume,0);
Plot (VWAP,"VWAP",colorRed, styleThick);
newday = Day() != Ref(Day(), -1);
BB = newday;// tn == 91500;

j = Sum(BB, Close_price > VV);
k = Sum(BB, Close_price < VV);
m = Sum(BB, Close_price == VV);

AddColumn(j,"# of bars above",1.0);
AddColumn(k,"# of bars below",1.0);
AddColumn(m,"# of bars equal",1.0);


Did you see me using Sum function in my post?

I was clearly using SumSince function.

BTW, in addtion you are using IIf function incorrectly. It is a function which returns result.

I am out of this thread...

... everything has been said

... and because of smelling (old) multi-ID. Looks familiar to me.


ok , Sumsince is a New function , i am using an old amibroker which is not supporting the Function.Thanks for the help and comments.

I have used SUMSINCE function as well and its not generating any results .

What version of AmiBroker are you using? Are you a Registered User?

@Srinathram - you need to BUY AmiBroker in order to use it. Once you buy the program you will have SumSince function.

1 Like