TradeStation Strategies

In the TradeStation community, trading systems are referred to as “TradeStation Strategies”. TradeStation strategies have a special structure that you need to understand when designing them.

  1. Only strategies can include entry and exit signals. Functions cannot include this. This means that if we want to combine systems, then we need to use another technique. Historically, this was called “#include system”, but this is now only included for historical reasons.
  2. Strategies can be stacked using Insert -> Strategy or Format Strategy. They can also be designed for just exits or just entries.
  3. Strategies can deal with long trades, short trades, or both. They can also deal with exits.

A question I often get from people is “how do you start designing a TradeStation strategy?” We discuss this below.

TradeStation Stacking Signals

In TradeStation we can create strategies using several different methods.

  1. Code all the rules into one TradeStation EasyLanguage script.
  2. Combine your TradeStation EasyLanguage scripts with #include statements to create one strategy. This is now replaced by stacking trading signals using the Insert Strategy dialog box.

Let’s take a look at how method #2 works.

TradeStation Strategies

Let’s first insert our TradeStation strategies.

TradeStation Strategies

We will insert one of the canned strategies which are Bollinger band breakout counter trend systems for Long entries and Short entries.

TradeStation Strategies

After inserting it we will go to format and see what we are running as our strategy.

TradeStation Strategies

We can see that we are running both of these strategies. This feature allows you to develop simple strategies in TradeStation without coding. We also can optimize the parameters. First, let’s suppose we want to add a protective stop to this system. We go back to insert and can insert TradeStation’s built-in stop functions.

TradeStation Strategies

Now let’s set the stop functions and add them.

TradeStation Strategies

We select stop loss LX and stop loss SX.

TradeStation Strategies

When we go back to format we can now see what we selected and are running.

TradeStation Strategies

Now you can press properties for ALL.

TradeStation Strategies

Here we can set commission and slippage. Initial capital is not used for a strategy using one lot. We’re not coding any money management into this particular strategy.

TradeStation Strategies

We can select each of these and change the parameters or optimize them. In fact, you can even optimize all four of these systems if you want at the same time. The problem is when you optimize more than 4-5 parameters, you will have too many combinations and will need to use the genetic optimizer to make that optimization feasible. Although it may look good initially that you can use built-in signals, sometimes these components interact and don’t work as expected. Therefore, this is a great tool for beginners who are just learning TradeStation but this is not the way to build real strategies to trade. If you want to be a successful system trader you need to develop strategies which are custom coded and designed to be integrated, or designed and implemented as one script.

Let’s now discuss the framework of coding a TradeStation strategy in EasyLanguage.

General Template for TradeStation Strategies

Inputs:Parm1(10), Parm2(.01); {Add Parmeters by separating with “,”}
Vars: Var1(0),Var2(5); { add needed variable separated by “,” init values in (X)}
{ Add logic for calculating true/false conditions for signals }
{ Add signals for trades , can be entry for long , entry for short
Exit for long, exits for shorts, can be all for or any combination }
A signal can also just be a single , entry or exit }

Order Types

TradeStation enables you to precisely control the way you enter or exit the market when you are writing and testing trading strategies. There are four basic order types available using EasyLanguage-limit orders, stop orders, this bar on close orders, and next bar at market orders.

Limit
These orders differ depending on if you are selling or buying. Limit orders can only be placed on the next bar; which can be the next minute, the next 5 minutes, or the next day-depending on the data interval. A buy limit order enters the market on the next bar at the specified price or lower, and a sell short limit order enters the market on the next bar at the specified price or higher.



When you use a limit order to enter the market long, the order will be generated regardless of how much lower the next bar opens, and when you use a limit order to enter a short position, the order will be generated regardless of how much higher the next bar opens. This can be significant, particularly in the case of “gap up” bars (bars whose open is higher than the High of the previous bar), or “gap down” bars (bars whose open is lower than the low of the previous bar).

Stop
Stop orders are placed on the next bar if the stop price is triggered. By default, strategy stop prices are monitored by your local computer but you also have the option of sending them to the TradeStation stop server to be monitored.

This Bar On Close
Close orders are filled at the close of the current bar. TradeStation can place orders for the current bar only on the close price.

Next Bar At Market
Market orders are shown as filled upon the open of the next bar.

Entry and Exit Order Type Syntax

[CON Contracts] is optional number of contracts or shares.

Let’s look at the conditional part of the signal. You oftentimes have signals which fire at given times. This can be done with a in line if like the syntax we have or a block if, then or if then else.

If Condition1=true then

Entry Market Orders
If Condition1=true then Buy(“LE”) Next Bar [CON Contracts] at market;
If Condition2=true then Sell Short(“SE”) Next Bar [CON Contracts] at market;

Exit Market Orders
If Condition3=TRUE then Sell(“LX”) Next Bar [CON Contracts] at market;
If Condition4=TRUE then Buy to Cover(“SX”) Next Bar [CON Contracts] at market;

Entry Stop Orders
If Condition1=true then Buy(“LE”) Next Bar [CON Contracts] LEStopVal stop;
If Consition2=true then Sell Short(“SE”) Next Bar [CON Contracts] SEStopVal stop;

Exit Stop Orders
If Condition3=TRUE then Sell(“LX”) Next Bar [CON Contracts] LXPoint stop;
If Condition4=TRUE then Buy to Cover(“SX”) Next Bar [CON Contracts] SXPoint stop;

Entry Limit Orders
If Condition1=true then Buy(“LE”) Next Bar [CON Contracts] LEStopVal Limit;
If Condition2=true then Sell Short(“SE”) Next Bar [CON Contracts] SEStopVal Limit;

Exit Limit Orders
If Condition3=TRUE then Sell(“LX”) Next Bar [CON Contracts] LXPoint Limit;
If Condition4=TRUE then Buy to Cover(“SX”) Next Bar [CON Contracts] SXPoint Limit;

You can see in our syntax sample notes that we have text within the signal order, Buy, Sell Short, Sell, Buy to cover. For example, Buy(“LE”). This is optional but recommended as it names the signals. These names are shown in the trade by trade report. You also could just use “Buy” and that would give you a unnamed signal. In addition, signals can also be done unconditionally

Buy(“LE”) Next Bar LEStopVal Stop;

We have now laid out the general template of a strategy and the template for the active signals in a strategy, buy, sell short, sell, buy to cover. Eventually we will show examples using EasyLanaguage to translate your trading ideas into strategies and also show how to use the optimizer, genetic optimizer, and how to test a system to try to judge how robust it will be in the future in our next installments.