A backtesting engine that never trades on a price it has seen

Veloce replays one-minute market history bar by bar. Strategies decide on closed candles, orders fill at the next candle’s open, and every fill pays slippage and itemised Indian charges. This page explains each of those rules and where it lives in the engine.

An algo trading harness around your strategy

In software, a test harness runs your code against controlled inputs and records what it does. Veloce does the same for a trading strategy: the strategy plugs in, and the harness supplies the market data, contracts, fills, costs, exits, risk limits, portfolio and report, the same way on every run.

  • Market data

    One-minute bars, checked as they arrive and resampled to your candle.

  • Expiries and contracts

    Expiry calendars with holidays, and strikes picked from the closed candle.

  • Fills

    Every order fills at the next bar’s open, never on a price already seen.

  • Costs

    Brokerage, STT or CTT, exchange and SEBI fees, stamp duty, GST and slippage.

  • Exits

    Stops, targets, trails and exits before expiry, checked on every bar.

  • Risk limits

    Lot caps, cash, futures margin, loss at expiry and daily limits.

  • Portfolio

    Positions in units, cash, cost basis and equity, in exact decimals.

  • Reports and runs

    Calendar, equity, breakdowns and trades, with every run stored.

Plugs in

Your strategy

Reads closed candles and returns the position it wants, in signed lots. It never places an order or touches cash.

  • A shipped strategy
  • Your own indicator rules
  • A strategy spec, written as data

Backtests today. Paper and live trading are coming soon.

The harness: everything around the strategy is supplied by Veloce, the same way on every run.

Five steps, in the same order, on every bar

The engine merges the bars of every instrument in the backtest into one timeline ordered by start time. For each moment it runs the same sequence.
  1. 1

    Bars for one moment

    The engine takes every bar that starts at the same moment: the underlying and each contract the strategy has picked so far.

    BacktestEngine

  2. 2

    Broker fills first

    Options past expiry settle. Orders waiting on a contract fill at its bar’s open, with slippage and charges, and the portfolio updates.

    SimulatedBroker.on_bar

  3. 3

    Strategy decides

    Only then does the strategy see the closed bars. It returns target positions in signed lots, never orders.

    Strategy.on_bar

  4. 4

    Stages review

    Exit-by time, daily target and stop, skipped days, exit rules and risk limits each adjust the targets in turn.

    TargetStage

  5. 5

    Orders wait

    The difference between each target and what is already ordered becomes an order, which waits for the next bar.

    OrderExecutor.submit

One pass of the replay loop. Orders sent in step 5 fill in step 2 of the next moment, at that bar’s open.

Instruments join as the strategy picks them

A backtest starts with the underlying alone: NIFTY 50, BANK NIFTY, SENSEX, or the gold future being traded. An option strategy then picks contracts as it goes, through the option chain: the at-the-money strike from the closed candle’s price, a set number of strikes away, on the nearest expiry. The engine adds each new contract to the replay from that bar on.

Before a contract can be ordered it needs a price for the risk checks. The engine looks back over the last hour, or one candle if that is longer, and takes the close of the last bar that had closed. If the contract did not trade in that window, the backtest stops and says so, instead of inventing a price.

Strategies return positions, not orders

A strategy says what it wants to hold: minus one lot of the 24000 put, plus one lot of the 23800 put. It never says buy or sell. Stages then review those targets against an account snapshot that already counts orders still waiting to fill, and the engine sends only the difference between the reviewed target and what is ordered.

The portfolio keeps positions in units, lots times the lot size at the time of the fill, so an exchange revising a lot size cannot change a position that is already open.

Decide on the close, fill at the next open

The default fill price is the open of the contract’s next candle. It is the first price anyone could have traded at after the strategy made up its mind.

GOLDM future, one-minute candles

DecisionFill price

When a backtest order fillsOne-minute candles from 10:08 to 10:18. The strategy sees the 10:14 candle only when it closes at 10:15:00, decides then, and its order fills at the open of the candle that starts at 10:15. Candles after the decision are still unknown to it.10:0810:0910:1010:1110:1210:1310:1410:1510:1610:1710:1810:15:00, the 10:14 candle closesStrategy decides on its close, ₹1,21,611Order fills at this open, ₹1,21,617then slippage and charges applyNot yet known to the strategy
  1. The candle closesA candle labelled 10:14 covers 10:14:00 to 10:15:00. Its close is known only at 10:15:00, so that is when the strategy sees it.
  2. Targets go through reviewExit rules and risk limits adjust the strategy’s targets against the account, and only the difference becomes an order.
  3. The next candle fills itThe simulated broker fills at the open of the contract’s next candle, the first price after the decision, before the strategy sees that candle.

