By tomorrow the following new function will be available:

LoopSum(“formula”,iterations[,start,increment])

Executes the formula a number of times and returns the sum. A special variable ‘CTR’ (short for counter) is available for the formula that is incremented each time.

Parameters:

formula: the formula to be executed in the loop. The special CTR variable must be used here.

iterations: the number of times to execute the formula (2-50)

start: the starting value of CTR(default 0)

increment: how much CTR is incremented for each iteration (default 1)

Example 1 Recreating the simple moving average. You can recreate SMA(5) like this:

LoopSum(“Close(CTR)”,5) / 5

This is also the same as:

(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 Number of years the annual revenues have increased for the past 5 years:

LoopSum(“ItemA(RTLR,CTR) > ItemA(RTLR,CTR+1)”,5)

The condition is evaluated 5 times and the sum returns from 0-5. When 5 all annual sales have increased from previous year.

Conclusion

This is a very powerful function. I’ve seen many examples of very long formulas that can be recreated with LoopSum in much fewer characters and less error prone. Le us know of great examples for using this function.

Once again, it will be made available tomorrow.