Navigation: Trading Your System >

CSV Order Baskets

 

 

 

The Tomorrow's Orders feature always produces an order list in a human-readable text format for your review.

RealTest makes it possible to additionally produce the list of orders for one or more strategies in machine-readable CSV format, and lets you define the format using a template file. This will, in most cases, be a much simpler way to generate a CSV-format order basket than having to build a Scan or TestScan to do so.

To create a CSV order basket file for a strategy, add the following (or something similar) to your strategy definition:

When the test is run, the usual text file list of tomorrow's orders will be displayed in a new log window. At the same time, CSV order list files are also created for each strategy that includes OrdersFile and OrdersTemplate statements.

By default, the file specified as OrdersFile is created as a new file, overwriting any prior version that may have existed. If you want to concatenate orders from several strategies into the same CSV file, add a plus sign to the start of the file path for the second, third, etc. strategies, e.g.

 

Another consideration when using RealTest to generate a CSV order list is position sizing. Pick a StartDate that is as recent as possible while still allowing enough time to align the backtest with your actual positions. In other words, whatever your longest holding period is, you would need to start the test at least that many days ago. You would then also need to set the AccountSize setting to whatever your actual account value was on that start date. Even then, the position sizes shown in the order list will most likely not exactly match your live trading. It is always advisable to review and edit as needed the generated files before using them to submit orders.

The Examples folder in the RealTest installation directory includes three example CSV basket order template files: ib_basket_template.csv, ib_basket_template_moc.csv, and nick_api_template.csv. The first two can be used to generate CSV order lists that IB Basket Trader can read, and the third will work with the automation "API" that Nick Radge sells as "The Chartist API".

The IB Basket template looks like this:

A CSV order list template file should have two rows. The first row will be used as the first (header) row of the output CSV file. The second row defines the fields to include in each order that is added to the list.

In the above example, all of the lower-case text values are special codes for field contents, and the upper-case values are literal constant strings to include.

Running the mr_sample.rts example script and using this template, the following order list is produced for today (28-Dec-2020):

The test was started in January 2020 with $100K, so the position sizes reflect the theoretical equity growth from this test.

Comparing the template to the output should serve to clarify how this works. Strings in the second row of the template that match the ones in the following table are placeholders for specific elements of each order (action, quantity, price, etc.) All other strings in the second row are simply copied to every output row, as in the above example.

Here is the list of template field placeholder strings:

String

Description

act

order action (BUY or SELL)

sym

stock symbol

type

order type (MKT, LMT, STP, STP LMT)

qty

position size (shares)

lmt

limit price

stp

stop price

oca

OCA group (automatically added if both stop and limit exits are used)

id

order id (use when attaching target/stop exits to entry orders)

parent

parent order id (use when attaching target/stop exits to entry orders)

ref

order reference (set to strategy name if present)

If you require blank columns, simply add them to the header row but leave them blank in the second row of the template.

At this time, only Interactive Brokers action and order type constants (the things shown in parentheses in the above table) are supported.

If the orders template includes the "id" and "parent" fields, and the strategy includes ExitLimit and/or ExitStop elements, then each entry order will have one or two exit orders attached to it, added as separate rows in the basket file. Order IDs are automatically generated sequential numbers which are arbitrary since the IB basket trader replaces them anyhow.

For "day trade" strategies, where ExitRule: 1 and ExitTime: AtClose are the only exit criteria, if "parent" is included in the template, a child MOC exit order is attached to each entry order. The ib_basket_template_moc.csv example template shows how this works.

 

 

 

 

 

Copyright © 2020-2021 Systematic Solutions, LLC