Backtest Lab Docs

Strategy Variables

Strategy Variables are configurable parameters that can be defined once and reused throughout a trading strategy.

They allow you to control commonly used values from a single location, making it easier to experiment with different strategy configurations without modifying individual conditions or indicators.

How Variables Work

A variable consists of a name, a value, and a value type.

Once defined, it can be referenced in different parts of the strategy, including:

  • Expressions: Use a variable as part of a condition or calculation.
  • Indicator Parameters: Use a variable to configure an indicator's settings, such as its timeframe or number of periods.

For example, suppose your strategy uses an RSI indicator in several conditions, each with a period of 14.

Instead of entering 14 separately in every indicator, you could define a variable named rsi_periods with the value 14 and reference it wherever required.

If you later want to experiment with an RSI period of 21, you only need to update the variable's value. Every reference to that variable will use the updated configuration.

Other common applications include defining candle timeframes, price thresholds, or numerical parameters used repeatedly across a strategy.

Variable Value Types

When defining a variable, Backtest Lab requires you to select a Value Type.

The value type describes what kind of information the variable is intended to represent.

Some types allow general numerical values, while others represent more specific quantities, such as a positive number of periods or a candle timeframe.

Choosing an appropriate value type helps Backtest Lab validate the variable's value and prevent invalid configurations.

For example, the number of periods used by an RSI indicator must be positive. Selecting an appropriate value type allows the builder to detect an invalid value, such as -5, before the backtest is run.

Although generic value types provide flexibility, using a more specific value type is recommended whenever one is available.

Type Compatibility

Backtest Lab also checks whether a variable's value type is compatible with the parameter or expression in which it is being used.

For example, an indicator parameter expecting a candle timeframe cannot accept a variable containing an unrelated type of value.

If a variable's type is incompatible with the intended parameter, Backtest Lab prevents it from being used in that location.

These checks help ensure that strategy configurations are valid before execution.