AllMarkets Trading

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.

1. Supply daily bars

CSV headers: Date,Open,High,Low,Close; optional Volume. ISO dates YYYY-MM-DD, unique and increasing. Positive prices with up to four decimals, dot decimal and no grouping. No automatic sorting, date repair, rounding or missing-bar filling. Limit: 2 MB and 5,000 rows.

Synthetic CSV example

2. Fix the rule and costs before inspecting results

Hold the requested whole units when the completed fast SMA is greater than the completed slow SMA; otherwise hold cash. The first signal can occur after the slow window is complete. Execute at the next supplied bar open. Equal averages mean cash. Insufficient cash rejects the whole buy and retries while the preceding-close target is long.

100 bp = 1%. The fixed fee and notional commission apply to each filled buy and sell, not rejected orders. Buy price = next open × (1 + impact); sell = next open × (1 − impact). Impact can exceed the bar range because this is a constant adverse-price model, not an order-book fill simulation.

Resume an exported setup

Only the source CSV and validated parameters are loaded. Saved result values are never trusted; the model is recomputed.

Backtest result

Load the synthetic example or your own CSV, then run the test.

Read the result correctly

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