Bracket Trader “3rd party entry” User Guide

Updated for version 2.15a and above

Introduction

Bracket Trader now supports 3rd party entry using a text file : you define its path/name in ATS FileName. If you have used Q’s AutoQtion before (thanks to Q’ for this), you can just use all your old scripts as Bracket Trader use the same script language.

Bracket Trader is set up to check this file every 300 ms (actual polling frequency depends on the CPU speed and on how many programs are running at the same time) and if a new order has been written to this file, an order is automatically sent to IB. The 3rd party application is used to generate the entry signal, which is then managed by Bracket Trader. While Bracket Trader is managing a 3rd party trade, it rejects all new signals until the trade is exited.

In the following documentation, we have chosen to give examples using futures but this feature also works exactly the same for stocks. If you trade stocks, be aware that the exchange chosen will be the one defined in Bracket Trader database (recommended choice is SMART when you setup the symbol).

You also need to be aware that so far the 3rd party entry feature of Bracket Trader will use the symbol that is selected and active in your Bracket Trader and is not able to switch to another symbol. For this functionality, we recommend to use BT-ATS available on request.

Another important thing to know is that the initial number of contracts/stocks is always the one decided by the 3rd party application.

Bracket Trader supports as decision making software all the programs that can write text files : in this guide we will talk about Tradestation, Wealth-Lab, eSignal and Ensign but other tools are also available for the same purpose.

General comment on 3rd party entry purpose

The aim of this feature is NOT to provide a completely automatic trading solution that will allow you to go out while your computer is trading for you. Be aware of the following problems that can happen and that Bracket Trader can’t prevent :

* Your ISP can disconnect,
* TWS can disconnect,
* TWS specific market access can go down for a while,
* The exchange can go down for a while,
* Your PC can crash,
* Your eSignal / Qchart can go down,
* Your Tradestation/Wealth-Lab/eSignal/Ensign or others can crash or stop collecting data,
* Power can be cut in your building (problem is solved by buying a UPS)

The aim of this feature is to allow you to be less concentrated on your graphs as the computer will decide by itself if there is a BUY or SELL signal. It allows you to do other activities on your computer while checking once in a while if everything is ok. To enhance your comfort, Bracket Trader plays a sound every time a new 3rd party order is received.

Another application of 3rd party entry is the ability to follow multiple markets at the same time or manage one account manually while other accounts are managed by the computer.

Two advantages of your computer versus yourself :

* speed of decision
* discipline & lack of emotions.

 

Comment on the use of a text file solution

There is one advantage in using a text file : you can support every software available that can write a text file based on market information. There is one disadvantage also about it : there is no communication between Bracket Trader and your trading software. Bracket Trader works in best effort mode. Most of the time this will work perfectly but there are some order types that are better to use in this context : MKT, STP as they allow a sure execution.

If you use LMT orders in your programs, give them a bit of room and if you want to absolutely buy with a LMT order the last price, give your LMT order some room and add some extra ticks to it (In this case it is often better in narrow spread markets to use a MKT order).

As a summary, for indicator based systems that wants to buy directly when the signal is given, we recommend MKT or STP orders. For breakout systems, you can use LMT, STP, or STP LMT orders.

How to test 3rd party entry ?

To run Bracket Trader in demo mode, create a file using notepad and save it with the filename/path you have chosen at the configuration phase.

Create a few orders such as :

cxlplace,BUY,1,LMT,955.00,0

cancel,,,,,0

cxlplace,BUY,1,MKT,,0

cxlplace,SELL,2,LMT,955.25,0

cxlplace,BUY,5,STPLMT,959.00,958.00

place,SELL,2,STP,,953.00

modify,BUY,5,LMT,957.00,0

Type one line at a time and save it to a file to simulate an order flow.

We recommend you to use IB edemo to get used to the way 3rd party entry works.

Another way to test Bracket Trader: when asked, refuse the connection with TWS, you will see the orders arriving in the Trade Log after selecting 3rd party entry settings.

You can also use a log file by checking Log Signals.

Order Types in BracketTrader :

Using the same script language as the one already available in Q’s AutoTrader, Bracket Trader supports the following functions :

place : to place a new order if no existing order

