Automated RealTest, OrderClerk, and IBKR Batch Trading (HolidayList and Drift Fix)
To automate RealTest with OrderClerk and Interactive Brokers unattended, chain realtest.exe -import and -orders inside a Windows Task Scheduler script checking exit codes (0 success, 5 syntax, 6 import, 7 data), add HolidayList us_auto inside OrderSettings so post-holiday orders date accurately, use OrderClerkSync to recover missed sessions, and audit live vs backtest drift via OrderClerkStats and day-1 FillPrice stop guards.
- Setting HolidayList to us_auto inside OrderSettings eliminates manual holiday calendar editing for US equities, ensuring RealTest dates tomorrow's orders accurately across Thanksgiving, Memorial Day, and market closures.
- Chaining realtest.exe -import followed by realtest.exe -orders inside a PowerShell or batch script with exit-code checks prevents OrderClerk from ever submitting orders built on stale or failed Norgate imports.
- Switching OrdersMode from OrderClerk to OrderClerkSync automatically simulates any missed trading days since the last record in OrderClerkTrades.csv and generates catch-up synchronization orders cleanly.
- The four main causes of live IBKR fills drifting from RealTest backtests are day-1 FillPrice substitution before market open, missing LimitExtra on tight limit entries, stale OrdersNetLiq balances, and mismatched IBKR TWS order routing.
- IBKR Error 201 rejections (limited liquidity or Peg-Best restrictions) typically resolve by pinning US stock routing cleanly inside ExchangeMap.csv (SMART/AMEX) and keeping liquidity floors above $20M average daily dollar volume.
- Validated in RealTest 2.0 via both -test (655 ETF trades, -8.72 percent max drawdown, 64.73 percent win rate) and -orders (exit code 0), the script below generated clean pre-open stop and limit instructions automatically.
Building a profitable RealTest backtest is only half the job. Across 58 dedicated threads on the RealTest user forum, the biggest operational bottleneck comes right after traders go live with Interactive Brokers and OrderClerk. Orders skip the morning after a US market holiday, a Windows batch file silently fails after a Norgate Updater restart, IBKR rejects a low-liquidity ticker with Error 201, or live fills drift away from what the backtest reported.
Every automation switch, exit code, and holiday rule below follows the official RealTest HolidayList and command-line documentation and was verified directly in RealTest 2.0 across both -test and -orders runs. For core OrderSettings CSV templates and IBKR order-type mappings, pair this walkthrough with our RealTest OrderSettings and OrderClerk syntax reference.
Fixing Post-Holiday Order Failures With HolidayList us_auto
During a historical backtest, RealTest never needs a holiday calendar because market holidays simply have no bars in your .rtd file. During daily live order generation (-orders), however, RealTest must compute the next valid trading date from today's last bar. Without a holiday list, Friday's run before a Monday holiday stamps orders for Monday instead of Tuesday, causing OrderClerk to ignore or misdate the file.
Instead of manually editing text files every January, RealTest 2.0 supports HolidayList: us_auto directly inside OrderSettings for US equities and ETFs (or a custom file path like ?scriptpath?\holidays.asx.txt for international exchanges).
Unattended Windows Task Scheduler Batch Script (-import to -orders)
Never run -orders blindly on a fixed clock without verifying that your Norgate Data import succeeded first. Because realtest.exe is a Windows GUI binary that writes diagnostics to C:\RealTest\batchlog.txt rather than console stderr, always run via Start-Process -Wait -PassThru and halt immediately on any non-zero exit code (0 success, 5 parse error, 6 import failure, 7 data issue).
# Unattended daily pipeline for Windows Task Scheduler (run after NDU evening update)
$rt = 'C:\RealTest\realtest.exe'
$script = 'C:\RealTest\Scripts\live_portfolio.rts'
$log = 'C:\RealTest\batchlog.txt'
# Step 1 Refresh .rtd file from Norgate Data Updater
$p1 = Start-Process $rt -ArgumentList '-import', "`"$script`"" -Wait -PassThru
if ($p1.ExitCode -ne 0) {
Write-Error "RealTest import failed with exit code $($p1.ExitCode). Inspect $log"
exit $p1.ExitCode
}
# Step 2 Generate tomorrow's OrderClerk / IBKR orders only if import succeeded
$p2 = Start-Process $rt -ArgumentList '-orders', "`"$script`"" -Wait -PassThru
if ($p2.ExitCode -ne 0) {
Write-Error "RealTest orders failed with exit code $($p2.ExitCode). Inspect $log"
exit $p2.ExitCode
}
If your machine or VPS missed a trading day due to a Windows reboot or broker outage, switch OrdersMode temporarily from OrderClerk to OrderClerkSync. RealTest replays missing dates against your strategy formulas and emits clean reconciliation orders automatically. To audit how real fills in OrderClerkTrades.csv compare against simulated strategy equity over time, switch to OrdersMode: OrderClerkStats.
Why Live IBKR Fills Drift From Backtests (5 Diagnostic Fixes)
When live brokerage statements diverge from your RealTest equity curve, check these five exact root causes before blaming slippage.
| Live vs Backtest Symptom | Root Cause in RealTest / IBKR | Validated Fix |
|---|---|---|
| Orders skipped after US market holiday | Missing HolidayList in OrderSettings
|
Add HolidayList: us_auto inside OrderSettings
|
| Day-1 stop prices mismatch pre-open orders |
FillPrice on entry day substitutes OrderPrice before actual open fill is known |
Guard stops with IF(BarsHeld >= 1, ..., 0) or anchor day-1 stop to EntryLimit
|
| Backtest fills far more limit orders than TWS | Daily OHLC bars count exact session-low touches without queue depth | Add LimitExtra: 0.001 * C and OpenSlip: 0.0005 * FillPrice
|
| Live share sizes diverge from backtest |
Quantity references S.Equity or OrdersNetLiq file is stale |
Size off S.Alloc and refresh OrdersNetLiq daily via TWS/OrderClerk |
| IBKR Error 201 (limited liquidity / NON Peg-Best) | Thin ticker or ambiguous exchange routing in TWS | Keep liquidity above $20M ADV and pin SMART/AMEX in ExchangeMap.csv
|
For deeper execution realism checks on LimitExtra and OpenSlip, review our RealTest EntryLimit and slippage guide, and check our RealTest debugging guide for tracing batchlog.txt exit codes.
Complete Validated RealTest Automation Script (Backtest + -orders)
Below is a clean, runnable script combining multi-decade backtesting with isolated OrderSettings (HolidayList: us_auto), realistic limit fill-through costs, and a day-1 BarsHeld >= 1 protective stop guard so pre-open orders match backtest assumptions cleanly. For production IBKR TWS execution, simply swap OrdersMode: Text to OrdersMode: OrderClerk alongside OrderClerkFolder and OrdersNetLiq.
Notes:
Production-ready automated IBKR and OrderClerk script demonstrating
HolidayList us_auto, OrderSettings isolation, day-1 FillPrice stop guard,
and clean unattended -import and -orders batch execution.
Settings:
DataFile: C:\RealTest\Data\MainETF.rtd
StartDate: 2010-01-01
EndDate: 2024-12-31
AccountSize: 100000
BarSize: Daily
OrderSettings:
StartDate: 2024-06-01
EndDate: Latest
HolidayList: us_auto
OrdersMode: Text
OrdersFile: C:\RealTest\Orders\ibkr_auto_orders.txt
Parameters:
numPos: 4
atrLen: 14
Data:
isUniv: Symbol = $SPY or Symbol = $VEU or Symbol = $GLD or Symbol = $TLT or Symbol = $VNQ or Symbol = $XLE or Symbol = $XLP or Symbol = $IYH
atrN: ATR(atrLen)
rsi2: RSI(2)
ma200: Avg(C, 200)
entrySig: isUniv and C > ma200 and rsi2 < 15
Strategy: etf_live_automated
Side: Long
EntrySetup: entrySig
EntryLimit: C - 0.35 * atrN
EntryTime: Intraday
SetupScore: 100 - rsi2
Quantity: 100 / numPos
QtyType: Percent
MaxPositions: numPos
MaxExposure: 100
Commission: Max(1, Shares * 0.005)
LimitSlip: 0
LimitExtra: 0.001 * C
OpenSlip: 0.0005 * FillPrice
StopSlip: 0.001 * FillPrice
// Guard BarsHeld >= 1 so pre-open orders match backtest without day-1 FillPrice drift
ExitStop: IF(BarsHeld >= 1, FillPrice - 3 * atrN[BarsHeld], 0)
ExitRule: C > H[1] or BarsHeld >= 7
ExitTime: NextOpen
Ambiguity: Stop
Charts:
MA200: ma200
Validated in RealTest 2.0 from January 2010 through December 2024, -test completed 655 trades (584 exit rule, 70 exit stop, and 1 end-of-test closure across 390 intraday limit fills and 265 gap-open fills) with a 64.73 percent win rate, 1.18 profit factor, and -8.72 percent max drawdown ($123,069 ending equity). Running the exact same file via realtest.exe -orders exited cleanly with code 0 and generated formatted pre-open instructions (sell 382 IYH 72.63 stop and buy 480 XLE 59.97 limit) dated automatically around US market holidays.

