Easylanguage Essentials

TradeStation Securities, Inc. Is an SEC-licensed broker dealer and a CFTC-licensed futures commission merchant (FCM), and a member of FINRA, SIPC, CME, NFA and several equities and futures exchanges, which offers to self-directed investors and traders Equities accounts for stocks, exchange-traded products (such as ETFs) and equity and index options, and Futures accounts for commodity. EasyLanguage Essentials Programmer s Guide is a programmers introductio n to TradeStation’s EasyLanguage programming tools. This book is based on the current release of TradeStation 8.3. It is assumed that the reader has access to the TradeStation platform.

  1. Easylanguage Essentials Free
  2. Easylanguage Essentials Software
  3. Easylanguage Essentials Book
  4. Easylanguage Essentials Download

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

Easylanguage Essentials Free

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.

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.

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.

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:

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.

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.

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.

Scaling-Out with EasyLanguage – Part I

Scaling-in is the process of entering a position using multiple entries, and scaling-out is the process of closing a strategy position by using multiple exits. The position being exited could have been created from multiple separate entries (pyramiding), or a single entry which bought or sold short more than one share or contract.

To understand how scaling-out works in EasyLanguage, it’s useful to think in terms of a 3-level hierarchy: strategy positions, entry groups, and individual entries. Strategies take long or short positions, the strategy positions are made up of groups of entries, and each entry group is composed of individual entries generated by a specific entry statement.

Each individual entry statement used to build a position can be named or unnamed. If an entry statement is given a name such as “B1” via the syntax “buy (“B1″) next bar at market;” that statement is associated with a named entry group, in this case, the “B1” entry group.

Exit orders do not “reverse-pyramid”

The first thing that users often have trouble with when writing scaling-out code is the issue of “matching” exits to entries. In EasyLanguage, each individual exit statement will apply to each entry in a position only once. So while entry statements can pyramid; repeatedly buying into a position, exit statements do not “reverse-pyramid” and will be applied to each given entry only once.

As an example of this, let’s consider a one entry position containing 4 contracts, and we would like to scale out of the position in 25% increments, or one contract at a time. If we use an exit statement such as:

Sell 1 contract next bar at TargetPrice limit ;

this exit will be applied to the 4 contract entry just once and will sell only 1-contract in total. Even if the exit statement is repeated on subsequent bars the 1-contract exit statement will apply to the individual 4-contract entry, just once.

Scaling out of a multiple contract single-entry position requires issuing multiple exit statements. To do this, a variable can be used as a counter which controls the cycling through of separate exit statements so that a different exit statement is issued each time part of the position needs to be closed. Below is a useful illustration of this technique:

Scaling-Out with EasyLanguage Part II

This is part-II of a three-part series discussing the scaling-out behavior of EasyLanguage. In the first part of this series, the basic EasyLanguage syntax for scaling out of a position was discussed. This week I’ll continue with this topic in more depth, describing the “From Entry” exit syntax.

Easylanguage essentials download

“From Entry” Exit Syntax
When issuing exit statements to scale out of a position, an individual exit will apply to all entry groups that created the position, unless the exit is restricted to a specific entry group. The “From Entry” syntax is used to restrict an exit statement so that an exit is only applied to a specific named entry group. For example, the exit statement:

Sell 1 contract next bar at market ;

Easylanguage Essentials Software

will apply to each separate entry which built a position. If the position was created with a single entry, the exit statement will sell just 1 contract from the entry. Now, if the position was created from 2 separate 1-contract entries, e.g., a 1 contract “B1” and 1 contract “B2” entry, the exit statement will sell one contract from each entry, for a total of 2 contracts sold. To exit from just the “B2” entry you would use the from entry syntax:

Sell 1 contract from entry (“B2”) next bar at market ;

This would close 1 contract from the B2 entry and would leave the position still open with the B1 contracts still remaining.

If you have multiple entries in each entry group, the behavior is a bit more complex. Let’s now assume the position was created using two entry statements:

Easylanguage Essentials

if Condition1 then Buy (“B1”) 2 contracts next bar at market;
if Condition2 then Buy (“B2”) 2 contracts next bar at market;

and Condition1 was true for 3 bars, and Condition2 was true for 2 bars. The strategy position would be long a total of 10 contracts: 6 contracts coming from the 3 separate 2-contract entries of the “B1” entry group, and 4 contracts coming from the 2 separate 2-contract entries of the “B2” entry group.

If a 1-contract sell statement is issued to sell from the “B1” entry group:

Sell 1 contract from entry (“B1”) next bar at market ;

this exit statement would apply once to each of the 3 entries in the “B1” entry group, selling a total of 3 contracts all on one bar, and leaving a 1 contract open entry in each of the “B1″ entries. The exit would not apply to the”B2” entry group since the “from entry” syntax restricted the exit to just the “B1” entries – leaving the position open with 7 contracts remaining.

Easylanguage Essentials Book

Scaling-Out with EasyLanguage Part III

This is part-III of a three-part series discussing the scaling-out behavior of EasyLanguage. In this final part of the series I’ll discuss the usage of “Total” keyword within an exit statement, and the combined use of “From Entry” with the Total keyword within the same exit statement.

Easylanguage Essentials Download

Total Keyword
When scaling out of a position, if you want an exit to sell a specific total number of shares or contracts against all entries for a given bar, you can use the Total keyword. For example, adding the keyword Total to an exit statement such as:

Sell 1 contract Total next bar at market ;

will sell a total of 1 contract against all entries in a position, each bar, in a first-in-first-out (FIFO) ordering. If a 10-contract position was created through 5 separate “B1” and “B2” named entries (see part II for the example entry statements used to build the position), the 1-contract total exit statement would apply once to each entry in the “B1” and “B2” entry groups, selling 5 contracts in total, exiting once against each entry, but selling only a total of 1 contract per-bar.

Using “From Entry” with the Total Keyword
If the “From Entry” and Total keywords are combined in an exit statement such as:

Sell 1 contract Total From Entry (“B1”) next bar at market ;

this exit syntax will result in the exiting of 1 total contract from each entry within the named entry group “B1”. For example, if the long position was created with separate “B1” and “B2” entry groups, i.e., 3 separate 2-contract entries in entry group “B1” and 2 separate 2-contract entries in entry group “B2”, the ‘From Entry (“B1”)’ part of the exit statement would restrict the exit statement to just the “B1” entries, and the use of the Total keyword would further restrict the exit statement to a total of 1 contracts from all entries for a given bar.

So using the ‘From Entry (“B1”)’ syntax by itself would cause 1 contract to be sold from each of the 3 entries that are part of the B1 entry group, all on the same bar – selling 3 contracts in total on one bar, from the 10 contract position.

Adding the “1 contract Total” to the exit statement will restrict the total number of contracts sold to a maximum of 1-per-bar, so now a total of 3 contracts will still be sold, but only at a rate of 1-contract each bar, causing the selling to take place over multiple bars.


Updated on 2020年2月14日

Was this article helpful?

Related Articles