Skip to content
Back to App

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:

TemplateStrategy TypeKey IdeaBest For
SMA CrossoverTrend followingTrade when fast and slow moving averages crossTrending markets, longer timeframes
RSI ScalperMean reversionBuy oversold, sell overbought based on RSIRange-bound markets, shorter timeframes
Channel BreakoutMomentumTrade when price breaks above/below recent extremesVolatile markets, breakout sessions
CustomYour logicBlank template with all API helpers readyAnything 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:

AspectSMA CrossoverRSI ScalperChannel Breakout
ApproachFollow the trendFade the extremesTrade the breakout
Signal frequencyLow to mediumMedium to highLow
Avg trade durationLongShortMedium to long
Whipsaw riskHigh in rangesLow in rangesHigh in ranges
Trend performanceStrongWeak (fights the trend)Strong
Number of params342
ComplexityLowMediumLow

How templates work under the hood

When you select a template and click Run Backtest, TestMax assembles a complete Python script from several parts:

  1. Script header — Imports, configuration from environment variables, and all API helper functions (api(), place_order(), get_positions(), etc.)
  2. Strategy parameters — Your template-specific parameters read from environment variables (e.g., FAST_PERIOD, SLOW_PERIOD)
  3. Backtest setup — Session initialization, account and contract ID resolution, and the get_next_bar() function definition
  4. Strategy logic — The main loop that processes bars and generates trading signals
  5. 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_BARS parameter. Set it to a specific number to limit how many bars the strategy processes (useful for quick testing). Set it to 0 to 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:

  1. Select the Custom template to get a blank strategy with all helpers pre-loaded
  2. Copy logic from a template and modify it
  3. Combine ideas from multiple templates (e.g., SMA crossover with RSI confirmation)
  4. Add risk management rules like stop-losses, take-profits, or position sizing

See Custom Strategies to learn how to write your own algorithms.

Detailed template guides