Automation Interactive Brokers Live Trading OrderClerk RealTest

RealTest, OrderClerk and IBKR: How Daily Execution Actually Works

Summary

Interactive Brokers has no way to attach a strategy name to a position, and no way to track two separate positions in the same symbol. OrderClerk fixes that by tagging every order with its strategy and keeping a round-trip trade list that RealTest replays the next day, which is what makes running several systems in one IB account possible. The RealTest side is two settings, and the fragile part is the daily sequence rather than the software.

· 7 min read
RealTest, OrderClerk and IBKR: How Daily Execution Actually Works
Key findings
  • IB provides no way to permanently associate a strategy name with a position, and does not track multiple separate positions in the same symbol, which is the specific gap OrderClerk exists to close.
  • Every order OrderClerk places carries its strategy name as an order reference, preserved in OrderClerkTrades.csv, which RealTest replays to establish real positions per strategy before generating the next day's orders.
  • The RealTest side of the integration is two settings, OrdersMode set to OrderClerk and an OrderClerkFolder path, after which the Orders button generates live order files instead of a backtest.
  • OrderClerkStats mode replays live trades without generating orders, so a live results row and a backtest results row can be compared directly on identical rules.
  • OrderClerkSync mode adds the orders needed to bring live positions back in line with the backtest after a gap in trading.
  • TWS is required rather than IB Gateway, because Gateway cannot retrieve execution reports for prior days, and the TWS Trade History window must be open showing several days of fills before connecting.
  • An order that IB no longer lists as open and for which no execution report arrived is treated as cancelled, so a missed fill report silently deletes an entry from the trade list.
  • Strategies using ThisClose entry or exit times, and strategies placing more limit orders than they can accept fills for, cannot be traded through OrderClerk.
  • Command line automation is supported through -folder, -connect, -placeorders, -confirm and -exit with numeric error codes, but the TWS Trade History window step cannot be automated at all.

Interactive Brokers cannot tell you which strategy a position belongs to. There is no field for it, no way to attach one permanently, and no way for IB to track two separate positions in the same symbol. Your account shows 300 shares of AAPL. It does not show that 100 of them came from a mean reversion system with a two-day exit and 200 from a breakout system with a trailing stop.

That single gap is why OrderClerk exists, and why running several systems in one IB account is harder than it looks.

What OrderClerk is

OrderClerk is a daily order placement and management program for IBKR Pro accounts, written by the author of RealTest. Its own documentation describes it as a slightly smarter substitute for IB Basket Trader, optimised for use with RealTest. It reads order lists in CSV, transmits them to IB through the TWS API, then collects the execution reports and maintains a round-trip trade list.

The trade list is the point. Every order it places carries its strategy name, sent to IB as an order reference and preserved in a file called OrderClerkTrades.csv. RealTest reads that file back the next day, replays it to establish what you actually hold per strategy, and generates tomorrow's orders from real positions rather than from what the backtest assumed you would be holding.

It uses your existing RealTest licence key, so there is no second subscription.

The daily loop

The workflow is a specific order of operations, and the order matters.

  1. Launch TWS with the Trade History window open, showing multiple days of fills.
  2. Launch OrderClerk and connect to TWS, which pulls yesterday's fills into the trade list.
  3. Reconcile any differences OrderClerk reports between its positions and IB's.
  4. Close OrderClerk.
  5. Update your data, typically Norgate.
  6. Run your daily import in RealTest.
  7. Run the strategy script in Orders mode, which replays the trade list and writes a new order list.
  8. Launch OrderClerk again, load the orders, connect, and place them.

Steps two and seven are the ones people underestimate. If the fills from yesterday are not in the trade list before RealTest generates orders, RealTest is reasoning about positions you no longer have.

The RealTest side is two lines

For a script that already backtests, switching it to live order generation takes almost nothing.

OrderSettings:
	OrdersMode:	OrderClerk
	OrderClerkFolder:	C:\OrderClerk\Folder1

Run the script with the Orders button rather than Test and RealTest does something slightly unusual. It runs the backtest in a hybrid mode where the strategy rules are ignored for historical dates and your live trades are played back instead. From the resulting account balance and open positions it generates tomorrow's orders, writing them to the OrderClerk folder as <strategy>_date_orders.csv.

