RealTest User Guide
RealTest User Guide

 

 

Navigation: <Root level>

New Example Scripts

 

 

 

 

The Examples-New folder is a curated library of example scripts organized by what you're trying to build, not by syntax feature. You'll find it in the Scripts\Examples-New subfolder of wherever you installed RealTest — C:\RealTest\Scripts\Examples-New for a default installation.

Every script is self-contained: it carries its own Import section (run Import once per data file, then Test as often as you like), states its teaching purpose in Notes, and lists the features it demonstrates. Scripts within a folder share a data file (the same SaveAs name), so importing any one of them covers its siblings. Most use Norgate data; the 10_data_import folder covers every other source.

Folder Contents


01_basics

The on-ramp: five short scripts that introduce the core moving parts of a RealTest script. Read them in order — every later example assumes them.

first_backtest.rts - your first backtest: a complete, minimal RealTest script

entry_types.rts - entry order types: the same dip-buy idea traded three ways

exit_types.rts - profit target, protective stop, and rule-based exits working together

position_sizing.rts - the four ways to size a position, side by side

data_vs_library.rts - Data vs. Library: the most important distinction in the script language


02_mean_reversion

Dip-buying and spike-fading on a survivorship-free stock universe.

mr_pullback_long.rts - the canonical dip-buy on a liquid stock universe

mr_short_side.rts - fading upward spikes

mr_long_short_pair.rts - long and short mean reversion combined in one script

mr_pair_common.rts - shared components included by mr_long_short_pair.rts (not meant to be run directly)

mr_moc_daytrade.rts - day trading: buy an intraday flush, sell the same day's close

mr_scale_in.rts - scaling in: averaging into a dip with multiple entries per symbol


03_trend_breakout

Breakouts, trailing stop constructions, weekly bars, and partial exits.

tf_donchian.rts - trend following basics: buy breakouts, ride a trailing stop, size by risk

tf_trailing_stops.rts - trailing stop techniques: seven exits for one entry, selectable by parameter

tf_weekly.rts - a strategy on weekly bars, honestly measured on daily bars

tf_pullback_entry.rts - buying the pullback in a trend: momentum continuation with a stop-limit entry

tf_scale_out.rts - scaling out: sell half at the first target, trail the rest


04_rotation_allocation

Momentum rotation and ETF asset-allocation portfolios.

rotate_monthly.rts - monthly momentum rotation: hold the strongest stocks in an index

rotate_dynamic.rts - rotation with true rebalancing using DynamicSizing mode

alloc_fixed_weights.rts - a five-asset fixed-weight "all weather" style portfolio

alloc_dual_momentum.rts - monthly tactical asset allocation: dual momentum with a canary asset

alloc_vol_target.rts - inverse-volatility weighting ("risk parity lite")


05_multi_strategy

The three capital-sharing patterns, cross-strategy caps, benchmarks and trackers.

combine_shared_capital.rts - combining strategies, pattern 1: one shared capital pool

combine_start_percent.rts - combining strategies, pattern 2: StartPercent sleeves

combine_two_accounts.rts - combining strategies, pattern 3: multiple accounts with cash transfers

combine_strategy_score.rts - strategy-level competition: StrategyScore and oversubscribed capacity

combine_benchmark.rts - benchmarks and trackers: comparison overlays and equity-curve gating


06_market_context

Regime, breadth, sector, and volatility context — with honest A/B tests of each filter, including one that fails.

regime_filter.rts - gate a strategy on the index trend, and test whether the gate helps

breadth_filter.rts - market breadth: build internals from the universe itself

sector_limits.rts - sector ranking and concentration limits

vix_filter.rts - using VIX level and term structure in a strategy

index_membership.rts - what survivorship-bias-free testing actually means


07_futures

Continuous-contract trend following, cost sensitivity, individual contracts and term structure. These scripts require custom Norgate futures watchlists — see each script's Notes.

futures_trend.rts - diversified trend following on continuous contracts, long and short

futures_one_contract.rts - one-contract testing and cost sensitivity

futures_term_structure.rts - individual contracts and term structure: VIX futures long/short


08_optimization

Parameter sweeps, pruning, walk-forward, overfitting analysis, and a random-entry null distribution.

opt_grid.rts - your first optimization: sweep two parameters, read the surface

opt_constraints.rts - optimizer controls: pruning, skipping, and ranking a sweep

opt_walk_forward.rts - walk-forward testing: simulate periodic re-optimization, honestly

opt_overfitting.rts - overfitting analysis: how much of your optimization is curve-fit?

opt_random_baseline.rts - random-entry baseline: the null hypothesis for your edge


09_scans_orders

From research to live: scans, order lists, broker baskets, rebalance files, and replaying actual fills.

scan_basic.rts - a basic scan: today's signal list, not a backtest

scan_multi_filter.rts - one scan, several signal lists

orders_tomorrow.rts - tomorrow's orders: from backtest to live trading

orders_basket.rts - broker basket orders: CSV output for IB Basket Trader

orders_rebalance.rts - target-percent output for the IB rebalance tool

track_actual_trades.rts - replaying actual trades: stats and equity from a list of real fills

The folder also includes the holidays.us.txt, ib_basket_template.csv and sample_trades.csv files used by these scripts.


10_data_import

One example per data source, plus symbol metadata, event lists, and external data series.

import_norgate.rts - the full-service data source

import_yahoo.rts - free data, no account needed

import_eodhd.rts - global exchange coverage via API

import_tiingo.rts - a low-cost API data source

import_csv.rts - your own data, one CSV file per symbol

