Algo Playground
The Algo Playground is TestMax’s Python-based algorithm backtesting environment. Write trading strategies in Python, run them against real historical market data, and watch the results unfold in real time on an interactive chart.
Instead of manually replaying bars and clicking to place trades, you define your logic in code and let the Playground execute it bar-by-bar — placing orders, tracking positions, and calculating P&L automatically.
What you can do
- Backtest strategies on historical data — Run your Python code against 1-second, 1-minute, 5-minute, or 15-minute bars for instruments like NQ, ES, GC, CL, and EURUSD.
- Start from templates or write from scratch — Choose a pre-built strategy (SMA Crossover, RSI Scalper, Channel Breakout) or write completely custom logic.
- Watch execution in real time — The chart updates live as your strategy processes each bar. Trade markers, candlesticks, and an equity curve render as the backtest runs.
- Control playback speed — Adjust execution speed from 1x to 100x while the backtest is running. Slow down to study individual trades or speed up to see the full picture.
- Save and compare strategies — Save your strategies with custom names, reload them later, and compare results across different runs and parameter sets.
- Use the real TopStep API — The Python code uses the same API endpoints as the live TopStep ProjectX Gateway. When you are ready to trade live, the transition requires minimal code changes.
How it works
The Playground follows a straightforward workflow:
- Configure — Pick an instrument, date range, timeframe, and strategy template (or write custom code).
- Run — Click “Run Backtest.” The server executes your Python script, stepping through historical bars one at a time.
- Watch — A WebSocket connection streams results back to your browser. The chart renders candles, trade markers (green triangles for buys, red for sells), and the equity curve updates live.
- Analyze — When the backtest completes, review final P&L, win rate, total trades, and the full output log. Switch to the Trades tab for a detailed breakdown.
The Python environment
Each strategy runs as a standalone Python script on the server. TestMax provides a set of helper functions that handle API communication, order placement, position management, and bar iteration. You do not need to install any packages — the scripts use only Python standard library modules (os, sys, json, time, urllib).
Your strategy code has access to:
- API functions —
api(),place_order(),get_positions(),close_all_positions(),get_account() - Bar iteration —
get_next_bar()returns the next OHLCV bar from the replay - Speed control —
read_speed()reads the current playback speed from the UI - Environment variables — Instrument, date range, timeframe, account ID, contract ID, and custom parameters are all passed via environment variables
See the Python API Reference for complete documentation of every available function.
Strategy templates
Templates give you a working strategy out of the box. Each template includes configurable parameters so you can experiment without writing any code.
| Template | Strategy Type | What It Does |
|---|---|---|
| SMA Crossover | Trend following | Buys when a fast moving average crosses above a slow moving average, sells on the opposite cross |
| RSI Scalper | Mean reversion | Buys when RSI drops below the oversold threshold, sells when it rises above overbought |
| Channel Breakout | Momentum | Buys on a price breakout above the recent highest high, sells on a breakdown below the lowest low |
| Custom | Your logic | Blank template with all helper functions ready — write whatever you want |
See Strategy Templates for detailed documentation on each one.
Interface layout
The Playground page is divided into several sections:
- Left sidebar — Configuration panel with instrument, dates, timeframe, template selection, parameters, speed control, and the Run/Stop button.
- Main chart — Candlestick chart with trade markers. Updates in real time during execution.
- Equity curve — Line chart below the main chart showing your account balance over time.
- Bottom panel — Tabbed area with three views:
- Output — Real-time log output from your strategy (
[INFO],[TRADE],[ERROR],[DONE]messages). - Code — Read-only view of the full Python script being executed (including the auto-generated header and setup code).
- Trades — Table of all trades executed during the run, with entry/exit prices and P&L.
- Output — Real-time log output from your strategy (
- Account bar — Shows current balance, equity, unrealized P&L, and trade count.
Supported instruments
The Algo Playground supports all instruments available in TestMax’s historical data library:
| Symbol | Instrument | Exchange | Tick Size |
|---|---|---|---|
| NQ | Nasdaq 100 E-mini | CME | 0.25 |
| ES | S&P 500 E-mini | CME | 0.25 |
| GC | Gold Futures | COMEX | 0.10 |
| CL | Crude Oil Futures | NYMEX | 0.01 |
| EURUSD | Euro/US Dollar | Forex | 0.00001 |
Each instrument has different price characteristics, volatility profiles, and tick values. A strategy that works well on NQ may behave differently on CL due to differences in how these markets move. Always test your strategy on the specific instrument you plan to trade.
Available timeframes
| Timeframe | Resolution | Typical Use Case |
|---|---|---|
| 1s | 1-second bars | Ultra-high resolution scalping, tick analysis |
| 5s | 5-second bars | Short-term scalping |
| 1m | 1-minute bars | Most common for intraday strategies |
| 5m | 5-minute bars | Intraday swing trading |
| 15m | 15-minute bars | Longer-term intraday or multi-day analysis |
Shorter timeframes produce more bars and take longer to process but provide finer detail. Longer timeframes run faster and are better for strategies that hold positions for extended periods.
TopStep compatibility
The Algo Playground uses the exact same API as the real TopStep ProjectX Gateway. This means the Python strategies you develop and test in TestMax can be adapted for live trading with minimal changes — primarily swapping the API URL and replacing get_next_bar() with a real-time data feed.
See TopStep Compatibility for a detailed migration guide.