Two settings need attention once. StartDate and AccountSize should be the date you began live trading with OrderClerk and the account balance on that date, and then left alone. Deposits and withdrawals are handled separately through a cash list file rather than by editing the account size.

Two modes worth knowing about

OrderClerkStats replays your live trades without generating any orders. Run it, then run a normal backtest on the same script, and you have two results rows side by side. That is a direct comparison of live trading against the backtest on identical rules, which is the only honest way to find out whether your cost and slippage assumptions were right.

OrderClerkSync handles the case where the backtest shows trades that OrderClerk never made, usually after downtime. It adds the extra orders needed to bring live positions back in line with what the strategy says they should be.

Where it goes wrong

Missing an execution report is unrecoverable

OrderClerk decides an order was cancelled if IB no longer lists it as open and no execution report ever arrived. For an entry, that deletes the row from the trade list. For an exit, it resets the order ID. This is reasonable logic and it means a missed fill report is silently interpreted as a cancellation, so the documentation is blunt about it being critical that OrderClerk never misses one.

TWS rather than IB Gateway

Gateway cannot retrieve execution reports for past days, only the current one. If you use Gateway you have to leave OrderClerk connected all day, every trading day. TWS with the Trade History window open, set to show several days, is the supported arrangement, and OrderClerk checks that the window is open before it will connect.

Reconciliation is your job

OrderClerk cannot rebuild its trade list from IB positions, because IB does not carry the strategy name. At each connection it compares its own position list against IB's and, if anything differs, terminates the connection by default so you have to deal with it. Long-term holdings you do not want it touching go on an ignore list. Everything else you either close in TWS or add to the trade list by hand.

Some strategies cannot be traded this way

Anything using ThisClose as its entry or exit time is out, unless you have intraday snapshot data available to the script. So is any strategy that places more limit orders than it can accept fills for, since that needs software cancelling orders in real time as the position count fills up. The documentation puts the boundary well, which is that RealTest can run any strategy through OrderClerk that you could trade manually by placing orders once a day while the market is closed.

Automation, and its one stubborn limit

OrderClerk accepts command line parameters, including -folder, -connect, -placeorders, -confirm and -exit, and returns numeric error codes for a batch script to check. Example automation scripts ship with it in both Windows Command and PowerShell form, the second including email alerts on failure.

The stubborn part is that the TWS Trade History window has to be open and populated before any of it runs, and the author states plainly that he knows of no way to automate that step. Full unattended operation is possible if TWS stays logged in permanently, with the documentation's own caution attached, which is to watch it closely for at least a week before trusting it.

Who actually needs this

If you run one strategy, you can place orders manually from a text file and nothing here will change your life. The value appears in proportion to how many systems share an account, because that is where the strategy attribution problem becomes unsolvable by hand. Five systems, some holding the same symbols, with different exit rules, cannot be reconciled from an IB position list at all.

The second reason is measurement. Because the trade list carries strategy names and real fill prices, you can compare live results against the backtest per strategy and find out which assumptions held. Most traders never learn this about their own systems, because the record required to answer it does not exist.

Getting it working

Do it in a paper account first, with one strategy, for at least a few weeks. The failure modes here are procedural rather than conceptual, meaning the software works and the daily sequence is what breaks. Paper trading costs nothing to get wrong. If your strategies use intraday stop losses or profit targets, check how RealTest evaluates day-one FillPrice and order timing in our RealTest ExitStop and trailing stop code guide so your live OrderClerk orders match the backtest.

The setup steps that cause most first-run problems are all in TWS rather than in RealTest. Socket clients have to be enabled in the API settings, the port has to match what OrderClerk expects, the operator timezone has to be right or execution times convert incorrectly, and the Trade History window has to be open with several days showing.

If you would rather be walked through it than work it out from the documentation, our course on connecting RealTest, OrderClerk and IBKR covers the configuration and the daily process end to end, including the parts the documentation leaves implicit.

Key terms

