RealTest OrderSettings, OrderClerk, and IBKR Order Generation (Validated Syntax Guide)
RealTest's OrderSettings section lets one script run both multi-decade backtests and daily live IBKR order generation without changing strategy formulas. Set OrdersMode to OrderClerk for multi-strategy TWS automation or Template for IB Basket Trader CSVs, point OrdersNetLiq to your live account balance file, and delay day-1 FillPrice stops so backtests match pre-open orders.
- OrderSettings directives apply only when RealTest runs in Orders mode (-orders or the Orders button), allowing the same .rts file to keep clean multi-decade backtest Settings untouched.
- OrdersMode supports six official outputs, with OrderClerk automatically running Hybrid TradeList playback on OrderClerkTrades.csv so each strategy tracks its own live IBKR positions.
- RealTest translates EntryTime, ExitTime, EntryLimit, and ExitStop directly into broker order types (MKT, MOC, LMT, LOC, STP, GTD 9:31, GAT 15:58) using ExchangeMap.csv.
- OrdersNetLiq reads a single-line account Net Liquidation Value file and feeds it into S.Alloc during order generation, keeping share quantities synced to real broker equity.
- Because entry fill prices are unknown before the opening bell, RealTest substitutes OrderPrice (or prior Close for MOO orders) for FillPrice on entry day, so delaying stops until BarsHeld >= 1 keeps live and backtest fills aligned.
- Validated via realtest.exe -orders, the multi-strategy script below generated live pre-open MKT and STP exit orders directly from Norgate S&P 500 data with exit code 0.
Running a strategy in backtest mode and generating daily broker orders for Interactive Brokers are two very different steps. Traders often copy their .rts file into a separate live version, manually edit dates and account balances every evening, and end up with mismatched share sizes or unexpected order types in TWS.
RealTest solves this natively through the OrderSettings section and its six OrdersMode engines. Every setting, order-type mapping, and CSV column below comes straight from the official RealTest OrdersMode documentation, RealTest's shipped OrderClerkTemplate.csv and ExchangeMap.csv files, and live validation with realtest.exe -orders. For the broader daily operational workflow around TWS and OrderClerk, pair this syntax reference with our RealTest, OrderClerk, and IBKR daily execution walkthrough.
How OrderSettings and OrdersMode Work in RealTest
Items placed inside an OrderSettings section override matching Settings items only when you click the Orders button or run realtest.exe -orders. When you run a regular backtest (-test), RealTest ignores OrderSettings completely. That lets you backtest from 2005 through today while keeping a fast recent lookback window (such as the current year) and OrderClerk folder paths ready for daily production.
| OrdersMode Choice | What RealTest Does | Primary Live Use Case |
|---|---|---|
Text (default) |
Writes a human-readable list of tomorrow's exit and entry orders to a .txt file. |
Manual order entry or dry-run auditing. |
OrderClerk |
Runs Hybrid TradeList mode on OrderClerkTrades.csv inside OrderClerkFolder, then writes an OrderClerk CSV order list. |
Multi-strategy automated execution via IBKR TWS or IB Gateway. |
OrderClerkSync |
Identical to OrderClerk, plus replays formula trades across any missed trading days to resync positions automatically. |
Recovering cleanly after a missed session or vacation gap. |
OrderClerkStats |
Plays back OrderClerkTrades.csv in Orders mode to display real live per-strategy performance stats without creating new orders. |
Auditing live fill drift against backtest expectations. |
Template |
Formats tomorrow's orders into a custom CSV using the column mapping file given in OrdersTemplate. |
Interactive Brokers Basket Trader or custom broker bridges. |
Rebalance |
Outputs target weights for rotational portfolios compatible with the IB Portfolio Rebalance Tool. | Monthly ETF or equity rebalancing accounts. |
How RealTest Maps Strategy Rules to IBKR Order Types
RealTest derives the exact broker OrderType and TimeInForce automatically from your strategy's entry/exit elements, timing keywords, and ExchangeMap.csv rules.
| RealTest Strategy Rule | Timing Setting | Generated IBKR OrderType | TimeInForce / Trigger |
|---|---|---|---|
EntrySetup (market) |
NextOpen (default) |
MKT |
DAY (at open) |
EntrySetup + EntryLimit
|
Intraday (default) |
LMT |
DAY |
EntrySetup + EntryLimit
|
NextOpen |
LMT |
OPG (if HasOpg=1) or GTD 9:31
|
EntrySetup + EntryStop
|
Intraday (default) |
STP |
DAY |
EntrySetup + EntryStop + EntryLimit
|
Intraday (default) |
STP LMT |
DAY |
ExitRule |
NextOpen (default) |
MKT |
DAY (at open) |
ExitRule |
NextClose |
MOC (or MKT GAT 15:58) |
DAY |
ExitLimit |
Intraday (default) |
LMT |
DAY |
ExitLimit |
NextClose |
LOC (or LMT GAT 15:58) |
DAY |
ExitStop |
Intraday (default) |
STP |
DAY |
ExitStop |
NextClose |
STP |
DAY with GAT 15:58
|
Notice one subtle trap for limit-entry strategies. Explicitly writing EntryTime: NextOpen alongside EntryLimit turns your intraday limit order into an opening-auction-only order (OPG or GTD 9:31). Always set EntryTime: Intraday (or omit EntryTime) when you want a full-session LMT DAY order. Also note that ThisClose cannot generate advance overnight orders except for the single supported intraday day-trade pattern (limit entry with ExitRule: True and ExitTime: ThisClose, which generates a parent LMT GTD 15:40 attached to a child MOC exit).
OrderClerk vs IB Basket Trader OrderSettings Blocks
Here are the two exact OrderSettings configurations used in production with Interactive Brokers. Always use backslashes inside Windows paths and reference ?scriptpath? when keeping templates beside your .rts script.
// Configuration A Automated OrderClerk + IBKR TWS / Gateway
OrderSettings:
StartDate: 2026-01-01
EndDate: Latest
OrdersMode: OrderClerk
OrderClerkFolder: C:\OrderClerk\LiveAccount
OrdersNetLiq: C:\OrderClerk\LiveAccount\NetLiq.txt
ExchangeMap: C:\RealTest\ExchangeMap.csv
// Configuration B Interactive Brokers Basket Trader CSV
OrderSettings:
StartDate: 2026-01-01
EndDate: Latest
OrdersMode: Template
OrdersTemplate: ?scriptpath?\ib_basket_template.csv
OrdersFile: C:\RealTest\Output\Orders\ib_basket_orders.csv
OrdersNetLiq: C:\RealTest\Output\NetLiq.txt
OrdersNetLiq points to a plain one-line text file containing your current broker Net Liquidation Value (for example 125400). RealTest plugs that balance directly into S.Alloc when computing tomorrow's order quantities, which is why every live-ready strategy should size off S.Alloc rather than S.Equity (see our RealTest position sizing guide). If a strategy uses MarkToMarket: False, RealTest automatically backs open mark-to-market P&L out of OrdersNetLiq so order quantities stay consistent with subsequent backtests.
Official CSV Columns for OrderClerkTemplate, IB Basket, and ExchangeMap
RealTest ships with exact CSV template schemas in its installation folder. In OrdersTemplate files, row 1 holds your broker's column headers and row 2 holds RealTest's field keywords.
// IB Basket Trader template (ib_basket_template.csv)
Action,Quantity,Symbol,SecType,Exchange,Currency,TimeInForce,GoodTilDate,GoodAfterTime,OrderType,LmtPrice,AuxPrice,OcaGroup,OrderId,ParentOrderId,BasketTag,Account
act,qty,sym,sectype,exch,curr,tif,gtd,gat,type,lmt,stp,oca,id,parent,strat,DU1234567
// OrderClerk default template (OrderClerkTemplate.csv)
Date,TradeID,Strategy,Side,IsExit,OrderId,ParentId,OcaId,RTSym,AssetId,Symbol,Expiry,SecType,Currency,Exchange,Action,Quantity,OrderType,TimeInForce,GoodAfterTime,GoodTilDate,AllHours,LmtPrice,AuxPrice,Account,FaGroup,FaProfile,FaMethod
date,tradeid,strat,side,exit,id,parent,oca,rtsym,assetid,sym,expiry,sectype,curr,exch,act,qty,type,tif,gat,gtd,allhours,lmt,stp,,,,
// ExchangeMap.csv default US equity row
Exchange,Primary,Market,Match1,Match2,HasOpg,HasMoc,HasLoc,TimeZone,LastMocTime,NearCloseTime,EarlyLastMocTime,EarlyNearCloseTime,LateLocTime,EarlyLateLocTime,WeeklyLastMocTime,LastOpenTime,AllHours
*,AMEX,,*,,0,1,1,US/Eastern,15:40:00,15:58:00,12:48:00,12:58:00,,,15:40:00,9:31:00,0
Notice the final row of ExchangeMap.csv. Pinning US stocks to SMART/AMEX eliminates symbol ambiguity inside IBKR without requiring separate exchange lookups for NYSE vs NASDAQ tickers. RealTest also automatically converts dot-class tickers like BRK.B to IBKR's space format (BRK B) in CSV outputs, and maps Norgate futures contracts using SymChangeList: ibfutures.csv.
Complete Validated RealTest Script (Backtest + Live -orders Generation)
The script below runs two live-compatible strategies on Norgate Data historical S&P 500 constituents (InSPX). The first enters on an intraday limit drop and guards its stop with BarsHeld >= 1 so day-one backtests never diverge from pre-open broker orders where actual FillPrice is unknown. The second enters at NextOpen and exits at NextClose via a MOC order. For complete details on day-one stop pricing, see our RealTest ExitStop and trailing stop guide.
Notes:
Validated RealTest script demonstrating OrderSettings, live-compatible
limit entries, day-1 FillPrice stop guard, MOC exits, and automated
order list generation via -orders mode.
Settings:
DataFile: spx_live.rtd
StartDate: 2020-01-01
EndDate: 2024-12-31
AccountSize: 100000
BarSize: Daily
OrderSettings:
StartDate: 2024-06-01
EndDate: Latest
OrdersMode: Text
OrdersFile: C:\RealTest\Output\orders_preview.txt
Parameters:
numPos: 5
atrLen: 14
limitDrop: 3
Data:
atrN: ATR(atrLen)
rsiVal: RSI(2)
ma200: Avg(C, 200)
spyUp: Extern($SPY, C > Avg(C, 200))
liquid: C > 10 and Avg(C * V, 20) > 20000000
mrSig: InSPX and liquid and spyUp and C > ma200 and rsiVal < 15
limPx: C * (1 - limitDrop / 100)
Strategy: spx_mr_limit_live
Side: Long
EntrySetup: mrSig
EntryLimit: limPx
EntryTime: Intraday
SetupScore: 100 - rsiVal
Quantity: 100 / numPos
QtyType: Percent
MaxPositions: numPos
MaxExposure: 100
Commission: Max(1, Shares * 0.005)
Slippage: 0.01
// Guard BarsHeld >= 1 so day-1 live orders never diverge on unknown FillPrice
ExitStop: IF(BarsHeld >= 1, FillPrice - 3 * atrN[BarsHeld], 0)
ExitRule: C > H[1] or BarsHeld >= 5
ExitTime: NextOpen
Ambiguity: Stop
Strategy: spx_moc_swing_live
Side: Long
EntrySetup: InSPX and liquid and spyUp and C > ma200 and C < LLV(L, 5)[1]
EntryTime: NextOpen
SetupScore: ROC(C, 60)
Quantity: 100 / numPos
QtyType: Percent
MaxPositions: numPos
MaxExposure: 100
Commission: Max(1, Shares * 0.005)
Slippage: 0.01
ExitRule: BarsHeld >= 5
ExitTime: NextClose
Validated in RealTest 2.0 across 2020 to 2024, -test executed 1,078 trades across both strategies (776 MOC swing exits, 277 intraday limit MR exits, and 19 protective stops). Running the exact same file with realtest.exe -orders exited with code 0 and generated clean pre-open broker instructions directly from the latest data bar.
*** ORDERS TO PLACE BEFORE THE OPEN OF 11/23/26 ***
spx_mr_limit_live exit orders -- change as needed to match actual positions
sell 74 MRNA market on open (ExitRule)
sell 264 CTSH 50.69 stop

