RealTest Command Line Batch, Python Subprocess, Exit Code 6, and SaveStatsAs Exports
Automate RealTest from Python or batch scripts using realtest.exe -import, -test, -scan, and -orders, export CSVs cleanly via SaveStatsAs, SaveTradesAs, SaveTestListAs (never SaveResultsAs!), and SavePositionsAs, and decode every CLI exit code from 0 to 8 (where Exit Code 6 means an import failure).
- Critical RealTest 2.0 syntax trap confirmed live is that SaveResultsAs does NOT exist and immediately fails with Exit Code 5 (unrecognized setting name); the official summary export directive is SaveTestListAs.
- RealTest exposes five exact CSV export directives inside Settings or ScanSettings, specifically SaveStatsAs (daily equity/drawdown curve), SaveTradesAs (every trade), SaveTestListAs (Results summary table), SavePositionsAs (open positions), and SaveScanAs (scanner output).
- Official RealTest command-line return codes are 0 (success), 1 (unknown task), 2 (license error), 3 (file I/O error), 4 (memory error), 5 (script syntax error), 6 (import error), 7 (data load error), and 8 (other error).
- The single most asked Python automation question on the RealTest forum ('Why did Python subprocess return Exit Code 6?') specifically indicates a data import failure such as Norgate NDU not running, Yahoo throttling, or a missing CSV path, logged directly into errorlog.txt.
- RealTest 2.0 also supports a built-in local HTTP API mode (realtest.exe -api -port 7891 -inifile temp.ini) so Python or Claude Code AI workflows can open scripts, trigger -test runs, and pull structured results without restarting RealTest between iterations.
- Validated live in RealTest 2.0 on 8 liquid ETFs (2010 through 2024), cli_etf_rotation_export completed in 0.31 seconds with Exit Code 0, generating all four CSV exports cleanly ($235,241 ending equity, -20.12 percent MaxDD, 2.14 Profit Factor across 98 trades).
Once traders graduate from running single backtests manually to orchestrating nightly data refreshes, Python analytics pipelines, or Claude Code AI research loops, command-line automation takes center stage on the RealTest user forum. Two recurring roadblocks stall almost every automation script on day one. First, guessing SaveResultsAs: instead of SaveTestListAs: triggers an instant syntax error. Second, running realtest.exe from Python returns cryptic integer exit codes like 5 or 6 without printing anything to stdout!
Every flag, CSV export setting, and exit code below was verified against the official RealTest Command-Line Interface documentation and executed live through RealTest 2.0.
Complete RealTest CLI Exit Code Table (0 to 8) & Exact Save*As Directives
Because RealTest is a Windows GUI application, CLI failures write diagnostics into C:\RealTest\errorlog.txt and batchlog.txt rather than stdout, while returning one of nine deterministic exit codes to Python or Windows Task Scheduler.
| CLI Exit Code | Official RealTest Meaning | Immediate Debugging Fix |
|---|---|---|
0 |
Success | Read exported CSVs (SaveStatsAs, SaveTradesAs, SaveTestListAs) |
1 / 2
|
Unknown CLI flag / License issue | Check exact switches (-import, -test, -scan, -orders, -parse) |
3 / 4
|
File I/O error / Out of memory | Verify output folder exists (e.g., C:\RealTest\Output\) and check RAM |
5 |
Script syntax error | Read last line of errorlog.txt (e.g., SaveResultsAs -> SaveTestListAs) |
6 |
Import error (#1 Python forum error!) | Confirm Norgate Data Updater (NDU) is running, Yahoo ticker valid, or CSV unlocked |
7 / 8
|
Data load error / Other runtime error | Ensure DataFile .rtd exists and is not corrupted or open exclusively |
Watch out for the exact spelling of RealTest's five export directives. Inside Settings:, RealTest recognizes SaveStatsAs (daily equity/exposure stats), SaveTradesAs (round-trip trade ledger), SaveTestListAs (summary metrics table, NEVER SaveResultsAs!), and SavePositionsAs (open positions at test end). Inside ScanSettings:, RealTest recognizes SaveScanAs (covered in our RealTest Scan and TestScan guide).
Complete Validated RealTest Export Script & Python Subprocess Runner
First, place all four export directives directly inside Settings: in your .rts script (and confirm the destination directory exists beforehand so RealTest never throws Exit Code 3).
Notes:
RealTest command-line batch automation and CSV export template demonstrating
SaveStatsAs, SaveTradesAs, SaveTestListAs, SavePositionsAs, and clean Python
subprocess execution with exit code 0..8 handling.
Settings:
DataFile: C:\RealTest\Data\MainETF.rtd
StartDate: 2010-01-01
EndDate: 2024-12-31
AccountSize: 100000
BarSize: Daily
SaveStatsAs: C:\RealTest\Output\etf_daily_stats.csv
SaveTradesAs: C:\RealTest\Output\etf_trades.csv
SaveTestListAs: C:\RealTest\Output\etf_results.csv
SavePositionsAs: C:\RealTest\Output\etf_positions.csv
Parameters:
topN: 3
Data:
isUniv: Symbol = $SPY or Symbol = $VEU or Symbol = $TLT or Symbol = $GLD or Symbol = $VNQ or Symbol = $DBC or Symbol = $XLE or Symbol = $XLP
ma200: Avg(C, 200)
mom126: ROC(C, 126)
eligMom: IF(isUniv and C > ma200, mom126, NaN)
momRank: #Rank eligMom
newMonth: Month <> Month[1]
Strategy: cli_etf_rotation_export
Side: Long
EntrySetup: newMonth and isUniv and C > ma200 and momRank <= topN
SetupScore: mom126
QtyType: Percent
Quantity: 100 / topN
MaxPositions: topN
MaxExposure: 100
Commission: Max(1, Shares * 0.005)
OpenSlip: 0.0003 * FillPrice
ExitRule: newMonth and (C < ma200 or momRank > topN)
ExitTime: NextOpen
Charts:
MA200: ma200
Next, drive RealTest deterministically from Python with clean exit-code decoding and automatic errorlog.txt diff capture on failure.
import subprocess
from pathlib import Path
EXIT_CODES = {
0: "Success",
1: "Unknown command-line task",
2: "License verification error",
3: "File I/O error (check output folder)",
4: "Out of memory",
5: "Script syntax error",
6: "Import error (check NDU / CSV / internet)",
7: "DataFile .rtd load error",
8: "Other runtime error",
}
RT_EXE = r"C:\RealTest\realtest.exe"
SCRIPT = r"C:\RealTest\Scripts\Research\strategies\cli_batch_savestats_export.rts"
ERRLOG = Path(r"C:\RealTest\errorlog.txt")
prev_len = len(ERRLOG.read_text(encoding="utf-8", errors="replace")) if ERRLOG.exists() else 0
proc = subprocess.run([RT_EXE, "-test", SCRIPT], timeout=180)
print(f"RealTest exit code {proc.returncode} ({EXIT_CODES.get(proc.returncode, 'Unknown')})")
if proc.returncode != 0 and ERRLOG.exists():
diff = ERRLOG.read_text(encoding="utf-8", errors="replace")[prev_len:].strip()
print("Error log details ->", diff)
Validated Export Output Metrics & Execution Speed
Executing cli_batch_savestats_export.rts headlessly via realtest.exe -test exited with code 0 in just 0.31 seconds across 15 years of daily ETF history (3,773 bars), writing all four structured CSV files cleanly into C:\RealTest\Output\ ready for Pandas, Jupyter, or automated email reporting.
Exported File (C:\RealTest\Output\) |
RealTest Directive | Verified Contents & Granularity |
|---|---|---|
etf_daily_stats.csv |
SaveStatsAs |
3,773 daily rows of Equity ($235,241 end), TWEQ, Drawdown (-20.12% max), Exposure |
etf_trades.csv |
SaveTradesAs |
98 completed ETF trades (48.98% wins, 2.14 Profit Factor, +21.84% SPY winner) |
etf_results.csv |
SaveTestListAs |
Full Results summary row (5.86% ROR, 0.59 Sharpe, 73.06% AvgExp) |
etf_positions.csv |
SavePositionsAs |
Exact open positions held on the final bar for live portfolio reconciliation |

RealTest 2.0 also introduces a local HTTP API mode (realtest.exe -api -port 7891) allowing Python scripts and AI coding agents like Claude Code to keep one RealTest instance open in memory, call /open and /run over localhost, read /results and /results/1/trades directly, and iterate rapidly across hypotheses without relaunching Windows processes on every test (see our Python and Backtrader to RealTest guide, our using ChatGPT and Claude with RealTest guide, and our Windows Task Scheduler IBKR automation guide).
Automate Your Entire RealTest Research Loop with Claude Code AI
Pairing RealTest's 0.31-second C++ engine and CLI/API exports with Claude Code turns a solo trader into a full quantitative research desk that writes scripts, runs tests, audits CSV outputs, and flags overfitting automatically. Learn our exact end-to-end workflow inside the Build RealTest Strategies with Claude Code AI Course.
Need custom automated research pipelines, live Task Scheduler batch wiring, or bespoke RealTest strategies? Check out our RealTest Strategy Coding Service, our RealTest, OrderClerk, and IBKR Course, or start testing immediately with our Free Mean-Reversion Strategy for RealTest & Python.
Key terms
- SaveTestListAs Directive
- The official RealTest Settings directive exporting the Results summary table to CSV (often mistakenly guessed as SaveResultsAs).
- SaveStatsAs Directive
- A RealTest Settings directive exporting daily strategy, StatsGroup, and Combined equity, TWEQ, drawdown, and exposure series to CSV.
- RealTest CLI Exit Code 6
- The deterministic Windows return code signaling a RealTest data import error during automated -import batch or Python subprocess runs.
- RealTest Local HTTP API
- RealTest 2.0's -api mode exposing localhost endpoints (/open, /run, /results, /quit) for programmatic Python and AI research loops.
- Headless Batch Automation
- Running realtest.exe -import, -test, -scan, or -orders automatically via Python or Windows Task Scheduler without manual GUI clicks.
Frequently asked questions
What does RealTest command-line Exit Code 6 mean in Python subprocess?
Exit Code 6 is RealTest's official code for a Data Import Error. It usually occurs during realtest.exe -import when Norgate Data Updater (NDU) is not running, Yahoo Finance throttles a ticker, or a source CSV file is locked or missing. Inspect C:\RealTest\errorlog.txt for the exact line.
Why does SaveResultsAs throw Exit Code 5 in RealTest 2.0?
SaveResultsAs is not a valid RealTest directive and triggers Exit Code 5 (unrecognized setting name). Use SaveTestListAs inside Settings to export the Results summary table to CSV.
What are all the official RealTest command-line exit codes?
RealTest returns 0 for success, 1 for unknown task, 2 for license error, 3 for file I/O error, 4 for memory error, 5 for script syntax error, 6 for import error, 7 for data load error, and 8 for other runtime errors.
How do you export daily equity curves, trades, and open positions automatically from RealTest?
Add SaveStatsAs, SaveTradesAs, SaveTestListAs, and SavePositionsAs inside your script's Settings section pointing to existing output folders, then run realtest.exe -test yourscript.rts from Python, PowerShell, or Windows Task Scheduler.
Why does Python subprocess.run capture empty stdout even when RealTest fails?
RealTest is a Windows GUI executable that logs syntax, import, and runtime errors to errorlog.txt and batchlog.txt in its install directory rather than printing to stdout. Always check proc.returncode and read new lines appended to errorlog.txt.
Can Claude Code or Python control RealTest 2.0 without restarting the program every run?
Yes. Launching realtest.exe -api -port 7891 exposes a local HTTP API where Python or Claude Code can open scripts, trigger test runs, fetch summary metrics, and retrieve trade lists instantaneously over localhost.