Tutorial: Using Advanced Features
Writing Custom Functions
Writing Custom Entry/Exit Systems
Writing Custom Functions
i Tutorial Task
Learn to write a custom function.
TradingSolutions includes over 250 built-in functions and technical indicators. However, there may be times when you want to use your own custom formulas. Examples of this would be when you have a new indicator you would like to try or when you want to combine several steps into one formula.
For this example, let’s create a simple moving average. While this function is already included in TradingSolutions, the equation provides us with a straightforward example of how formula entry works.
A moving average is an average of the most recent values for each point in time. To calculate an average, you simply take the sum of the recent values and divide it by the number of values being included.
The resultant formula will look like this:
Div ( Sum ( Data, Period), Period)
Step-by-step Instructions
1. Press the Define Functions button in the toolbar.

Figure 1. Pressing "Define Functions".
Ä Note: If you cannot locate this button, you can also select this option from the Processing menu.
2. Create a group for your functions so you can keep them separate from those included with the software. Press the New… button beneath the list of Trading Solution Groups.
Ä Note: If you have already created a new group, simply select it from the list of groups and proceed to step 4.

Figure 2. Location of "New…" button for creating a new group.
3. Accept the default name of My Functions by pressing OK.
4. Create a new function in the selected group by pressing the New… button beneath the list of Function Definitions in the Selected Group.

Figure 3. Location of "New…" button for creating a new function.
5. Enter a Display Name for your function of My Moving Average and a Short Name of MyMA.

Figure 4. Entering the names for the function.
6. Enter a brief description, such as "My function for a tutorial exercise.".
![]()
Figure 5. Entering a description.
7. Press the Next button.
8. TradingSolutions formulas are entered from the outside in, so the first thing we want to put in our equation is the Divide function. Select Basic Math Functions from the Function Group list.

Figure 6. Selecting the "Basic Math Functions" group.
9. Select the Divide function from the Function Definitions in this Function Group.

Figure 7. Selecting the "Divide" function.
10. Press Insert into Formula. This will result in the formula at the top of the wizard looking like this.
![]()
Figure 8. Formula after Divide inserted.
11. Now insert a function to provide a sum of recent values. Select the Function Definition tab.

Figure 9. Location of "Function Definition" tab.
12. Don’t worry if you don’t know what group a function is in. With <All Groups> selected, scroll down through the alphabetical list of functions and select the Summation function.

Figure 10. Selecting the "Summation" function.
13. Press Insert into Formula. This will result in the formula at the top of the wizard looking like this.
![]()
Figure 11. Formula after Summation inserted.
14. We will specify the value to take the moving average of when we go to use the function. On the Input Field sub-page, press Create New Input….

Figure 12. Location of "Create New Input" button.
15. Accept the default values of naming this input "Data" and providing it as a data series. Press OK.

Figure 13. The Modify Input dialog.
16. Press Create New Input… and press OK again to repeat these steps and create a Period input.
![]()
Figure 14. Formula after both inputs added.
17. Now, to calculate a moving average, we want to divide the sum by the period. Select Period from the list of inputs.

Figure 15. Selecting the "Period" input.
18. Press Insert into Formula. This will result in the formula at the top of the wizard looking like this.
![]()
Figure 16. Formula after Period inserted.
19. Press the Next button.
20. On the Verify Inputs page, press Finish to create your function.
21. Press Close. You can now use this new function directly as an indicator, as an optimizable input to predictions, or anywhere else you would use an existing function.
Congratulations!
You have learned the basics of writing custom functions in TradingSolutions. These same principles of formula entry can be used to write custom entry/exit systems and alerts, as well. In the next tutorial, we’ll see a slightly more complex example that builds on these principles.
_ Continue to the next task.