Example: Writing a Moving Average Function

 

This is an example of how to enter a simple formula using the Formula Entry controls.

 

A moving average is a summation of the n most recent values divided by n. In formula notation, it would appear as follows:

 

Div ( Sum ( Data , Period ) , Period )

 

In other words, take the summation of an input field called "Value" over the last "Period" values and divide that by "Period".

 

To enter this as a formula, you would use the following steps:

1.    Use the Function Definition sub-page to select the Divide function. To do this, choose the Divide function from the Function Definition list and press the Insert button. The current selection will automatically advance to the first parameter of the Divide function.

2.    The text "Value 1" should now be selected in the Formula View. This is the first parameter of the Divide function. Use the Function Definition sub-page to select the Summation function. Again, the current selection will automatically advance, this time to the first parameter of the Summation function.

3.    The text "Data" should now be selected in the Formula View. This is the first parameter of the Summation function, which adds the most recent n values of a data series together. The specific data series will be specified when the function definition is used, so we want to make this value an input field.

To do this, use the Input Field sub-page and press the
Create a New Input… button, which will display the Modify Input Dialog. To accept the default name and type, press the OK button. The first parameter of the Summation function will be replaced with "Data", which indicates that it is an input field named "Data".

4.    The text "Period" should now be selected in the Formula View. This is the second parameter of the Summation function. This is also the length of our moving average, which will also be specified when the function definition is used. Therefore, this value should also be an input field.

To do this, use the Input Field sub-page and press the
Create a New Input… button to create an input field called "Period" in the same way the "Data" input field was created.

5.    The text "Value 2" should now be selected in the Formula View. This is the second parameter to the Divide function. You can check this by noting that the "Div" function in the Formula view is bold and the prompt at the bottom of the Formula View references the Divide function.

Since we are dividing the summation by the length of our moving average, we want this value to be the same as the value we used for that length. In this case, we want to reuse the value of the Period input field. To do this, use the Input Field sub-page and select the Period input field, then press the
Insert button.

How Did I Get Here?

This is an example of Formula Entry.