RealTest RealTest Code Scan Stock Scanner TestScan VCP

RealTest Scan and TestScan Guide (Daily VCP Scanners and Open Position Exports)

Summary

In RealTest, Scan runs independently before any backtest using Data items and ScanSettings to screen watchlists or export daily candidates to CSV, whereas TestScan runs at the end of a backtest with full access to open holdings via Extern(@strategy_name, Shares <> 0). Use Scan for daily VCP or breakout watchlists, use TestScan to audit open positions and active stop levels, and remember that Scan never sees Strategy capacity limits.

· 6 min read
RealTest 2.0 scanner workbench showing 7 Stage 2 S&P 500 VCP Scan output rows top, Scan and TestScan script bottom-left, and FICO breakout chart bottom-right
Key findings
  • Scan and TestScan solve two different problems in RealTest, with Scan evaluating pre-test Data formulas across your universe while TestScan executes after a backtest to inspect live open holdings via Extern(@strategy_name, ...).
  • ScanSettings overrides Settings strictly during Scan mode (-scan), letting one script keep a multi-year backtest window in Settings while scanning only the latest trading day into SaveScanAs.
  • Scan output counts frequently exceed Backtest entry counts because Scan checks raw EntrySetup conditions without enforcing MaxPositions, MaxExposure, MaxSameSym, or intraday EntryLimit fill rules.
  • Because TestScan operates per symbol without an implicit strategy scope even in single-strategy scripts, always wrap open-position variables inside Extern(@your_strategy, Shares), FillPrice, BarsHeld, and stopPx.
  • Appending formatting tags such as {%} for percentages and {/#} for clean decimals inside Scan columns formats both the RealTest Scan grid and exported CSV files automatically.
  • Validated in RealTest 2.0 on historical S&P 500 data, -scan screened 7 Stage 2 tight-base VCP candidates on December 31, 2024 (DFS-202505, SW, LUV, CAH, WAT, T, CME) while -test executed 651 breakout trades cleanly.

Across 84 dedicated threads on the RealTest user forum, Scan and TestScan generate more daily workflow questions than almost any other feature outside live orders. Traders try to read Shares or FillPrice inside a regular Scan block and get zeros, wonder why a scan finds 25 candidates while the backtest enters only 4, or copy an entire script into a second file just to run a single-day watchlist screen.

Every rule and column formatter below follows the official RealTest Scan and TestScan documentation, and the complete S&P 500 Stage 2 Volatility Contraction (VCP) scanner plus post-test position exporter was verified via both realtest.exe -scan and -test in RealTest 2.0.

Scan vs TestScan vs Backtest (Why Counts Differ)

Choosing the right scan section eliminates nearly every silent zero-column bug in RealTest.

RealTest Mode When It Runs Sees Data & Breadth Tags Sees Open Shares, FillPrice & Stops Primary Use Case
Scan (-scan) Standalone pre-test screen Yes No (always 0 or NaN) Daily watchlist screening (VCP tight bases, oversold setups, RS leaders)
TestScan (runs with -test) End of backtest (or every date if TestScanAllDates: True) Yes Yes (via Extern(@strat, ...)) Auditing open holdings, active trailing stop prices, and order logs
Strategy (-test) Full portfolio simulation loop Yes Yes (native context) Enforcing MaxPositions, MaxExposure, SetupScore, and limit fills

That table also explains the classic forum question about why Scan and Backtest disagree. A Scan filter checks every symbol passing your indicator criteria on a date. It knows nothing about how many slots are already full, whether SetupScore ranked other candidates higher, or whether an intraday EntryLimit will fill tomorrow. To see exact post-constraint accepted vs skipped setups, combine TestScan with KeepTrades: All from our RealTest debugging reference.

Using ScanSettings, Column Formatting, and Watchlist Splits

Just as OrderSettings isolates live order settings, ScanSettings overrides Settings only when you click Scan or run realtest.exe -scan. Setting StartDate: Latest (or a target date) and SaveScanAs: C:\RealTest\Scans\daily_vcp_scan.csv inside ScanSettings keeps your multi-year backtest dates intact while exporting a fresh daily watchlist CSV automatically.

Two practical formatting tips make Scan tables immediately readable. First, avoid naming any Scan column after a reserved RealTest keyword like Close, Open, Symbol, or Rank (use ClosePx, RS_60d, BreakoutLv instead). Second, add Sort: -RS_60d (leading minus sorts descending) and inline format tags like {%} for percentage columns so both the RealTest grid and CSV export stay clean. You can also split any universe cleanly into In-Sample vs Out-of-Sample watchlists inside Scan or EntrySetup by checking even vs odd symbol indices or fixed date cutoffs.

Complete Validated RealTest Script (Stage 2 VCP Scan + Open-Position TestScan)

Below is a complete, runnable S&P 500 script built on survivorship-free Norgate Data historical constituents (InSPX). Running -scan screens for Stage 2 stocks (C > ma50 > ma150 > ma200) with contracting 10-day price range below 8 percent, contracting short-term volatility (ATR(5) / ATR(20) < 0.85), and price hovering within 8 percent of its 50-day high. Running -test simulates the 50-day breakout strategy and triggers TestScan to list every open holding alongside its exact entry price, holding bars, and active Chandelier trailing stop.

Notes:
	Daily Scan and post-test TestScan workflow on historical S&P 500 stocks.
	Scan screens for tight Stage 2 volatility contraction bases; TestScan
	exports active open positions with entry price, bars held, and stop level.

Import:
	DataSource:	Norgate
	IncludeList:	.S&P 500 Current & Past
	StartDate:	2018-01-01
	EndDate:	Latest
	SaveAs:	spx_scanner.rtd

Settings:
	DataFile:	spx_scanner.rtd
	StartDate:	2020-01-01
	EndDate:	2024-12-31
	AccountSize:	100000
	BarSize:	Daily

ScanSettings:
	StartDate:	2024-12-31
	EndDate:	2024-12-31
	SaveScanAs:	C:\RealTest\Scans\daily_vcp_scan.csv

Parameters:
	numPos:	10

Data:
	ma50:	Avg(C, 50)
	ma150:	Avg(C, 150)
	ma200:	Avg(C, 200)
	atr5:	ATR(5)
	atr20:	ATR(20)
	hh50:	HHV(H, 50)
	range10:	(HHV(H, 10) - LLV(L, 10)) / C
	volRatio:	atr5 / Max(atr20, 0.001)
	rs60:	ROC(C, 60)
	liquid:	C > 15 and Avg(C * V, 20) > 25000000
	stage2:	InSPX and liquid and C > ma50 and ma50 > ma150 and ma150 > ma200
	tightBase:	stage2 and range10 < 0.08 and volRatio < 0.85 and C > hh50 * 0.92
	breakoutSig:	stage2 and C > hh50[1]

Library:
	stopPx:	HHV(H - 3 * atr20, BarsHeld + 1)

Scan:
	Filter:	tightBase
	ClosePx:	C
	RS_60d:	rs60 {/#}
	Range10Pct:	range10 {%}
	ATR_Ratio:	volRatio
	BreakoutLv:	hh50
	Sort:	-RS_60d

Strategy: spx_breakout_scan
	Side:	Long
	EntrySetup:	breakoutSig
	SetupScore:	rs60
	Quantity:	100 / numPos
	QtyType:	Percent
	MaxPositions:	numPos
	MaxExposure:	100
	Commission:	Max(1, Shares * 0.005)
	OpenSlip:	0.0005 * FillPrice
	StopSlip:	0.001 * FillPrice
	ExitStop:	IF(BarsHeld >= 1, stopPx, 0)
	ExitRule:	BarsHeld >= 40
	ExitTime:	NextOpen
	Ambiguity:	Stop

TestScan:
	Filter:	Extern(@spx_breakout_scan, Shares <> 0)
	ClosePx:	C
	OpenShares:	Extern(@spx_breakout_scan, Shares)
	EntryPx:	Extern(@spx_breakout_scan, FillPrice)
	HeldBars:	Extern(@spx_breakout_scan, BarsHeld)
	ActiveStop:	Extern(@spx_breakout_scan, stopPx)
	Sort:	-HeldBars

Charts:
	MA50:	ma50
	MA200:	ma200

Validated RealTest 2.0 Output (Scan Grid + Breakout Backtest)

Running realtest.exe -scan on December 31, 2024 exited with code 0 and exported 7 tight-base Stage 2 S&P 500 leaders ranked by 60-day relative strength (DFS-202505 at +19.56%, SW at +15.18%, LUV at +7.58%, CAH at +5.62%, WAT at +5.24%, T at +3.93%, and CME at +3.48%), all displaying 10-day ranges between 3.25% and 7.16% and contracting ATR ratios below 0.85. Running -test across 2020 through 2024 completed 651 breakout trades (583 exit stop, 57 exit rule, and 11 end-of-data/end-of-test closures, ending at $119,303) while TestScan exported all 7 active holdings on the final session with their live trailing stop prices.

RealTest 2.0 Stage 2 breakout chart on FICO from Scan and TestScan S&P 500 scanner template showing MA50 and MA200
RealTest 2.0 trade chart on FICO (August 14 to October 10, 2024) from the validated Stage 2 breakout script showing clean MA50/MA200 alignment and a +12.88% advance through the 40-bar exit rule.

Pairing Daily Scanners With Systematic Breakout Rules

Combining a fast daily Scan watchlist with audited backtesting rules lets you inspect chart structure visually while verifying historical expectancy quantitatively. For deeper breakout mechanics and indicator formulas, pair this scanner with our RealTest indicators cheat sheet (VCP, SuperTrend, Clenow R-Squared) and our RealTest Turtle Donchian breakout guide.

If you want a ready-made, production breakout flag scanner you can run daily in RealTest immediately, check out our Breakout Flag Pattern Scanner for RealTest or explore the full RealTest Modern Breakout Strategy. To download more free working scripts right away, visit our free RealTest strategy and code library, or see our Build RealTest Strategies with Claude Code AI course for automated scanner and backtest scripting workflows.

Key terms

Scan Section
A standalone RealTest script section that filters symbols using Data formulas and displays or exports formatted screening tables to CSV.
TestScan Section
A post-backtest RealTest scan section with full access to open holdings, entry fill prices, and strategy stop levels via Extern(@strategy_name, ...).
ScanSettings
An optional RealTest script section whose date range and SaveScanAs paths override Settings strictly when running in Scan mode (-scan).
TestScanAllDates
A RealTest Settings option (default False) that expands TestScan from the final backtest date to every historical date in the simulation.
Volatility Contraction Pattern (VCP)
A Stage 2 bullish consolidation setup characterized by shrinking price ranges and declining short-term ATR relative to longer-term ATR ahead of a breakout.

Frequently asked questions

What is the difference between Scan and TestScan in RealTest?

Scan runs standalone before any backtest and evaluates only Data-section formulas across your universe (so Shares and FillPrice are unavailable). TestScan runs at the end of a backtest and can inspect active open positions, entry prices, holding periods, and trailing stop levels via Extern(@strategy_name, ...).

How do you read current open positions in RealTest Scan?

Use a TestScan section rather than a regular Scan section, set Filter to Extern(@your_strategy_name, Shares <> 0), and wrap each position column such as Shares, FillPrice, BarsHeld, or active stop price inside Extern(@your_strategy_name, ...).

Why does my RealTest Scan return more stocks than my backtest enters?

Scan evaluates raw indicator criteria without applying portfolio constraints. Your Strategy backtest drops candidates that exceed MaxPositions, MaxExposure, MaxSameSym, lower SetupScore rank, or fail to trigger intraday EntryLimit prices.

How do you scan only the latest trading day while keeping multi-year backtest dates?

Add a ScanSettings section to your script with StartDate set to Latest, EndDate set to Latest, and SaveScanAs pointing to your output CSV path. RealTest applies ScanSettings strictly in Scan mode while keeping Settings unchanged for backtests.

How do you export a RealTest TestScan across every date of a backtest?

Add TestScanAllDates set to True inside Settings alongside SaveScanAs. By default RealTest runs TestScan only on the final test date before end-of-test exits.

How do you sort Scan output descending in RealTest?

Add a Sort line at the bottom of your Scan or TestScan section with a minus sign in front of the column name (such as Sort -RS_60d or Sort -HeldBars).

Related strategies

Breakout Flag Pattern Scanner
Ready-to-run RealTest breakout flag and tight-base stock scanner built cleanly for daily watchlist workflows.
View →
RealTest Modern Breakout Strategy
Full systematic equity breakout strategy in RealTest built on survivorship-free historical data with transparent editable code.
View →
Build RealTest Strategies with Claude Code AI
Automated workflow for building and validating RealTest scanners, TestScan exports, and strategies with Claude Code.
View →
← Back to Learn

#1 RealTest Backtests

Supercharge Your Trading Now

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

Browse RealTest Strategies