Navigation: Trading Your System >

CSV Order Baskets





The Tomorrow's Orders feature produces an order list in a human-readable text format by default.

RealTest can optionally generate a machine-readable CSV order basket file as well (or instead), and lets you define the format using a template file.

This will, in most cases, be an easier and better way to generate a CSV-format order basket vs. building it using a Scan or TestScan

To create a CSV order basket file, add the following (or something similar) to your Settings (note that there is not a way to do this using the Settings Panel):

When the test is run, the default text file list of tomorrow's orders will still be displayed, unless you changed that option.

The specified CSV file will also be created and formatted using the specified template file.

The default CSV output file will be {RealTest folder}/Output/Orders/{test_name}_{date}_orders.csv, where your actual test name and the current date are used.

You can override this default by adding OrdersFile to your settings and/or to specific strategies if desired.

When not using OrderClerk, an important consideration when using RealTest to generate a transmittable 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 two example CSV basket order template files: ib_basket_template.csv and chartist_api_template.csv.

The first can be used to generate CSV order lists that IB Basket Trader can read, and the other will work with the automation "API" that Nick Radge sells as "The Chartist API".

In many cases, using OrderClerk will be a simpler and better alternative to either of the above.

Note that with OrderClerk it is not necessary to specify an OrdersTemplate path. RealTest includes a standard OrderClerkTemplate.csv file in its installation folder and will use that file automatically when generating orders for OrderClerk.

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 (see below), and the upper-case values are literal constant strings to include.

Running the mr_sample.rts example script from the start of 2022 through Feb-14, the following order list is produced for the next day:

This same set of orders in the generated CSV order basket:

Notice how the entry limit orders are each given a unique order ID which the child target orders then use to identify their parents. IB Basket Trader translates these basket-specific ID numbers to unique internal values -- all that it requires is that they be unique and express the correct relationships within the basket file.

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:




order date


order action (BUY or SELL)


stock or contract symbol reformatted for IB


expiration date of a contract


account number


original symbol as shown in RealTest


stock or contract currency


stock or contract domicile (country)


stock economic sector


stock industry


exchange to route orders to (can be e.g. SMART/NYSE)


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


position size (shares)


position size (shares) for entry, 0 for exit


position size in dollars


position size as an account fraction


limit price


stop price


time-in-force (DAY, GTD, OPG)


good-after-time time (e.g. 15:58:00 EST)


good-until-date time (e.g. 15:45:00 EST)


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


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


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


listing exchange of stock or contract


security type of stock or contract


strategy name (typically for the order reference field)


side of new or existing position: will be 1 for long, -1 for short


MaxEntries value (for The Chartist API "Max Fill" column)


whether order is for an exit (1) vs. an entry (0)


OrderNote value (could be used as Account, FAGroup, etc.)


OrderExtraN value, where N is a number from 1 to 3


suppresses the comma in the CSV output of this column


required for OrderClerk, not needed otherwise

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







Copyright © 2020-2024 Systematic Solutions, LLC