SMA backtest lab: close signals, next-bar open fills
Trace a fixed long-only moving-average rule on your daily OHLC CSV. Record the signal, execution price, commission, cash and marked equity without sending data to a server.
Educational historical simulation of one cash-funded, share-like instrument. No strategy optimization, forecast or profitability claim. No shorting, leverage, Forex margin, futures multipliers, options, dividends, corporate actions, taxes or liquidity model. Supply consistently adjusted prices yourself.
Backtest result
Load the synthetic example or your own CSV, then run the test.
Read the result correctly
- There is no forced final liquidation. Ending equity = cash + open units × last close. Open-position value and unrealized profit include entry costs but exclude hypothetical exit costs. Closed-trade profit includes both entry and exit commissions.
- The buy-and-hold reference attempts the same whole-unit purchase at the first eligible strategy execution bar, using identical buy costs, then holds through the same final close. It is not fully invested, has no terminal sale, and can reject its single purchase for insufficient cash.
- Maximum drawdown uses closing equity and an initial peak equal to starting cash. It is not intraday or order-level maximum drawdown. Win rate includes break-even trades in the count; profit factor is unavailable when there are no losing closed trades.
- The latest close target may require an order, but there is no next bar in the file to fill it. The report shows that pending state.
- Execution prices round half up to four decimals; order notionals, commissions and close marks round half up to cents. This is our convention, not a claim to match a listed provider’s rounding.
- All supplied rows are validated. Gaps in dates are allowed as next available bars; trading calendars and omitted history are not externally verified. At least slow-window +2 rows are required.
- Print shows the summary, curve and first 20 orders/closed trades. CSV exports contain the complete records and assumptions. Setup JSON includes your source data; handle it as your own financial file.
Why this model delays fills
A closing-price rule uses information only known after that bar is complete. Filling at an earlier point on that same bar without an explicit valid execution convention introduces look-ahead. This model uses the next supplied bar’s opening price instead. No future rows affect earlier signals or orders.
TradingView Pine strategy concepts · Backtrader quickstart · Backtrader slippage
Read the bias and cost checklist · Compare full-featured backtesting platforms