Core conceptBeginner

Trading Rules

Trading rules are the fully specified, unambiguous logic (entry, exit, position sizing, timing and edge-case handling) that a backtest engine executes deterministically to turn a strategy idea into simulated trades.

Quick answer: Trading rules are the fully specified, unambiguous logic (entry, exit, position sizing, timing and edge-case handling) that a backtest engine executes deterministically to turn a strategy idea into simulated trades.

In simple words

Trading rules are your idea written so precisely that a computer can follow it with no judgement calls. They state exactly when to enter, how much to buy, when to exit, and crucially at which price and moment each order fills. Vague words like strong or oversold have no meaning to an engine, so every condition must become a concrete, testable statement.

Purpose

This page explains how a strategy idea is translated into deterministic rules a backtest can execute, and why the timing of those rules is where most silent errors enter.

Professional explanation

Entry, exit and the full state machine

A complete rule set is effectively a state machine: it defines the conditions to open a position, the conditions to close it, and what happens in every intermediate state. Entries specify direction, trigger and price; exits specify profit targets, stop losses, time-based exits and trailing logic. Crucially the rules must resolve conflicts deterministically, such as what happens when an entry and exit signal coincide, or when a stop and target could both be hit within one bar. Any state the rules leave undefined becomes an implicit assumption the engine will resolve for you, often not the way you intended.

Position sizing is part of the rules

How much to trade is as consequential as when to trade, yet it is frequently left implicit. Sizing can be fixed quantity, fixed rupee value, volatility-scaled, or a fraction of equity, and each produces a materially different equity curve and drawdown profile from identical entry and exit signals. A strategy with a genuine directional edge can still be ruined by sizing that risks too much per trade. Because sizing interacts with compounding, two backtests of the same signals with different sizing rules are effectively two different strategies.

Timing and the next-bar rule

The most error-prone part of rule specification is timing. If a signal is computed from a bar's close, the order must be assumed to execute at the next available price, typically the next bar's open, never at the same close that produced the signal. Acting on the signal bar's own close is look-ahead bias, because in real time that close is only known once the bar has finished and the opportunity has passed. Every rule must answer precisely: at what moment is the decision made, and at what later moment and price is it filled.

Parameters, thresholds and their danger

Rules usually contain parameters: lookback lengths, threshold levels, stop distances. Each parameter is a degree of freedom that can be tuned, and every additional one increases the risk of overfitting to the tested history. Robust rule sets favour few parameters, values that make economic sense rather than ones discovered by exhaustive search, and thresholds that perform across a plateau of nearby values rather than at a single fragile point. A rule that only works at exactly one parameter setting has been fitted to noise.

Order types and execution assumptions embedded in rules

The rules must specify how orders reach the market: market, limit or stop, and what is assumed when a limit is not filled or a stop gaps through its level. A limit-order rule that assumes every limit fills ignores the reality that limits at good prices often go unfilled, which quietly overstates the edge. Conversely a market-order rule must account for slippage. The choice of order type is not an execution detail bolted on afterwards; it is part of the strategy definition and changes the achievable result.

Determinism, edge cases and reproducibility

For a backtest to be trustworthy, the rules must be fully deterministic: the same data must always produce the same trades. This means specifying behaviour for every edge case, such as insufficient capital, a gap through a stop, a trading halt, expiry, or a corporate action mid-position. Undefined edge cases are where subtle bugs and accidental hindsight hide. Writing rules as explicit, ordered conditions, and logging every decision, is what makes a backtest auditable rather than a black box.

Practical example

Illustrative example (Indian market)

Consider a simple Nifty futures rule on Rs 5,00,000: go long one lot when the 20-day close crosses above the 50-day, exit when it crosses back below, no pyramiding. To make it executable you must add the missing decisions. The cross is detected on the daily close, so the order fills at the next day's open, not the signal close. One lot is 75 units, so with Nifty near 25,000 a lot is about Rs 18.75 lakh notional against Rs 5,00,000 margin, which fixes the leverage. You add Rs 20 brokerage and one tick of slippage per side. Only with the timing, sizing, order type and costs pinned down does the rule set become a real, reproducible backtest rather than a sketch.

On NSE, an intraday rule must also encode the square-off requirement and the fact that a stop can gap through its level on the open after overnight news, filling far worse than the stop price. Rules that assume the stop always fills exactly at its level understate real losses.

Advantages

  • Forces a vague idea into complete, testable logic
  • Makes the strategy reproducible and auditable trade by trade
  • Exposes hidden assumptions about timing, sizing and fills
  • Enables systematic testing of robustness across parameters

Limitations

  • Every parameter added is a degree of freedom that invites overfitting
  • Discretionary judgement cannot be captured without inserting hindsight
  • Undefined edge cases become implicit assumptions the engine resolves silently
  • Rules encode assumed fills that real liquidity may not honour

Why it matters in practice

  • The precision of the rules determines whether the backtest is honest
  • Timing errors in the rules are the leading cause of look-ahead bias

Common mistakes

  • Acting on the signal bar's own close instead of the next available price
  • Leaving position sizing implicit, so the equity curve is an accident
  • Assuming every limit order fills at the desired price
  • Adding parameters until the in-sample curve is perfect
  • Not defining what happens when a stop and target could both hit in one bar
  • Ignoring gaps, halts and expiries that occur while a position is open

