Backtest Lab Docs
Saved Values
Saved Values allow a strategy to remember information from an earlier stage and use it to make decisions later.
For example, a strategy might need to remember the price at which a breakout occurred, then compare future prices against that recorded level.
Without saved values, the strategy would only be able to use currently available market data and calculated indicators, rather than remembering a specific value from an earlier event.
How Saved Values Work
Saving a value is a State Entry Action. Like other state actions, it is performed once when the strategy enters the state, not repeatedly while the state remains active.
The saved value is then available for use in subsequent strategy logic, including:
- Conditions: Compare current market data against a previously recorded price or indicator value.
- Trade Entry: Use a saved value when calculating an order's limit price.
- Risk Management: Use a previously recorded value to configure stop-loss or target-profit levels.
A value must be saved before it can be used. Once recorded, it remains available as the strategy progresses through its states, until it is cleared or replaced.
Example: Remembering a VWAP Level
Consider a strategy that looks for a price crossover above the Volume-Weighted Average Price (VWAP), followed by a return to that level before entering a trade.
The strategy follows three steps:
- Detect the crossover: Wait until the market price crosses above VWAP.
- Remember the level: When the crossover occurs, save the current VWAP value.
- Wait for a retest: Monitor the market until the price returns to the saved VWAP level, then enter a long trade.
Suppose the price crosses above VWAP when the indicator's value is ₹250.
The strategy saves ₹250 at that moment.
Even if the VWAP subsequently changes to ₹253 or ₹255, the strategy continues comparing the market price against the originally saved ₹250 level.
This is the key advantage of saved values: the strategy remembers what a value was when a particular event occurred, rather than continuously using its latest value.
When Are Saved Values Cleared?
Saved values remain available as the strategy moves between states, but all saved values are cleared whenever the strategy returns to the Start State.
This allows each new run through the strategy's decision-making sequence to begin without carrying over values from an earlier setup.
For example, if the VWAP retest never occurs and the strategy returns to the Start State because of a State Timeout, the previously saved VWAP level is forgotten.
The strategy must detect a new crossover and save a new VWAP value before it can use that value again.
Saved values are also maintained independently for each symbol. A value recorded for one symbol does not affect another symbol's strategy execution. Learn more about Per-Symbol Execution.