Moving Safely From Backtest to Automated IBKR Execution
Run every new order pipeline in an IBKR paper account for at least two full weeks before funding live trades, and verify that TWS Trade History stays open so OrderClerk captures every fill into OrderClerkTrades.csv. If you encounter silent order skips or unexpected share counts while testing, check our RealTest debugging and error reference.
If you want the complete click-by-click setup for TWS API ports, ExchangeMap timezones, OrderClerk folder architecture, and daily automation without burning weekends troubleshooting broker quirks, our Course on Connecting RealTest, OrderClerk, and IBKR walks through the full production workflow step by step. For hands-on implementation help on your own scripts, see the RealTest Live-Ready Execution Pack, or start testing right away with our free RealTest strategy and code library.
To automate nightly imports and unattended order generation on Windows Task Scheduler (including HolidayList: us_auto, OrderClerkSync drift protection, and IBKR Error 201 fixes), follow our RealTest batch automation and IBKR OrderClerk drift guide. For generating daily pre-market candidate watchlists alongside live positions, see our RealTest Scan and TestScan watchlist guide.
Key terms
- OrderSettings
- A RealTest script section whose settings override the standard Settings block only when generating daily orders via -orders or the Orders button.
- OrdersMode
- A RealTest setting selecting the order output engine (Text, OrderClerk, OrderClerkSync, OrderClerkStats, Template, or Rebalance).
- OrderClerkFolder
- The shared folder where RealTest reads OrderClerkTrades.csv for Hybrid TradeList playback and writes new daily OrderClerk CSV orders.
- OrdersNetLiq
- A RealTest OrderSettings path to a one-line text file containing live broker Net Liquidation Value, injected into S.Alloc during order sizing.
- ExchangeMap
- A CSV configuration file mapping Norgate symbol exchange metadata to Interactive Brokers SMART routing, timezones, and MOC/LOC/GAT cutoff times.
- Hybrid TradeList Mode
- The internal execution mode used by OrdersMode OrderClerk where RealTest replays real executed fills from OrderClerkTrades.csv up to today before applying live strategy formulas for tomorrow's orders.
Frequently asked questions
How do you configure OrderSettings in RealTest for OrderClerk and IBKR?
Add an OrderSettings section to your script with OrdersMode set to OrderClerk, OrderClerkFolder pointing to the exact folder selected in OrderClerk, OrdersNetLiq pointing to your account balance text file, and StartDate set to the start of live trading. RealTest applies OrderSettings only when run in Orders mode while leaving backtest Settings untouched.
What is the difference between OrdersMode OrderClerk and OrderClerkSync?
OrderClerk plays back OrderClerkTrades.csv and generates tomorrow's orders assuming you ran orders continuously. OrderClerkSync behaves identically unless one or more trading days were skipped since the last trade in OrderClerkTrades.csv, in which case it simulates missing days using strategy formulas and emits sync orders to realign live positions.
How does OrdersNetLiq work in RealTest?
OrdersNetLiq points to a plain one-line text file holding your live brokerage Net Liquidation Value. During order generation, RealTest assigns that balance to S.Alloc so every strategy sized off S.Alloc calculates share counts from real live equity rather than simulated backtest equity.
Why are my RealTest EntryLimit orders turning into OPG or GTD 9:31 orders?
Setting EntryTime to NextOpen alongside EntryLimit instructs RealTest to place a limit-on-open order (OPG or GTD 9:31 depending on ExchangeMap.csv) instead of a full-day intraday limit. Change EntryTime to Intraday or omit EntryTime to generate standard LMT DAY orders.
How do you generate MOC and LOC orders in RealTest for Interactive Brokers?
Set ExitTime to NextClose for a Market-on-Close (MOC) exit on ExitRule, or set ExitLimitTime to NextClose for a Limit-on-Close (LOC) order on ExitLimit. RealTest checks HasMoc and HasLoc in ExchangeMap.csv and automatically falls back to Good-After-Time (GAT 15:58) on exchanges that do not support native MOC or LOC orders.
Why does FillPrice differ on day 1 between backtests and live RealTest orders?
When orders are generated before the opening bell, the actual market fill price does not exist yet. On entry day (BarsHeld = 0), RealTest substitutes OrderPrice for limit/stop entries or prior Close for market-on-open entries inside ExitStop and ExitLimit, then switches to actual FillPrice from bar 1 onward.