EasyLanguage is an easy-to-learn, but powerful, computer programming language for creating technical in-dicators and trading strategies for the TradeStation trading platform. EasyLanguage is designed by traders, for traders, to de scribe trading ideas to a co mputer in plain English-like. 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.
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.
“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 ;
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:
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.
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.
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.