OrderClerk
A daily order placement and management program for IBKR Pro accounts, built to work with RealTest and described by its documentation as a smarter substitute for IB Basket Trader.
OrderClerkTrades.csv
The round-trip trade list holding every entry and exit with its strategy name and actual fill price. RealTest replays it to determine live positions before generating orders.
TWS API
The socket interface exposed by Interactive Brokers Trader Workstation, which OrderClerk uses to transmit orders and receive execution reports.
Orders Mode
A RealTest run mode that replays the live trade list instead of applying strategy rules to history, then generates the next session's orders from the resulting positions and balance.
OrderClerkStats Mode
A run mode that replays the live trade list without producing orders, so live results can be compared with a backtest of the same script.
OrderClerkSync Mode
A run mode that adds the extra orders required to bring live positions back into line with what the backtest says they should be after a gap.
Strategy Attribution
Knowing which strategy a given holding belongs to. Absent from broker position data, and the reason a separate trade list has to be maintained.
Reconciliation
Comparing the locally maintained position list against the broker's at each connection, and resolving any differences before trading continues.

Frequently asked questions

What is OrderClerk?

OrderClerk is a daily order placement and management program for Interactive Brokers Pro accounts, written by the author of RealTest. It reads order lists in CSV, sends them to IB through the TWS API, collects execution reports, and maintains a round-trip trade list that records which strategy each trade belongs to.

Why do you need OrderClerk instead of placing orders yourself?

Because Interactive Brokers cannot record which strategy a position came from, and cannot hold two separate positions in the same symbol. With one strategy that does not matter. With several systems sharing an account, there is no way to work out from an IB position list which shares belong to which exit rule.

How does RealTest connect to OrderClerk?

Through two settings in an OrderSettings or Settings section, OrdersMode set to OrderClerk and an OrderClerkFolder path. Running the script in Orders mode then replays your live trade list, works out real positions and balance, and writes the next session's orders into that folder.

Does OrderClerk cost extra on top of RealTest?

No separate licence is required. OrderClerk uses your existing RealTest licence key, which is why the installation includes a copy of the same licence management files.

Should you use TWS or IB Gateway with OrderClerk?

TWS. Gateway can only return execution reports for the current day, so using it means leaving OrderClerk connected all day every trading day. TWS also provides the Trade History window that OrderClerk depends on, and it checks that window is open before allowing a connection.

What is the daily workflow with RealTest and OrderClerk?

Open TWS with Trade History showing several days, connect OrderClerk to pull yesterday's fills, reconcile any position differences, close it, update your data, run the RealTest import, run the script in Orders mode, then reopen OrderClerk to load and place the new orders.

What happens if OrderClerk misses an execution report?

It concludes the order was cancelled. If IB no longer lists an order as open and no fill report ever arrived, an entry row is deleted from the trade list and an exit order ID is reset. That is why the documentation is emphatic that OrderClerk must never miss an execution report.

Can OrderClerk rebuild its trade list from IB positions?

No, and it is not a limitation of the software. IB does not carry the strategy name on a position, so the information needed to rebuild the list does not exist in the account. OrderClerk instead reconciles its list against IB at each connection and reports differences for you to resolve.

How do you compare live trading results against the backtest?

Run the script with OrdersMode set to OrderClerkStats, which replays the live trade list without generating orders, then run a normal backtest on the same script. That produces two results rows on identical rules, which is where cost and slippage assumptions are confirmed or disproved.

Which strategies will not work with OrderClerk?

Strategies using ThisClose as entry or exit time, unless intraday snapshot data is available to the script, and strategies that place more limit orders than they can accept fills for, since those require orders to be cancelled in real time. The working rule is that anything you could trade manually once a day while the market is closed will work.

Can the whole process be automated?

Almost. OrderClerk supports command line operation with error codes, and ships with example batch and PowerShell scripts covering data update, import, order generation and placement. The exception is the TWS Trade History window, which the author states he knows of no way to automate.

How do you handle deposits and withdrawals?

Not by editing the account size. StartDate and AccountSize are set once to the date you began live trading and the balance on that date, and cash movements are handled through a separate cash list file referenced by a dedicated strategy in the script.

Related strategies

Course: How to Connect RealTest, OrderClerk, and IBKR
The configuration and the daily process walked through end to end, including the steps the official documentation leaves implicit.
View →
RealTest Mean Reversion Trading Strategy
A system of the kind this setup exists to run, with rules that generate orders once a day while the market is closed.
View →
Free RealTest Strategy
A complete script to point at a paper account first, which is where the daily sequence should be learned.
View →
← Back to Learn

#1 RealTest Backtests

Supercharge Your Trading Now

Reduce drawdown, build diversification, or speed up your development time.

Browse RealTest Strategies