Illustrative prices.

Slippage, in ticks

Fills then move against you by the number of ticks you set, one by default. A buy pays more and a sell receives less. The result is rounded to the contract’s tick, up for buys and down for sells, and a sell never fills below one tick.

A tick is ₹0.05 on NIFTY, BANK NIFTY and SENSEX options and ₹1 on gold futures. Set slippage to zero to see what the strategy would make with perfect fills, then compare.

How one tick of slippage moves a fill
OrderNext openSlippageFill
Buy NIFTY call₹120.00+₹0.05₹120.05
Sell NIFTY call₹150.00−₹0.05₹149.95
Sell a ₹0.05 option₹0.05−₹0.05₹0.05
Buy GOLDM future₹1,21,450+₹1₹1,21,451

Six rules that keep the future out of the past

Lookahead bias is any way a backtest lets a decision use information that was not available when it was made. These are the rules the engine enforces.
  1. Rule 1

    Bars are labelled by their open

    Every bar carries the time it starts. The strategy sees it at start plus interval, the moment it closes, and not before.

  2. Rule 2

    The broker sees each moment first

    All bars that start at the same moment go to the simulated broker before any reaches the strategy, so pending orders fill on prices the strategy has not seen.

  3. Rule 3

    Contracts are priced from closed bars

    When a strategy picks a contract mid-run, its first price is the close of its last bar that had already closed, looking back at least an hour.

  4. Rule 4

    Only the difference is ordered

    The engine compares each target with what is already ordered and sends the difference. Targets that change nothing send nothing.

  5. Rule 5

    Data is checked as it arrives

    A bar out of order, at the wrong interval or outside the requested range stops the backtest with an error instead of being used.

  6. Rule 6

    Signals stop before the closing auction

    Since 3 August 2026, NIFTY index bars go flat from 15:15 and jump to the official close. Index-option signals ignore bars that close after 15:15.

The glossary defines lookahead bias and the other terms on this page, and the blog works through them with examples.

Larger candles, built from one-minute bars

Data arrives as one-minute bars. Any candle that is a whole number of minutes, up to a day, is built from them, aligned to the session open.

Candles line up with the session: 09:15 for NSE and BSE, 09:00 for MCX. A 15-minute NIFTY candle covers 09:15 to 09:30, then 09:30 to 09:45, the way a trading terminal draws them. A one-hour candle covers 09:15 to 10:15.

The app offers 1, 3, 5, 15 and 30 minutes and 1 hour. Each strategy has a default: 1 minute for the iron condor and the hedged straddle, 3 minutes for the moving average and MACD buyers, 5 minutes for the rest.

How a resampled candle is built
FieldTaken from
StartThe session open plus whole intervals
OpenThe first one-minute bar
High and lowThe highest high and lowest low of all of them
CloseThe last one-minute bar
VolumeThe sum
Resampling one-minute bars into a five-minute candleFive one-minute bars from 09:15 to 09:19 combine into one five-minute candle that starts at 09:15: open 24180.50 from the first bar, high 24209.60, low 24171.00, close 24207.40 from the last bar. It closes at 09:20.09:1509:1609:1709:1809:1909:15, 5 minH 24209.60C 24207.40O 24180.50L 24171.00
The 09:15 five-minute candle takes its open from the 09:15 bar, its high and low from all five, and its close from the 09:19 bar. It closes at 09:20, and nothing can act on it before then. Illustrative prices.

Itemised charges on every fill

Each fill pays a schedule of charges built from small parts: a fixed amount per order, a rate on turnover for one side or both, and GST on some of the others. Turnover is the fill price times the units.

NSE and BSE index options

Charges on NSE and BSE index options
ChargeRateOn
Brokerage₹20 per orderEvery order
Exchange transaction charge0.03503% of premium turnoverBuys and sells
SEBI turnover fee0.0001% of turnover (₹10 a crore)Buys and sells
Securities transaction tax (STT)0.15% of premium turnoverSells only
Stamp duty0.003% of turnoverBuys only
GST18% of brokerage, exchange and SEBI chargesEvery order

Turnover is premium times units. STT defaults to 0.15% and can be changed per backtest.

MCX gold futures

Charges on MCX gold futures
ChargeRateOn
Brokerage₹20 per orderEvery order
Exchange transaction charge0.0021% of turnoverBuys and sells
SEBI turnover fee0.0001% of turnover (₹10 a crore)Buys and sells
Commodity transaction tax (CTT)0.01% of turnoverSells only
Stamp duty0.002% of turnoverBuys only
GST18% of brokerage, exchange and SEBI chargesEvery order

