Skip to content

Automation

Strategy development: turning a trading idea into testable rules

A strategy is a hypothesis about market behaviour, expressed as rules precise enough for a computer to follow and for someone else to reproduce. Good development is mostly about removing ambiguity and deciding in advance what would prove the idea wrong.

Key points

  • Start from a reason the pattern might exist, not from a search through thousands of parameter combinations.
  • Every rule needs a data source, timeframe, calculation and threshold.
  • Exits and position sizing shape results as much as entries do.
  • Decide your rejection criteria before you look at test results.

Start with a hypothesis

A useful hypothesis names a behaviour and a reason. For example: 'After a strong trending day in an index, the next session tends to continue in the same direction in the first hour, because institutional orders are often executed over several sessions.' The reason may turn out to be wrong, but it guides which tests matter and stops you from accepting any random pattern that happens to look good.

Ideas often come from technical analysis, market structure, or observed behaviour around events. Whatever the source, write down which market, which instruments, which timeframe and which session you are studying.

Write unambiguous rules

Each rule should be answerable with yes or no from data available at that moment. 'Price is in an uptrend' is not a rule. 'The closing price of the last completed 15-minute candle is above the 50-period exponential moving average of closes' is a rule.

Rule checklist
ElementQuestions to answer
UniverseWhich instruments, and how are they chosen without hindsight?
DataWhich candles: traded prices or transformed candles such as Heikin-Ashi? Which session times?
EntryExact condition, evaluated on a closed bar or intrabar? Order type: market or limit?
ExitStop, target, trailing rule, time exit, and what happens at session end?
SizingRisk per trade, maximum quantity, how lot sizes are rounded?
FiltersDays or times excluded, maximum trades per day, daily loss limit?

Exits and sizing deserve equal attention

Two strategies with identical entries can produce very different outcomes because of their exits. A tight stop-loss cuts losses quickly but may be hit by normal noise; a wide one survives noise but loses more per failure. A trailing stop lets winners run but gives back part of each move.

Expectancy per trade
Expectancy = (win rate × average win) − (loss rate × average loss)

Measured in rupees or in R (multiples of the initial risk). It must stay positive after costs to be meaningful.

Position size converts a per-trade risk budget into a quantity. The position sizing guide and the position size calculator show the arithmetic.

Choose parameters carefully

Most strategies have parameters: moving-average lengths, ATR multiples, thresholds. Every parameter you tune on historical data increases the risk of overfitting, where the rules describe past noise rather than a durable effect.

  • Prefer few parameters with sensible, round values.
  • Check that nearby values give broadly similar results; a sharp peak is a warning sign.
  • Keep some data untouched for a final out-of-sample check.
  • Record every variation you tried, not just the best one.

Decide what would reject the idea

Before testing, write down the evidence that would make you abandon or revise the strategy: for example, negative expectancy after costs, a maximum drawdown larger than you could tolerate, or results that depend on a handful of trades. Pre-commitment protects against the very human habit of moving the goalposts after seeing results.

Then test in stages: historical backtesting, walk-forward analysis, and forward paper trading. Each stage exposes problems the previous one could not.

Document and version every change

Treat a strategy like software. Give each version a number, record what changed and why, and keep the results of every version. When a live or paper result disappoints, you need to know exactly which rules produced it. AlgoStok's five Trend Dominator versions are documented this way on the strategies page.

A worked example of tightening a rule

Suppose the starting idea is 'buy strong stocks on dips'. Each word needs a definition. 'Strong' might become 'closing price above its 200-day moving average and within 10% of its 52-week high'. 'Dip' might become 'three consecutive lower closes on the daily chart'. 'Buy' needs an order type and timing: 'a limit order at the next session's open price plus a small buffer, cancelled if unfilled within the first 30 minutes'.

Then the exit: 'a stop at 1.5 times the 14-day ATR below entry, a time exit after ten sessions, and an exit at the close if the price closes below the 50-day average'. Finally sizing: 'risk 0.5% of equity per trade, at most five open positions, no new entries after a 3% monthly drawdown'. The numbers here are illustrative, not suggestions; the point is that every one of them is now testable.

Writing the rule this way usually exposes hidden choices. Does 'within 10% of the high' use the closing high or the intraday high? Are stocks with corporate actions handled? What happens when two signals arrive on the same day and only one position slot remains? Answering these before testing prevents results that depend on accidental implementation details.

Frequently asked questions

How many rules should a strategy have?

As few as needed to describe the idea completely. Every extra rule or parameter is another opportunity to fit historical noise.

Should I optimise parameters for the best backtest result?

Optimising for the single best result usually overfits. Look for a broad region of reasonable values and confirm on data that was not used for tuning.