Going From Manual Clicks to Full IBKR Automation
Once your strategy runs cleanly in paper trading for two full weeks with zero drift against OrderClerkStats, shifting to automated daily scheduling frees you from watching the opening bell. For the complete click-by-click setup covering IB Gateway / TWS API ports, Windows Task Scheduler triggers, ExchangeMap.csv configuration, OrderClerk multi-strategy folder architecture, and recovery checklists, see our Course on Connecting RealTest, OrderClerk, and IBKR. If you want our team to wire your existing RealTest scripts directly into automated IBKR execution, explore the RealTest Live-Ready Execution Pack, or start testing clean templates from our free RealTest strategy and code library and daily OrderClerk operations guide.
Need hardware and cloud VPS sizing specs (including RealTest's 64-byte per-bar RAM math, zero-RAM Library tricks, and Mac Parallels tips) for 24/7 automated trading? Read our RealTest Mac, Parallels, VPS, and speed optimization guide.
Key terms
- HolidayList us_auto
- A built-in RealTest 2.0 OrderSettings value that automatically tracks US stock market holidays so -orders stamps the correct next trading session date.
- OrderClerkSync
- A RealTest OrdersMode setting that replays formula trades across missed trading days to resynchronize OrderClerkTrades.csv with strategy holdings.
- OrderClerkStats
- A RealTest OrdersMode audit view that plays back real filled trades from OrderClerkTrades.csv to compare live performance against backtest expectations.
- batchlog.txt
- RealTest's diagnostic log file in the installation directory where headless -import, -test, -scan, and -orders runs record exact errors and timestamps.
- ExchangeMap.csv
- RealTest's exchange routing table mapping stock symbols and markets to Interactive Brokers Exchange, Primary Exchange, MOC/OPG cutoffs, and time zones.
Frequently asked questions
How do you fix RealTest generating orders on US market holidays?
Add HolidayList set to us_auto inside your OrderSettings section. RealTest 2.0 automatically calculates US equity market holidays and advances tomorrow's order date cleanly to the next valid session without maintaining manual text files.
How do you automate RealTest import and order generation with Windows Task Scheduler?
Run a PowerShell script via Task Scheduler after your Norgate Data evening update that executes realtest.exe -import script.rts with Start-Process -Wait -PassThru, checks that ExitCode equals 0, and only then runs realtest.exe -orders script.rts so OrderClerk never submits stale orders.
What is the difference between OrdersMode OrderClerk and OrderClerkSync?
OrderClerk assumes you ran daily orders without interruption and reads OrderClerkTrades.csv directly. OrderClerkSync automatically detects skipped trading days, simulates missed signals using your script formulas, and outputs catch-up sync orders to realign your IBKR positions.
Why do my live IBKR fills differ from my RealTest backtest?
Check four items first. Add IF(BarsHeld >= 1, ..., 0) to ExitStop so day-1 FillPrice substitution does not diverge, add LimitExtra 0.001 * C so marginal tick-low touches are filtered out, ensure Quantity sizes off S.Alloc fed by fresh OrdersNetLiq, and run OrdersMode OrderClerkStats to compare live vs simulated curves.
How do you fix IBKR Error 201 limited liquidity or Peg-Best rejections from RealTest?
Tighten your strategy liquidity filter to at least $20M average daily dollar volume and ensure ExchangeMap.csv pins US stock primary routing cleanly to SMART/AMEX so TWS does not reject orders on thin or ambiguously routed symbols.
Where does RealTest write error messages during headless batch runs?
RealTest writes all command-line diagnostics, line numbers, and import warnings to C:\RealTest\batchlog.txt alongside numeric exit codes (0 success, 5 syntax error, 6 import error, 7 data issue).