Turnover is the futures price times units, so a GOLDM lot at ₹1,21,450 is ₹12,14,500.

Buy NIFTY 24200 CE

1 lot of 65, filled at the next open

Buy
Next candle’s open
₹120.00
One tick of slippage
+₹0.05
Fill price
₹120.05
Turnover
₹7,803.25
Charges on this fill
BrokeragePer order₹20.00
Exchange charge0.03503%₹2.73
SEBI fee0.0001%₹0.01
STTSells only₹0.00
Stamp duty0.003%₹0.23
GST18% of the first three₹4.09
Charges on this fill₹27.07

Sell NIFTY 24200 CE

1 lot of 65, filled at the next open

Sell
Next candle’s open
₹150.00
One tick of slippage
−₹0.05
Fill price
₹149.95
Turnover
₹9,746.75
Charges on this fill
BrokeragePer order₹20.00
Exchange charge0.03503%₹3.41
SEBI fee0.0001%₹0.01
STT0.15%₹14.62
Stamp dutyBuys only₹0.00
GST18% of the first three₹4.22
Charges on this fill₹42.26

What the two fills cost

Bought at ₹120.05 and sold at ₹149.95, the round trip makes ₹1,943.50 gross. Charges take ₹69.33, and the two ticks of slippage already took ₹6.50 against the opens. Net: ₹1,874.17.

Rows are rounded to the paisa. Veloce keeps every amount exact, so a column of rounded rows can differ from the total by a paisa.

What each charge is, in the glossary

Options held to expiry settle in cash

Index options are European and cash-settled. Veloce settles any still open at their intrinsic value against the underlying’s close on expiry day.

At the close of the derivatives session on expiry day, 15:30, or 15:40 for expiries from 3 August 2026, each open option closes at its intrinsic value: for a call, the index close minus the strike, and for a put, the strike minus the close, never below zero. Orders still waiting on an expired contract are dropped.

Settlement fills carry no charges in Veloce. In practice, exercised in-the-money options pay STT on their intrinsic value, so a strategy that holds to expiry will look slightly better than it would have done. No shipped option strategy holds to expiry by default: the iron condor and the credit spread exit a day before, and the rest square off at 15:15 each day.

Expiry dates come from a calendar per underlying, with holidays moved to the previous trading day. The NIFTY and BANK NIFTY page shows the calendar, including the move from Thursday to Tuesday expiries.

Common backtest shortcuts, and what Veloce does instead

Each of these shortcuts makes a backtest look better than trading would have been.
Backtest shortcuts compared with Veloce
ShortcutVeloceWhy it matters
Fill at the close of the signal candleFill at the open of the next candle, after the decisionThe close is the price that produced the signal. No order placed after seeing it could have traded there.
Label candles by their close time and act at onceLabel candles by their open and act only after start plus intervalA candle stamped 09:15 covers 09:15 to 09:20. Acting on it at 09:15 reads five minutes of the future.
Trade the index price for an options strategyTrade the option contract, priced from its own one-minute barsAn index cannot be ordered. Option premiums move with time and volatility as well as spot.
Ignore charges, or take a flat percentageItemise brokerage, STT or CTT, exchange and SEBI fees, stamp duty and GST on each fillCharges differ by side and product. STT is on option sells only; stamp duty is on buys only.
Assume fills at the quoted priceMove every fill against you by the ticks of slippage you set, one by defaultReal orders cross a spread and move the market. Even one tick is a cost on every fill.
Use floating-point numbers for moneyUse exact decimals for every price and amount, and reject floatsFloats round 0.1 + 0.2 to 0.30000000000000004. Over thousands of fills the errors add up.

Where the bars come from

Market data comes from Dhan’s historical APIs: one-minute bars for the indices, the option contracts and the gold futures, and daily bars for the trading calendar.

Option data arrives one trading day at a time and covers strikes around the money, up to ten either side on the nearest expiry and three on later ones. Each finished day is cached, so a second backtest over the same period downloads nothing.

The trading calendar is the days the index has a daily bar. That is how Veloce knows a day was a holiday, and why it refuses expiry dates beyond the last day it has data for rather than guessing.

Every price and amount is an exact decimal, and every timestamp carries its time zone. The engine rejects floating-point prices and times without a zone outright.

Backtest with fills you can trust

Create an account with a verified email and phone number, pick a strategy and a market, and see every fill, fee and day of P&L.

Create account
esc
↑↓Move↵Open