cxlplace : to cancel an existing order and replace it with another OR place a new order where none existed before (this will be the most used feature)

modify : to modify an existing order

cancel : to cancel an existing order

Order structure :

Field1 Field2 Field3 Field4 Field5 Field6 Field7

place, BUY, #contracts, LMT, Limit price, 0

cxlplace, SELL, STP, , Stop price

modify, STPLMT, Limit price, Stop price

MKT, , 0

cancel , , , , , 0


Special note for BT-ATS users

BT-ATS is a standalone application that has the same feature set as AutoQtion : it supports 6 different systems at the same time instead of only one in the classical Bracket Trader. It adds two new features :

* First stop : instead of waiting for the next cycle to put your stop, the first stop is sent as soon as your entry order is received.
* ENTRY/EXIT tags to differentiate orders :
o cxlplace,SELL,4,STP,,834.50,ENTRY
o cxlplace,SELL,4,STP,,836.50,EXIT
* Error control : the 2nd of two exact orders fired consecutively for different purposes will not be sent out

Send me a mail to join bracket_traders private yahoogroup focusing on BT-ATS.

Order examples :

place,BUY,1,LMT,958.00,0 place a limit buy at 958

modify,BUY,5,LMT,957.00,0 change the buy limit to 957

cancel,,,,,0 cancel the previously placed order

place,BUY,7,STPLMT,901.00,900.00 place a buy stop limit trigger on 900

place,SELL,1,STPLMT,901.00,902.00 place a sell stop limit trigger on 902

cxlplace,SELL,2,STP,,980.00 cancel the buy stp limit and place sell stop

cxlplace,BUY,1,MKT,,0

Please note that you must print 5 commas in every order . the Cancel order must end with a 0. The STP order must contain a ,, ( blank field) in the limit field.as follows:

place,SELL,2,STP,,925.50

Tradestation example (2000i and Tradestation 6) :

Orders will be available for placement once every cycle time in Tradestation. For example if you are using 5 minute bars, Tradestation will only create a new line in your order text file once every 5 minutes.

Bracket Trader is designed to handle only one order at a time. If you choose 3rd party managed exit, the external software will manage the trade ie the target and risk of the position. If you prefer you can let Bracket Trader manages the trade : your default target/stop/trailing stop/exit method will be used and apply.

It is designed so far to trade the same number of contracts each trade and the same symbol each trade. One could modify the text file to include differing numbers of contracts to trade.

The print file is comma delimited for easy parsing by Bracket Trader.

Example of an EasyLangage statement :

if condition1 then

print (file("C:\Trading.txt"), "place,BUY,1,STPLMT" + "," + numtostr(buystp +1,25)+"," + numtostr(buystp,2))

else if condition2 then

print (file("C:\Trading.txt"),"cancel,,,,0");

The if else if structure forces Tradestation to have only one condition true at a time so that more than one line is not printed to the text file per cycle. However, one could probably program it to handle any number of command lines from Tradestation. Bracket Trader only considers one line of the text file per Tradestation cycle.

Wealth-Lab 2.1 example :

In Wealth-Lab you will need to do the following in your Wealth-Lab script :

var f:integer;

var s : string;

var price_entry1, price_entry2 : float;

var nbr_contract : integer;

f:=FileOpen(‘C:\Trading.txt’);

FileClear(f); {to start each time with a fresh file}

if condition1 then

begin

nbr_contract :=1;

s :=’cxlplace, BUY,’ + IntToStr (nbr_contract) + ‘,STPLMT,’ +

FloatToStr (price_entry1) + ‘,’ + FloatToStr (price_entry2);

FileWrite (f, s);

end;

else if condition2 then

begin

s:=’ cancel,,,,0’;

FileWrite (f, s);

end;

ESignal 7.1 example :

In order to run this example written in EFS (_Javascript-like) you need to use eSignal 7.1 because of the filesystem / backtesting new features it incorporates.

By default the file will be written in eSignal subfolder : FormulaOutput. If you want to change this go to Tools menu and choose settings and change the formula Output Root to whatever you want (for example C:\). Or you can keep the original eSignal settings and change the path of the filename in your BTDefaults.ini in order to read the file from the default C:\Program Files\eSignal\FormulaOutput.

