Print Page  
Advanced Functions / Loop Functions
LoopMin("formula(CTR)", iterations[, start=0, increment=1, noNAs=FALSE, break=FALSE])
Full Description

These “Loop” functions return a summary statistic from a series of historical values evaluated using a Loop Function. Loop functions contain a CTR variable that is iterated through with specific increments to create the desired offset for the formula. 

LoopAvg(formula(CTR)", iterations[, start, increment, noNAs, break])
Average of the values

LoopSum(formula(CTR)", iterations[, start, increment, noNAs, break])
Sum of the values

LoopProd(formula(CTR)", iterations[, start, increment, noNAs, break])
Product of the values

LoopMedian(formula(CTR)", iterations[, start, increment, noNAs, break])
Median of the values

LoopMax(formula(CTR)", iterations[, start, increment, noNAs, break])
Maximum value

LoopMin(formula(CTR)", iterations[, start, increment, noNAs, break])
Minimum value

LoopStdDev(formula(CTR)", iterations[, start, increment, noNAs, break])
Standard deviation of the values

LoopRelStdDev(formula(CTR)", iterations[, start, increment, noNAs, break])
Relative standard deviation is calculated as follows: RSD = 100 * (SD/Abs(mean)) 

LoopStreak(formula(CTR)", iterations[, start, increment, streak, recent)
Counts the number of consecutive times the formula evaluates to the streak type specified

Common Parameters

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) 

Special Parameters

noNAs: when set to 1 any NAs will return NA, when set to 0 (the default) NAs are skipped 
break: when set to 1 the loop will break when it encounters an NA and will return the result to that point, when set to 0 (the default) the function will return NA if it encounters any NA in the loop.
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 1

Recreating the simple moving average SMA(5) three different ways: 

LoopSum("Close(CTR)", 5) / 5
 or
LoopAvg("Close(CTR)", 5)
 or
(Close(0) + Close(1) + Close(2) + Close(3) + Close(4)) / 5

Example 2

Count the number of times the close price is greater than the previous day for the past 10 bars: 

LoopSum("Close(CTR) > Close(CTR + 1)", 10)

The ">" test is executed 10 times and returns either 1 (TRUE) or 0 (FALSE). The values are added together. The sum returns from 0-10, with 10 being stocks that have had higher closing prices for the past 10 bars vs the previous day. 

Example 3

Find companies that have increased quarterly income after tax at least 8 of the last 10 quarters 

LoopSum("IncAftTax(CTR, QTR) > IncAftTax(CTR + 1, QTR)", 10) >= 8

 

Example 4

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