Professional usage

Professional systematisers write rules as explicit, ordered logic with every edge case defined and every decision logged, then keep the parameter count deliberately low. They separate signal generation from execution assumptions so each can be stressed independently, force all fills to the next available price, and treat position sizing as a first-class part of the strategy rather than an afterthought. The aim is a rule set another researcher could read and reproduce exactly.

Key takeaways

  • Trading rules are the strategy idea written precisely enough for a machine to execute
  • Timing is the most error-prone part: act on the next available price, never the signal close
  • Position sizing and order type are part of the rules, not afterthoughts
  • Every parameter is a degree of freedom that raises overfitting risk

Frequently asked questions

What are trading rules in a backtest?
Trading rules are the fully specified logic a backtest executes: the conditions to enter, the conditions to exit, how much to trade, and exactly when and at what price orders fill. They must be precise enough that a machine can execute them deterministically with no human judgement.
Why must rules be completely unambiguous?
Because a backtest engine cannot interpret vague terms like strong or oversold, and any state you leave undefined becomes an implicit assumption the engine resolves for you, often incorrectly. Unambiguous rules make the result reproducible and prevent hidden hindsight from creeping in.
Is position sizing part of the trading rules?
Yes, and it is as consequential as the entry and exit. Fixed-quantity, fixed-value, volatility-scaled and fraction-of-equity sizing produce materially different equity curves and drawdowns from identical signals, so two backtests of the same signals with different sizing are effectively different strategies.
What is the next-bar rule?
The next-bar rule states that a signal computed from a bar's close must be executed at the next available price, typically the next bar's open, never at the same close. Acting on the signal bar's own close is look-ahead bias, because that close is only known once the opportunity has passed.
How many parameters should a strategy have?
As few as possible. Every parameter is a degree of freedom that can be tuned to fit noise, so fewer parameters with economically sensible values generalise better. A rule set that works only at one exact parameter setting has been fitted to the tested history.
How do order types affect the backtest?
They change what fills are assumed. A rule using limit orders that assumes every limit fills overstates the edge, because good-priced limits often go unfilled, while market-order rules must include slippage. The order type is part of the strategy definition, not a detail added afterwards.
What happens if a stop and target could both hit in one bar?
The rules must resolve it deterministically, because from OHLCV data alone you cannot know which was reached first. A conservative convention assumes the worse outcome, and leaving this undefined lets the engine silently pick, which can flatter the result.
Can I backtest a discretionary rule?
Only the parts that can be made explicit. Any component that relies on human judgement cannot be simulated faithfully, and attempting to encode it usually means inserting hindsight where the discretion was, which biases the backtest toward looking better than it could have been.
Why is timing the most dangerous part of rules?
Because a small timing error, such as using the signal bar's close as the fill price, injects look-ahead bias that can turn a losing strategy into a winning one. Every rule must state precisely when the decision is made and at what later moment and price it is filled.
How do sizing rules interact with drawdown?
Sizing directly scales risk, so a strategy with a genuine edge can still suffer catastrophic drawdowns if it risks too much per trade. Because sizing interacts with compounding, the same signals can look smooth or violently volatile depending purely on the sizing rule chosen.
What edge cases should trading rules define?
At minimum: insufficient capital, a gap through a stop, a trading halt, expiry, coincident entry and exit signals, and corporate actions mid-position. Undefined edge cases are where subtle bugs and accidental hindsight hide, so specifying each keeps the backtest deterministic and auditable.
Do trading rules include the cost model?
Effectively yes, because the fill assumptions and order types the rules specify determine the frictions applied. A rule that assumes ideal fills with no slippage encodes an unrealistic cost model, so honest rules pair each order with a realistic brokerage, STT and slippage assumption.
How do I keep rules reproducible?
Write them as explicit ordered conditions, define every edge case, version the code and parameters, and log each decision so the same data always yields the same trades. Reproducibility lets another researcher read the rules and recreate the exact result.

Voice search & related questions

Natural-language questions people ask about Trading Rules.

What are trading rules in simple terms?
They are your strategy written so exactly that a computer can follow it, spelling out when to buy, how much, when to sell, and at what price each order fills.
Why can't I just say buy when it looks strong?
Because a computer cannot judge strong. Every condition has to become a concrete number or comparison it can test, or the backtest cannot run honestly.
When should my backtest fill an order?
At the next available price after the signal, usually the next bar's open. Filling at the same close that made the signal is cheating with hindsight.
Is how much I trade part of the rules?
Yes, and it is huge. The same buy and sell signals can look calm or wild depending only on how much you size each trade.
How many settings should a strategy have?
As few as you can. Every extra setting is something you can tune to fit the past, which makes the strategy more likely to fail on new data.
What if my stop and target could both hit in one bar?
You have to decide the rule in advance, usually assuming the worse one filled first, because the daily bar cannot tell you which came first.

Sources & references

    Last reviewed 11 July 2026. Educational content only — not investment advice. Markets and rules change; verify current conventions with SEBI, NSE/BSE and your broker.

    Educational content only — not investment advice. Examples use illustrative numbers and simplified models. Backtested results are hypothetical and trading derivatives involves substantial risk. See our Risk Disclosure and SEBI Disclaimer.