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?
Why must rules be completely unambiguous?
Is position sizing part of the trading rules?
What is the next-bar rule?
How many parameters should a strategy have?
How do order types affect the backtest?
What happens if a stop and target could both hit in one bar?
Can I backtest a discretionary rule?
Why is timing the most dangerous part of rules?
How do sizing rules interact with drawdown?
What edge cases should trading rules define?
Do trading rules include the cost model?
How do I keep rules reproducible?
Voice search & related questions
Natural-language questions people ask about Trading Rules.
What are trading rules in simple terms?
Why can't I just say buy when it looks strong?
When should my backtest fill an order?
Is how much I trade part of the rules?
How many settings should a strategy have?
What if my stop and target could both hit in one bar?
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.