'How to make the counting of an event's occurrences started from the occurrence of a(nother) certain event? V5

The function to be used in this case is:

cnt = math.sum(cond ? 1 : 0, len)

In my (defective) example:

NumberOfOccurrencesToBeCounted = math.sum(OccurrencesToBeCounted ? 1 : 0, ta.barssince(EventWeWantToMakeTheCountingStartedFrom))

ta.barssince() returns with an integer which should be right the same number we should enter in the place of len, still this error happens:

Study Error: Invalid value of the 'length' argument (0.0) in the "sum" function. It must be > 0.

It works with a high number instead of ta.barssince(event).

Code for reproduction:

isNewPeriod = anchor == "Earnings" ? new_earnings :
 anchor == "Dividends" ? new_dividends :
 anchor == "Splits" ? new_split :
 na(VWAPsrc[1]) ? true :
 anchor == "Session" ? timeChange("D") :
 anchor == "Week" ? timeChange("W") :
 anchor == "Month" ? timeChange("M") :
 anchor == "Quarter" ? timeChange("3M") :
 anchor == "Year" ? timeChange("12M") :
 anchor == "Decade" ? timeChange("12M") and year % 10 == 0 :
 anchor == "Century" ? timeChange("12M") and year % 100 == 0 :
 false

TheEventForExample = open > close
NumberOfOccurrences = math.sum(TheEventForExample ? 1 : 0, int(ta.barssince(isNewPeriod)))


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source