Sum Function clarification

Kindly refer to the below image:


AFL Code:

NewDay = Status("firstbarinrange") OR Day() != Ref(Day(), -1);
BarsSince_NewDay = BarsSince(NewDay) + 1;
SumDays = Sum(NewDay, BarsSince_NewDay);

Filter = 1;
AddColumn(NewDay, "New Day");
AddColumn(BarsSince_NewDay, "Bars Since New Day");
AddColumn(SumDays, "Sum Days");

The Sum Function is not giving any results on the first day and am not sure of the reason, if any of the seniors could help on this please.

1 Like

You should be using SumSince() function instead

Using the Sum in a way you do (variable period) is significantly less efficient.

1 Like

Noted Dr. Tomasz, thank you!

As for the reason why it shows NULL (Emtpy) for first day:
There has been change in Sum/MA functions in AB 6.03.

So since it returns NULL in first element in your example the sum for the whole day becomes NULL also.

1 Like

To start accumulating values from the beginning of the array, you could use the Cum() function instead of Sum() or SumSince():

CumDays = Cum(NewDay);

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.