A backtest is a sequence of claims about prices you could have got. Every one of those claims is an order-type decision in disguise. Choose a market order and you have claimed a fill at an unknown price; choose a limit and you have claimed a price but not a fill. Most retail systems never make the choice explicitly — they inherit whatever the first tutorial used, then measure the strategy as though execution were free and instantaneous. This page covers the four order types available on NSE and BSE, exactly which assumption each one forces your backtest to make, why the signal-bar close is a price the live market never promised you, and how to measure your own execution against a benchmark instead of by feel.
Why is order type a strategy parameter and not a UI choice?
In a discretionary account the order type is a convenience. In a systematic account it is a term in the model.
The reason is that a rule is only meaningful if it produces the same trade every time. 'Buy on a close above the range high' does not specify a trade. Buy it with a market order at the next open and you have one strategy. Buy it with a limit at the range high and you have a different strategy — one that sometimes does nothing at all, and one whose historical record is not the same set of trades.
So the order type has to be written into the rulebook alongside the entry condition, and the backtest has to simulate that order type honestly, including the days it would not have filled. A backtest that quietly assumes every signal became a position is testing a strategy nobody can trade.
Note — Educational content, not advice, and not a recommendation of any order type, broker or platform. Order-handling behaviour — what a broker converts, what it rejects, what it does at the pre-open and in the closing session — differs between brokers and is changed by exchange circular. Verify the specifics against the exchange documentation and your broker's own API docs before you rely on any of it.
What are the four order types, and what does each refuse to promise?
- Market
- Fill me now at whatever the book has. You give up all price control and receive, in exchange, near-certainty of execution in a liquid instrument. The fill price is unknown until it exists — which means a strategy using market orders cannot claim a price in its backtest, only a fill.
- Limit
- Fill me at this price or better, otherwise wait. You keep price control and give up certainty of execution. The order rests in the book and may never trade. A strategy using limits must model the trades it did not get, because those non-fills change its entire trade set — usually removing exactly the fast moves it most wanted.
- Stop-loss limit (SL)
- When the market reaches my trigger, place a limit order at my limit price. Two prices, two failure modes. In the fast move a stop is for, the market can trip the trigger and travel straight past the limit, leaving you triggered, unfilled and still in the position you were trying to exit.
- Stop-loss market (SL-M)
- When the market reaches my trigger, place a market order. It removes the unfilled-stop problem and accepts the consequence: in a gap or a fast move, the fill can be far from the trigger. The trigger is the level at which you decided you were wrong. It has never been a promise about the price you would exit at.
Watch out — The most common and most expensive misunderstanding in this list: a trigger is not a fill. Neither an SL nor an SL-M is resting in the order book before its trigger is hit, so neither one protects you against anything that happens overnight or in a gap. Position size is the only defence against a gap, and that belongs to the risk topic, not this one.
How does the choice between market and limit change the strategy itself?
The row that decides most cases is the last-but-one. A limit order is a filter you did not intend to add. It systematically declines the trades that ran away from your level, and those are not a random sample — for a breakout rule they are frequently the ones the whole strategy exists to catch.
The mirror-image problem for market orders is that they never decline anything. On a thin morning, in an illiquid strike, a market order is an instruction to pay whatever is being asked. If you cannot say what the worst acceptable price is, you have not finished writing the rule.
| Market order | Limit order | |
|---|---|---|
| What you control | Nothing about price | The worst price you will accept |
| What you are promised | Execution, in a liquid book | Nothing |
| The cost you pay | The spread, immediately, plus impact if you are large | Adverse selection — you fill most easily when you least want to |
| What the backtest must model | An unknown fill price, so a slippage allowance is mandatory | The non-fills, so the trade set itself changes |
| The trade it loses | None — but it may take bad ones at bad prices | The fast moves. The days price never came back to your level are usually the days it kept going |
| Best suited to | Rules where being in the trade matters more than the entry tick | Rules with a defined level where a worse price genuinely invalidates the idea |
What is the backtest-to-live gap?
Here is the claim buried inside almost every retail backtest: 'the signal fired on this candle's close, so I was filled at this candle's close.'
Read that sentence back. The candle's close is, by definition, the last print of that interval. At the instant it exists, the interval is over. Your program has not yet seen the bar, has not evaluated the rule, has not sent anything, and the exchange has not received anything. The closing price is a historical fact the moment it becomes available to you.
Which fill assumptions are honest, and which are not?
The point is not that a backtest must be pessimistic. It is that every assumption should be one a live order could have satisfied.
| Assumption | Honest? | Why |
|---|---|---|
| Signal on the bar close, fill on that same close | No | The close is only known once the bar has ended. You cannot act inside a moment that has already passed. |
| Signal on the bar close, fill at the next bar's open | Broadly yes | The conservative default for bar-based systems, and the one most live implementations can genuinely achieve. |
| Fill at the mid-price | No | Nobody trades at the mid. A buy lifts the offer and a sell hits the bid; the mid is an average of two prices you cannot have. |
| Limit order filled because the bar's low touched your price | No | A touch is not a trade for you. It says somebody traded there, not that your position in the queue was reached. |
| Filled the full quantity in one print | Depends on size | Fine for a small order in a liquid name; a fiction once your quantity exceeds the depth at the touch. |
| Stop exited exactly at the stop price | No | SL-M fills at whatever is available after the trigger; SL may not fill at all. Both are worse than the assumption. |
Example — Illustrative, with invented round numbers on no instrument and no date. A rule signals on a close at ₹500. The backtest books ₹500. Live, the next open is ₹501, the offer is ₹501.10, and a large order fills across ₹501.10 to ₹501.45. The backtest recorded an entry ₹1.30 better than the one the market provided. Repeat that across a few thousand round trips and the gap is no longer a rounding difference — it is the entire question of whether the strategy is worth running.
Why can a limit order at the right price still trade nothing?
Because an order book is a queue, not a pool. Orders at one price are filled in the sequence they arrived, so being at the correct price is necessary and nowhere near sufficient. Everyone who got there before you has to be filled first.
What does queue position mean for a systematic strategy?
- A limit order placed after a level becomes obvious joins the back of a queue that formed while you were still deciding. Latency is not only a speed problem; it is a queue-position problem.
- Amending an order usually costs you your place. A strategy that nudges its limit price on every tick is repeatedly sending itself to the back.
- The queue is why 'my price traded' and 'I traded' are different statements. Only your own fill confirmations prove the second.
- The shorter your holding period, the larger the share of your result that queue position decides. Below a few minutes it can dominate the signal entirely.
- For most retail systematic traders the practical conclusion is not to compete on queue position but to choose holding periods where it does not decide the outcome.
How should a system handle partial fills?
A partial fill is the normal case, not the exception, once order size approaches the depth available. It breaks two things that beginner systems assume are safe.
First, position tracking. Your position is the running sum of fills, never the sum of orders you sent. A cancelled order that was part-done still left you holding the part. Second, risk. If your entry filled 40% and your stop order was sized for 100%, you are now carrying a stop for a position you do not have — and the reverse mistake, sizing the stop off the intended quantity when the entry was partial, is how a system ends up accidentally short.
- 1
Track fills, not orders
Maintain position from execution messages only. Never infer it from the orders you believe you placed.
- 2
Size the exit off the actual filled quantity
Re-derive the protective order from the position as it stands after each fill, not from the quantity you intended.
- 3
Decide in advance what a partial entry means
Do you top up, hold the partial, or cancel and stand aside? All three are valid; improvising between them at 09:20 is not.
- 4
Give the remainder a deadline
An unfilled remainder still consumes margin and still carries risk if it fills later on unrelated news. Cancel it on a written rule, not on remembering.
- 5
Reconcile against the broker at least once per session
Your internal position and the broker's position must agree. When they disagree the broker's is correct, and your reaction to that is a system design decision you should have already made.
What are iceberg and disclosed-quantity orders for?
A disclosed-quantity or iceberg order shows only a slice of your total to the market, replenishing it as each slice is consumed. It exists because a large visible order is information — it tells everyone else what you intend to do before you have done it, and the price frequently moves away in response.
The cost is exactly what the previous section described: each replenished slice rejoins the queue at the back rather than keeping the original order's priority. You are trading time priority for invisibility. That is often the right trade for a genuinely large order and usually pointless for a small one, and the exact permitted mechanics — minimum disclosed quantity, how many legs, which segments — are set by exchange and broker rules that you must read rather than assume.
Note — Whether slicing helps is a measurable question, not a matter of taste. Run the order both ways over a large number of executions and compare each against a benchmark. One order tells you nothing; a few hundred tell you whether the slicing is paying for the priority it costs.
When is crossing the spread worth it?
Crossing the spread means paying the offer rather than bidding for it. It is an immediate, certain cost, and traders instinctively avoid certain costs in favour of uncertain ones — which is often the wrong instinct.
The question is a comparison, not a preference. What does the spread cost you against what a missed trade costs you? If your rule captures a move many times the spread and the trades it misses are the largest ones, crossing is cheap. If your rule captures a move comparable to the spread, then crossing is the strategy, and there is nothing left over.
- Measure the spread in your actual universe at your actual trading times before deciding. In liquid NSE large caps at midday it is one thing; in a far strike at 09:16 it is another entirely.
- Compare the spread to the average gross move the rule targets. If they are the same order of magnitude, the rule is not viable at that frequency regardless of order type.
- The open and the close carry wider spreads and thinner books. A rule that fires there is paying more for the same execution.
- A hybrid — post a limit, then convert to market after a written timeout — is a real strategy, but it is a strategy with its own parameter that must be tested, not a free improvement.
- Circuit limits and pre-open sessions change what is possible at the extremes. Read the exchange's session rules rather than discovering them live.
How do you measure execution quality instead of guessing at it?
Execution quality is not an opinion about whether a fill felt good. It is the distance between your fill and a benchmark that was defined before the order was sent, recorded on every order, and read as a distribution across hundreds of them.
What benchmarks should a systematic trader record?
- Decision price
- The price at the moment your rule fired. The gap between this and the arrival price is your own latency — the time your system spent between seeing the data and getting an order out. It is the only component entirely within your control.
- Arrival price
- The prevailing price when the order reached the market. Measuring your average fill against arrival gives implementation shortfall: the total cost of turning a decision into a position. This is the benchmark that matters most for a strategy taking discrete signals.
- Interval VWAP
- The volume-weighted average price over the window your order worked in. Useful when an order is deliberately spread over time, because it asks the fairer question — did you do better or worse than the average participant during that window.
- Fill ratio
- For limit-based strategies, the share of signals that became positions at all. A falling fill ratio is a signal about the market's behaviour, not just about your plumbing, and it changes the strategy's trade set without changing a line of code.
How do you build the measurement?
- 1
Timestamp four moments on every order
When the rule fired, when the order was sent, when the exchange acknowledged it, and when each fill arrived. Without all four you cannot separate latency from spread from impact, and each has a different remedy.
- 2
Snapshot the book at decision and at arrival
Store the bid, the offer and the last price at both moments. Reconstructing them later from candle data is guesswork, and the whole exercise is about not guessing.
- 3
Compute the shortfall per order, in basis points
Absolute rupee figures are not comparable across instruments or price levels. Normalise so a ₹200 stock and a ₹3,000 stock can sit in the same distribution.
- 4
Read the distribution, never the average alone
The mean hides the tail, and the tail is where execution damage lives. Look at the worst decile and ask what those orders had in common — size, time of day, instrument, or volatility.
- 5
Slice by the variables you can change
By hour, by instrument, by order type, by order size. This is how a measurement becomes a decision instead of a dashboard.
- 6
Feed the measured number back into the backtest
Replace the assumed slippage allowance with the one you actually measured, then re-run. This closes the loop between the model and reality, and it is the step almost nobody performs.
What invalidates your execution assumptions?
The conditions that retire an execution model. Any one of them means re-measuring before you trust the backtest again.
- Measured shortfall drifts consistently wider than the allowance in the backtest. Consistently, in one direction — not one bad week.
- Fill ratio on limit orders falls. Your live trade set is diverging from the historical one, so the historical record no longer describes what you are running.
- Order size grew relative to the book. The same order type in the same instrument is a different order once your quantity exceeds the visible depth.
- You added instruments further down the liquidity curve. An assumption calibrated on liquid large caps says nothing about a far-dated illiquid strike.
- The strategy moved its firing time towards the open or the close. Spreads and depth at the session edges are not the ones your midday measurement described.
- A broker, platform or exchange change altered order handling, throttles or session rules. Any of these can silently change what your order type does.
- The instrument hit a circuit limit or entered a special session. What your order can do there is set by exchange rules, not by your code's expectations.
What should the rulebook say about execution?
The execution section of the rulebook
- The order type for entry, for exit and for the protective stop is named explicitly — not left to whatever the API defaults to.
- For limit orders, the rule for what happens when the order does not fill is written down, including the deadline for cancelling it.
- The backtest's fill assumption is stated in one sentence, and it is one a live order could actually have satisfied.
- Position is derived from fills only, and the protective order is re-derived after every partial.
- Four timestamps and two book snapshots are captured on every order, and stored.
- A benchmark — arrival price at minimum — is computed per order in basis points and reviewed as a distribution.
- A written threshold exists at which measured execution cost triggers a review of the strategy, not just a note in a log.
- Broker and exchange order-handling rules relevant to your order types have been read from the source, and the date you read them is recorded.
Key points
Pro tip — Before adding a single feature to a strategy, take one week of its live orders and compute the average shortfall against arrival price in basis points, split by hour of the day. Most retail systems discover their execution cost is concentrated in the first fifteen minutes of the session — and simply refusing to fire in that window is a bigger, cheaper improvement than any parameter change was going to be.
Frequently asked questions
Should an algo use market orders or limit orders?
It depends on what the rule is trying to capture, and the choice changes the strategy rather than merely implementing it. Market orders guarantee execution and give up price, so they suit rules where being in the trade matters more than the entry tick. Limit orders guarantee price and give up execution, so they suit rules with a defined level where a worse price genuinely invalidates the idea — but they systematically decline the fast moves, which for a breakout rule is often the trades it exists to take.
What is the difference between SL and SL-M orders?
Both wait for a trigger price. An SL then places a limit order, so in a fast move it can trigger and never fill, leaving you still holding the position you were trying to exit. An SL-M places a market order, so it fills once triggered but at whatever price is available, which in a gap can be far from the trigger. Neither is resting in the order book before the trigger, so neither protects against an overnight gap.
Why does my live trading differ from my backtest?
The most common single cause is the fill assumption. A backtest that books a fill at the signal bar's close is claiming a price that only exists once the bar has already ended, before your program has seen it or sent anything. Live, the earliest realistic fill is on the next bar, after crossing the spread. Add queue position on limit orders, partial fills on larger quantities, and impact from your own size, and the gap is structural rather than a bug.
What is implementation shortfall?
It is the difference between the price prevailing when your order arrived at the market and the average price you actually filled at, usually expressed in basis points so orders in different instruments can be compared. It captures the whole cost of turning a decision into a position — spread and impact together — and is the most useful single execution benchmark for a strategy that takes discrete signals.
What is queue position and why does it matter?
Orders resting at the same price are filled in the sequence they arrived, so your place in that queue decides whether you trade at all when only part of the level executes. It matters most for short holding periods, where it can decide more of the outcome than the signal does, and it is why amending a resting order — which usually forfeits your place — is more expensive than it looks.
How do I handle partial fills in an algo?
Track position from fill confirmations only, never from the orders you sent, and re-derive the protective stop from the actual filled quantity after every partial. Decide in the rulebook whether an unfilled remainder is topped up, held or cancelled, give it a written deadline, and reconcile your internal position against the broker's at least once per session — when they disagree, the broker's is the correct one.
Does using an iceberg or disclosed-quantity order reduce cost?
It reduces information leakage by showing only a slice of a large order, at the cost of time priority, since each replenished slice rejoins the back of the queue. Whether that trade is worth it is measurable rather than a matter of taste — run the order both ways across a few hundred executions and compare each against arrival price. The permitted mechanics are set by exchange and broker rules and should be read from those sources.