Skip to content
All library documents

Choosing Prices When Moving a Backtest to Live Trading

Article Quant Q&A · Author: PiE

Summary

The document raises a practical execution question when translating a bar-based backtest into simulated or real-time trading through a broker API. Its example generates a signal from a moving-average crossover, shifts the signal to the next bar, sets a limit relative to the prior close, and checks whether the bar’s low would have reached that limit. It then uses the lower of the opening price and limit as the simulated entry price.

The unresolved issue is what “Open” should mean in live operation: the opening price recorded for the bar or the latest traded price from a real-time feed. The text frames these as alternatives but supplies no answer, comparison, or execution evidence. In practice, the choice depends on when the bar opens, when the signal is known, and what order behavior the backtest intends to represent; a last-traded price is not necessarily an executable fill. The example therefore highlights a backtest-to-live consistency problem rather than prescribing a complete solution.

Key ideas

  • The example backtest enters on the bar after a moving-average crossover signal.
  • It models a limit entry using the prior close and checks the following bar’s low.
  • The author asks whether live logic should use the bar open or latest traded price.
  • The document does not resolve the choice or validate either price as an execution assumption.
  • Live fills depend on order timing and execution conditions that a last price alone may not capture.

Tags

Full text
# Backtesting :: Migration to Simulated / Real-Time Trading


# Backtesting :: Migration to Simulated / Real-Time Trading












I am relatively new to backtesting and I want to migrate my system to simulated trading via Amibrokers Interactive Broker's API.

What I have been doing is setting trade delays such that when a Buy or Short signal occurs, the algorithm buy or short on the next Open.

Here is a sample code:

```
**BuySignal = Cross( Close, MA(Close, 100 ) ); 

// buy on the next bar

Buy = Ref( BuySignal, -1);

BuyLimitPrice = Ref( Close, -1) * 0.99;

// now we check if limit was hit

Buy = Buy AND L < BuyLimitPrice;

// if Open price is below the limit, then we use Open for entry

BuyPrice = Min( Open, BuyLimitPrice );**
```

The question is that: When you migrate this to real-time or simulated trading, what price do you use for Open?

This is what I am struggling with - there are two options:

a) Use real-time data for the price of the stock (i.e., GetRTData( "Last" ) ) which is the "last" value that the ticker was traded at, or

b) Use the value of Open of the stock for that bar, which can be obtained by the system.

Which value is the correct or the best one to use (i.e, `a` or `b`)?

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.