Strategy Templates
Strategy templates are pre-built Python trading algorithms you can run immediately without writing any code. Each template comes with configurable parameters so you can experiment with different settings and compare results.
Available templates
TestMax includes three strategy templates plus a blank custom template:
| Template | Strategy Type | Key Idea | Best For |
|---|---|---|---|
| SMA Crossover | Trend following | Trade when fast and slow moving averages cross | Trending markets, longer timeframes |
| RSI Scalper | Mean reversion | Buy oversold, sell overbought based on RSI | Range-bound markets, shorter timeframes |
| Channel Breakout | Momentum | Trade when price breaks above/below recent extremes | Volatile markets, breakout sessions |
| Custom | Your logic | Blank template with all API helpers ready | Anything you can code |
Choosing a template
SMA Crossover
The SMA Crossover is the most beginner-friendly template. It calculates two Simple Moving Averages — a fast one (default: 10 periods) and a slow one (default: 30 periods) — and generates signals when they cross.
Use this when:
- You want a simple, well-understood strategy to start with
- The market is trending (strong directional moves)
- You are backtesting on 1-minute or longer timeframes
Avoid when:
- The market is choppy or range-bound (you will get whipsawed)
- You are using very short timeframes like 1-second (noise causes false crossovers)
Parameters: FAST_PERIOD (10), SLOW_PERIOD (30), MAX_BARS (0)
RSI Scalper
The RSI Scalper uses the Relative Strength Index to identify oversold and overbought conditions. It buys when RSI drops below the oversold level and sells when RSI rises above the overbought level.
Use this when:
- The market is range-bound or mean-reverting
- You want to catch short-term price swings
- You are testing on 1-second to 5-minute timeframes
Avoid when:
- The market is strongly trending in one direction (RSI stays overbought/oversold)
- You are using very long timeframes where RSI signals are rare
Parameters: RSI_PERIOD (14), OVERBOUGHT (70), OVERSOLD (30), MAX_BARS (0)
Channel Breakout
The Channel Breakout tracks the highest high and lowest low over a lookback period. When price breaks above the channel, it buys. When price breaks below, it sells.
Use this when:
- You expect strong moves after consolidation (breakout patterns)
- The market has clear support and resistance levels
- You are testing around high-impact news events or session opens
Avoid when:
- The market is in a tight range (many false breakouts)
- Volatility is extremely low
Parameters: LOOKBACK (50), MAX_BARS (0)
Template comparison
Here is a side-by-side comparison to help you decide which template fits your scenario:
| Aspect | SMA Crossover | RSI Scalper | Channel Breakout |
|---|---|---|---|
| Approach | Follow the trend | Fade the extremes | Trade the breakout |
| Signal frequency | Low to medium | Medium to high | Low |
| Avg trade duration | Long | Short | Medium to long |
| Whipsaw risk | High in ranges | Low in ranges | High in ranges |
| Trend performance | Strong | Weak (fights the trend) | Strong |
| Number of params | 3 | 4 | 2 |
| Complexity | Low | Medium | Low |
How templates work under the hood
When you select a template and click Run Backtest, TestMax assembles a complete Python script from several parts:
- Script header — Imports, configuration from environment variables, and all API helper functions (
api(),place_order(),get_positions(), etc.) - Strategy parameters — Your template-specific parameters read from environment variables (e.g.,
FAST_PERIOD,SLOW_PERIOD) - Backtest setup — Session initialization, account and contract ID resolution, and the
get_next_bar()function definition - Strategy logic — The main loop that processes bars and generates trading signals
- Cleanup — Position flattening, session end, and final results output
You can view the assembled script at any time by switching to the Code tab in the bottom panel during or after a run.
Customizing template parameters
Every template exposes parameters that you can adjust before running:
- Modify parameters in the sidebar — When you select a template, its parameters appear as input fields. Change the values and run the backtest.
- Set MAX_BARS — All templates include a
MAX_BARSparameter. Set it to a specific number to limit how many bars the strategy processes (useful for quick testing). Set it to0to process all available bars in the date range.
Parameter tuning tips
- Change one parameter at a time. If you change multiple parameters between runs, you will not know which change caused the difference in results.
- Use the same date range. When comparing parameter settings, always backtest on the same instrument, dates, and timeframe.
- Test on multiple dates. A parameter set that works well on January 15 might fail on January 16. Run the same strategy on different days to check robustness.
- Consider the timeframe. Moving average periods of 10 and 30 mean very different things on 1-second vs 5-minute bars. A 30-period SMA on 1-second bars spans only 30 seconds, while on 5-minute bars it spans 2.5 hours.
From templates to custom strategies
Templates are a starting point. Once you understand how a template works, you can:
- Select the Custom template to get a blank strategy with all helpers pre-loaded
- Copy logic from a template and modify it
- Combine ideas from multiple templates (e.g., SMA crossover with RSI confirmation)
- Add risk management rules like stop-losses, take-profits, or position sizing
See Custom Strategies to learn how to write your own algorithms.