You can find more examples on central.esignal.com, in the Automated Trading group.

function preMain() {

setPriceStudy(true);

setStudyTitle("MA15 under/over BT Trading System");

setCursorLabelName("MA15", 0);

// var d = new File("BracketTrader"); // You can use those lines to create a directory

// if (!d.exists()) // does directory exist?

// d.mkDir(); // Create this new directory in FormulaOutput Root

}

var study = new MAStudy(15, 0, "Close", MAStudy.SIMPLE); // We display a simple 15 period moving average.

var f = new File("Trading.txt"); // you can change it to whatever you want

function main() {

var v = study.getValue(MAStudy.MA);

if(v == null)

return;

f.open("at+"); // Open and append

if(!f.isOpen()) {

debugPrintln("Could not open!");

}

if(close() >= v) {

if(!Strategy.isLong()) {

Strategy.doLong("Crossing Up", Strategy.MARKET, Strategy.THISBAR);

f.writeln("cxlplace,BUY,1,MKT,,0");

}

} else {

if(!Strategy.isShort()) {

Strategy.doShort("Crossing Down", Strategy.MARKET, Strategy.THISBAR);

f.writeln("cxlplace,SELL,1,MKT,,0");

}

}

if (Strategy.isLong()) {

setBarBgColor(Color.green);

} else if(Strategy.isShort()) {

setBarBgColor(Color.red);

}

f.close();

return v;

}

Ensign example :

As Ensign ESPL is quite difficult, we have included in this documentation a more complete example than for Tradestation or Wealth-Lab using a simple moving average system. For support on ESPL langage, please contact support@ensignsoftware.com

var

i,Handle: integer;

nbr_contract : integer;

order : string;

entryprice : real;

entrystr : string;

stop : real;

begin

nbr_contract :=1; {We will trade 1 contract}

entryprice := 0;

entrystr:='';

if OpenFile('C:\trading.txt',eRewrite) then

{Open a new file named Trading.txt for Bracket Trader 3rd party autotrading}

begin

Chart('ES #F.-360'); {Open a 360 ticks ES continuous contract chart}

Template(eLoad,'TradingSys');

{We will use TradingSys chart template}

Handle := AddStudy(eAve,5,10);

{Add Simple Moving Averages 5 and 10 to the chart}

ResetTrades(2.4,0,1,3);

{Initialize the Trading system, with a commission of 2.4USD for IB}

for i:= BarBegin to BarEnd do

{Loop through the bars}

begin

{start of loop code}

if GetStudy(Handle,4,i)=1 then {4=Get crossing flag, return 1 when MA1 crosses above MA2}

begin

Trade(eBuy+eIf,i); {Generate a buy signal if there is not already a short trade}

entryprice:=Last(i)/100 + 0.25;

{We enter at the Last + 0.25 or better}

{because of ESignal future price format we divide by 100}

entrystr:=FloatToStr(entryprice);

{We convert the price in a string}

order:='cxlplace,BUY,' + IntToStr(nbr_contract) + ',LMT,' + entrystr + ',0';

writelnfile(order);

{the file is written}

end;

if GetStudy(Handle,4,i)=2 then

{4=Get crossing flag, return 2 when MA1 crosses below MA2}

begin

Trade(eSell+eIf,i);

{Generate a sell signal if there is not already a long trade}

entryprice:=Last(i)/100 - 0.25;

{We enter at the Last - 0.25 or better} {because of ESignal future price format we divide by 100}

entrystr:=FloatToStr(entryprice);

order:='cxlplace,BUY,' + IntToStr(nbr_contract) + ',LMT,' + entrystr + ',0';

writelnfile(order); {the file is written}

end;

end; {end of loop code}

Trade(eOut); {Close-out the last open trade}

TradeReport(True); {Print a Trading System Summary}

CloseFile;

end;

end;

Disclaimer :

This software is provided for free. You should be aware of all the problems that can happen when you decide to let your computer trade for yourself (if you want an overview have a look at General comment on 3rd party entry purpose). The author can NOT be considered responsible for any loss that occurred after the use of such a solution.

Special Thanks:

Special thanks to “George Soros” (Matt Briand) for preparing this documentation.