|
An argument is a formula input--a value that is passed to the formula. You declare an Argument in a parenthetical statement appended to a formula name. For example,
MyFormula(MyFirstArgument, MySecondArgument,...)=<expression>
Here, the name of the formula is 'MyFormula'. The arguments of the formula appear between the parentheses and offset by commas (,).
Arguments enable you to write formulas that can be applied in a variety of circumstances. For example, you can write a formula that will calculate a percentage:
percentage(numerator,denominator)=(numerator/denominator)*100
Here, the percentage formula defines two arguments, numerator and denominator. Because the arguments are declared without setting them equal to a value, the formula requires a call with two values. To use this formula, you would write:
percentage(10,100) |
This call yields a value of 10.000
|
percentage($1.net,$1.last) |
This call calculates the percent move based on the previous.
|
percentage($1.last-$1.open,$1.last) |
This call calculates the percent move based on the open. |
These examples illustrate how a formula's arguments enable you to apply the formula in different ways.
Arguments can be declared with a value, a technique that is particularly useful in writing studies. For example, in the formula,
MyRSI(series, period = 14)=RSI(series, period)
the period argument is declared equal to 14. By setting the value in this way, you establish a default value for the argument and create a parameter for the study. The RSI() function requires two arguments, a data series, and a number of periods. By setting the period argument equal to 14 in the argument declaration, you create an adjustable parameter that defaults to 14:
While the MyRSI formula defaults to 14 periods, the number of periods is adjustable in the MyRSI parameters menu.
Declaring a Formula Study
To declare a formula study, the first argument you declare must be one of two parameters:
Parameter |
Function |
INPUT |
Creates an overlay formula. Values are rendered in the units of the underlying instrument in all Aspen windows.
|
SERIES |
Creates a conventional study formula. In chart windows, values are rendered in decimals. In quote windows, values are rendered in the units of the underlying instrument. |
If you declare either the SERIES or INPUT parameter, you can declare as many other parameters required to calculate your study.
Formula Study Parameters
Standard parameters are fundamental to the formula study’s graphical display. They are only necessary when you have declared either SERIES or INPUT as the first parameter.
Standard parameters provide control over study display. This control includes the operative price (open, high, low, etc.), the color, and the rendering technique (bar, line, histogram, etc.) used to draw the graph.
If omitted, standard parameters are provided automatically. There are three standard parameters:
Parameter |
Meaning |
Price |
The default operative price, i.e., open, high, low, close, et. al. |
Color |
The default graph element color rendered by the formula, i.e., red, yellow, blue, etc. |
Graph |
The graphing technique used by the formula, i.e., line, bars, histogram, etc. |
Currently, you cannot affect these parameters with arguments.
Other Parameters
In addition to study- and standard parameters, a parameter can be anything. You can, for example, declare an argument x and use it as a multiplier in the formula's expression. This argument could vary, depending on the needs of the calling formula.
If you declare a parameter that is not study related, the parameter must serve as a value in the formula's expression; if it does not, a syntax error will result.
Don't neglect this seemingly innocuous category of parameters, especially if you have any background in programming.
Aspen Graphics 4.0 introduces several key advances in formula writing:
©2008 Aspen Research Group, Ltd. All rights reserved. Terms of Use.