You can call up other functions (helper programs) from within your custom study. A function can be a built-in helper program that performs a certain task, or any program that is visible in the TeleTrader WorkStation interface. For built-in functions, you cannot see or change the source code all other functions can be displayed in the Study Editor.

You can use the results of a function in your own calculations, or make the other function draw your own results on the screen, or both. The TeleTrader Language includes some basic functions that you can use for such operations as summing up values or drawing a line on the screen. Using functions can be very convenient, as you do not have to write all the code that it includes yourself, and can re-use them several times. You can also use programs you have written yourself as a function, when you call it from inside another program.

When you call a function that returns a value, you will usually use it as part of an expression. This means, you use the value that is returned by the function for some calculation, assign its value to a variable or use it as part of a condition.

When you call a function that draws your results on the screen, you usually use it on its own, that means the function call makes up the complete command statement on this line.

To call up a function, you have to know what inputs it expects. In the same way as you define parameters for your own programs, all other functions also expect one or more parameters as an input. The list of parameters that you supply must match the type of parameters that are needed by the function if the function needs a numeric input, you cannot call it up with a text input, for example.

Similarly, you have to be aware of the kind of output that a function returns. Some functions might return a numeric value, that you can use in your calculations; some functions return a logical value, that you can e.g. use inside a condition; some functions return nothing, but perform an action, such as drawing something on the screen.

Note You can also apply functions only to specific bars. The syntax is similar to that of addressing past and future bars (see Accessing the Time Series). For example, you can draw a marker at the Close of the bar before the current bar by using DrawMarker[1]("Marker1", Source.Close, True, "PastBar").

You can find all built-in functions, their expected parameters and outputs in the Function Reference.

Syntax

FunctionName(Parameter1, Parameter2, ...)

FunctionName

Name of the function that you want to call up.

Some functions both calculate and return a result and draw that result on the screen. If you only need the calculated results of such a function, add a pound sign #, NoPlot or NoDraw in front of its name, for example #movs.

Parameter1

Parameter2

Parameters that you pass to the function.

These can be fixed values, parameters or variables of your own program, expressions, or even other function calls.

Examples

Draw an area between two values:

DrawArea("Area", middleBand1, middleBand2);

Get a value from the function Sum and store it in the variable middleBand:

middleBand = Sum(source, 50);

Use the output of a function as a condition in an If statement, then draw a line with a second function that takes the result of a third function as an input parameter:

If IsValid(Source.High) Then
DrawLine("PDI", pdi(Source, period));