New function LoopStreak for counting consecutive occurrences

New function is now available

LoopStreak ("formula(CTR)", iterations, start=0, increment=1, streak=#Positive, recent=TRUE )

Counts the number of consecutive times the formula evaluates to the streak type specified

formula: the formula to be executed in the loop.
iterations: the number of times to execute the formula (up to 502)
start: the starting value of CTR (default 0)
increment: how much CTR is incremented for each iteration (default 1)
streak: #Positive, #NotPositive, #Increasing, #NotIncreasing
recent: set this to TRUE to stop when streak fails. Use FALSE to evaluate all iterations and find the longest streak.

Example

Find companies that have closed higher than previous day for 10 trading days in a row

LoopStreak("close(CTR)", 21, 0, 1, #Increasing, TRUE) > 10

4 Likes

Thanks- excited to try it out with custom formulas

Excellent. Makes a good sell rule:
LoopStreak("close(CTR)", 21, 0, 1, #Increasing, TRUE) > 5

Thanks Marco. Very nice

@geov That improved mine as well, with a small modification.