Creating Your Own Indices
Or performing a calculation on all of the datasets in a list
Suppose you wish to create an Equally-weighted Average of the Dow Jones 30 Industrials. The normal DJIA weights some stocks more than others and you want to eliminate the weighting factors.
First create a list of the 30 stocks, and get their prices. Let’s call the list “Dow30”. Then create the following command set, which we will explain in detail below:

Line 1 resets the temporary datasets.
Line 2 starts the loop, calling up the list “Dow30”. The loop then performs computations in the lines between :for and :endfor sequentially on all datasets in the list Dow30.
Line 3 involves the loop function count. It tells you the number of the current value of #1 in the list. That is, #1 represents each name in a list successively. There might be 20 or 200 names in that list. If #1 currently holds the name of the third dataset in the list, then “count 1” would be 3. If #1 currently holds the name of the ninety-eighth dataset in the list, then “count 1” would be 98. If you were also using the variable #2, you would access its count by “count 2”. Thus line 3 is only true when #1 contains the name of the first stock. This stock is initially assigned to resultdata.
For all subsequent datasets in the list, action goes to line 6, where the stock price is added to the current value of resultdata. When the loop finishes, resultdata is a dataset that, on each date, holds the sum of the data for all Dow 30 stocks on that date.
Line 9 takes resultdata and divides it by the length of the list (i.e. 30), and renames the result resultdata.
Line 10 simply requests the value resultdata, which would not otherwise appear, as the function “gets” calculates values without showing them. Line 11 stops the autoplay operation.
reset
:for #1 :in Dow30
:if (count 1) = 1
resultdata gets #1
:else
resultdata gets #1 plus resultdata
:endif
:endfor
resultdata gets (resultdata / (length 'Dow30'))
resultdata
:stop