Easylanguage Essentials

TradeStation EasyLanguage Tutorial
Multiple Output Functions
In this TradeStation EasyLanguage Tutorial we will show one of the most powerful methods in TradeStation EasyLanguage, which is developing multiple–output functions using by ref parameters. This concept allow you to write very reusable functions and we will use several TradeStation functions in our example.

A basic user function framework

User functions are used to make reusable calculations, for example to calculate indicator values, sorting, and so on. User functions have input parameters. These parameters can be either input parameters or input/output parameters. These parameters can also have various types. Some of these types are NumericSimple, NumericSeries, NumericRef, StringSimple, numericarrayref, numericarray, and StringRef.

TradeStation EasyLanguage is great – simple enough to pick up quickly and complex enough to do some pretty nifty analysis. Sure, sure, you C and C# coders can do anything – but for me it’s too hard. Plus I’m an old dog and stuck in my ways. Here are some TradeStation EasyLanguage resources to get started: TradeStation EasyLanguage PDFs. EasyLanguage, an innovative app that allows you to learn languages in a more easy way! The application allows you to play any video and merge two tracks of subtitles: one for the language from the learner and a second for your language, allowing you to learn the new words immediately that you do not know.

Easylanguage Essentials 2

A function can return a single value, but when we use byref, we can return many values from a function. Let’s look at several function shells. ByRef passes the memory address of a variable which we can then fill the contents of that memory address within the user functions. That is how byref works. Normal parameters, such as NumericSimple, NumericSeries, and Stringsimple all just copy the contents to an address on the function stack. This means it can copy data into the function but can not modify the values that are passed in. Only the variable types with Ref suffix can be modified.

Download

Let’s first look at a simple moving average function:

We can see that we can pass a price series. This series can be a scalar or a system for example Close, High or (Close+High+Low)/3 which would be a scalar which will be passed though and converted to a numeric series. We also have the Length parameter which is a simple numeric value. Another interesting thing about this function is the use of the error trapping routine for divide by zero.

Let’s now look at a simple example of using input/output variables.

Easylanguage EssentialsEasylanguage essentials book

This is a very powerful concept. In TradeStation, the best example of how to use this concept is in the linear regression functions:

This function gives us all of the variables that are used in regression models. Let’s look at the inputs for this function:

Essentials

We can see that we can predict any number of bars in the past or future, we can return the slope, angle, intercept and the value. This allows this one piece of code to be used for many wrapper functions as well as in more complex models and systems and only do these calculations once. Let’s look at an example of how TradeStation used this in a wrapper. Let’s first look at the complete linear regression function.

Easylanguage Essentials Tutorial

We will now create a linear regression slope function which uses the multiple output function from above. This is an example of creating these super functions and using wrappers to use them for multiple purposes.

Easylanguage Essentials 2

I hope this tutorial has explained how to use byref and make functions which return multiple outputs and how they can be used to simplify developing complex code and make valuable reusable functions.