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 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.txt, where your actual test name and the current date are used.

You can override this default by adding OrdersFile to your settings 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.

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, LMT, 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, GAT, GTD, LOC, MOC)


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)

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


Support for International Exchanges, Order Types, and Time Zone Names

RealTest uses an ExchangeMap to determine how to correctly map available symbol metadata to correct brokerage orders.

See the above link for full details about the contents and usage of this map file.

The information it contains is used with the OrdersTemplate (also with OrderClerk) to ensure that:

symbols are correctly translated from Norgate to IB format

the correct SMART/xxx exchange definition is used in each order

MOC orders are generated where supported, otherwise GAT <time> is used

parent LMT entry orders for MOC exit strategies are placed with GTD <time> as appropriate

NextClose orders are placed as GAT <time> correctly for each exchange (to become "NearClose" orders)

Note that IB does not require the xxx in SMART/xxx to be the exchange on which a stock is listed. It only needs to pin it to the correct stock market, so that the symbol will not be ambiguous. For example, "SMART/AMEX" works fine for all US stocks even though most of them are not listed on AMEX.

Norgate to IB Futures Symbol Mapping

RealTest includes a file called ibfutures.csv. This file maps Norgate futures symbols to the corresponding IB symbols when there are differences.

The default contents are:

If you find others, feel free to add them.

Note that for any Norgate futures contract symbol, RealTest will automatically change the name to the correct IB format when creating a CSV order basket. For example, ES-2022M would become ESM2, and (also using mapping) 6E-2022M would become EURM2.






Copyright © 2020-2022 Systematic Solutions, LLC