import_metastock.rts - reading MetaStock-format local data

import_multi.rts - one data file from several sources

syminfo_events.rts - symbol information files and event lists: metadata and dated events

external_series.rts - joining your own values to the bars

The folder also includes sample data used by these scripts: djia_earnings.csv, djia_info.csv, djia_syms.txt, sample_values.csv, and the sample_csv folder.


11_output_reporting

Custom Results, Trades, Charts and Graphs sections, TestData/StratData, and account-level cash flows and fees.

custom_results.rts - design your own results table

custom_trades_charts.rts - custom trade list columns and chart overlays

custom_graphs.rts - daily series for the stats graph and CSV export

testdata_stratdata.rts - custom analytics computed during the test

accounting.rts - deposits, fees, cash interest, and honest Sharpe


12_special_topics

International markets, multi-currency accounts, Library functions with arguments, and a debugging checklist.

international_asx.rts - trading a non-US market: Australian stocks, weekly MOC rotation

multi_currency.rts - US, Australian, and Canadian stocks in one account

library_functions.rts - reusable formulas with arguments

debug_and_validate.rts - debugging and validating a strategy that "runs but looks wrong"

The folder also includes the holidays.au.txt file used by these scripts.


Which Example Do I Want?

I want to...

Start here

Run my first backtest

01_basics\first_backtest.rts

Understand entry/exit order types

01_basics\entry_types.rts, exit_types.rts

Size positions (shares / dollars / percent / risk)

01_basics\position_sizing.rts

Understand Data vs Library (do this early!)

01_basics\data_vs_library.rts

Buy dips in a stock universe

02_mean_reversion\mr_pullback_long.rts

Short spikes / trade both sides

02_mean_reversion\mr_short_side.rts, mr_long_short_pair.rts

Day trade (no overnight holds)

02_mean_reversion\mr_moc_daytrade.rts

Average into a position

02_mean_reversion\mr_scale_in.rts

Trade breakouts with trailing stops

03_trend_breakout\tf_donchian.rts, tf_trailing_stops.rts

Trade weekly bars

03_trend_breakout\tf_weekly.rts

Buy pullbacks in trends (stop-limit entries)

03_trend_breakout\tf_pullback_entry.rts

Take partial profits

03_trend_breakout\tf_scale_out.rts

Rotate into the strongest stocks monthly

04_rotation_allocation\rotate_monthly.rts

Rebalance positions to target sizes

04_rotation_allocation\rotate_dynamic.rts

Run a fixed-weight ETF portfolio

04_rotation_allocation\alloc_fixed_weights.rts

Tactical asset allocation (dual momentum)

04_rotation_allocation\alloc_dual_momentum.rts

Risk-parity style weighting

04_rotation_allocation\alloc_vol_target.rts

Combine several strategies in one account

05_multi_strategy\combine_shared_capital.rts (start), then combine_start_percent.rts, combine_two_accounts.rts

Let strategies compete for capital

05_multi_strategy\combine_strategy_score.rts

Compare against buy & hold / gate on the equity curve

05_multi_strategy\combine_benchmark.rts

Add a bull-market filter (and test it honestly)

06_market_context\regime_filter.rts

Use market breadth

06_market_context\breadth_filter.rts

Limit sector concentration

06_market_context\sector_limits.rts

Use VIX / term structure

06_market_context\vix_filter.rts

Understand survivorship bias

06_market_context\index_membership.rts

Trade futures

07_futures\futures_trend.rts (continuous), futures_term_structure.rts (individual contracts)

Check if costs kill a futures edge

07_futures\futures_one_contract.rts

Optimize parameters

08_optimization\opt_grid.rts, then opt_constraints.rts

Know whether I'm curve-fitting

08_optimization\opt_overfitting.rts, opt_walk_forward.rts, opt_random_baseline.rts

Get today's signal list

09_scans_orders\scan_basic.rts, scan_multi_filter.rts

Generate tomorrow's orders

09_scans_orders\orders_tomorrow.rts, orders_basket.rts, orders_rebalance.rts

Analyze my actual fills

09_scans_orders\track_actual_trades.rts

Import data (any source)

10_data_import\import_<source>.rts

Attach metadata / earnings dates

10_data_import\syminfo_events.rts

Join external data to bars

10_data_import\external_series.rts

Customize results / trades / graphs output

11_output_reporting\custom_*.rts

Compute portfolio-level analytics in-test

11_output_reporting\testdata_stratdata.rts

Model deposits, fees, cash interest

11_output_reporting\accounting.rts

Trade non-US markets / multiple currencies

12_special_topics\international_asx.rts, multi_currency.rts

Write reusable formula functions

12_special_topics\library_functions.rts

Debug a strategy that "runs but looks wrong"

12_special_topics\debug_and_validate.rts

Conventions Used Throughout

Realistic costs everywhere: Commission: Max(1, 0.005 * Shares) (IB-style), slippage or LimitExtra where fills would otherwise be optimistic, Slippage: TickSize on futures.

Every portfolio strategy has at least one capacity limit (MaxPositions, MaxExposure or MinFreeCash).

Test start dates leave a warmup year after the import start so long-lookback indicators are ready, and never precede an index's constituency coverage.

Each script ends with a small #ifdef research include used by AI-assisted research sessions (see Using RealTest with Agentic AI). It is inert in normal use.

Some strategies are deliberately mediocre. When a filter doesn't help or an edge dies to transaction costs, the Notes say so — reading an honest negative result is part of the lesson.

 

 

 

Copyright © 2020-2026 Systematic Solutions, LLC