How to Write an EA Strategy Specification Someone Else Could Rebuild

Ask most EA developers for their strategy's rules and they will open the source code. The code is precise, but it is not a specification. It records what the EA does, including every bug, and gives no way to tell a bug from a deliberate choice.

A strategy specification is the written reference the code is built and tested against. It says what the EA is meant to do, precisely enough that someone else could build it from the document alone. When a backtest looks odd, the spec is how you decide whether the code is wrong or the idea is.

This guide covers what a specification needs to contain, how to phrase rules so they can't be read two ways, and how to test the code against the document.

One point up front: the test of a specification is whether two people could build it independently and get the same trades. If they would have to ask you questions first, the answers belong in the document.

Why the code is not enough

A written specification earns its place in a few common situations:

  • Someone else builds or changes the EA. A developer, a colleague or an AI assistant can only build what they are told. Gaps get filled with guesses.
  • The strategy moves between platforms. Porting from MT4 to MT5, or from a Python research backtest to an EA, means rebuilding the logic. Without a spec, there is nothing to check the new version against.
  • You return to it months later. Small decisions, such as why a filter exists or which bar a signal reads, are easy to forget and hard to recover from code.
  • A result needs checking. If the backtest and the rules disagree, the spec says which one is right.

What a strategy specification covers

The sections below are a practical minimum. Each one answers a question a builder would otherwise have to guess.

SectionWhat it pins down
ScopeSymbol, timeframe, the account and execution types it is designed for, and the data used to test it
InputsEvery adjustable setting, with its default, its allowed range and its units
IndicatorsExact definitions: formula, smoothing method, price source, warm-up period
TimingWhen rules are evaluated, which bar they read, and the clock used for any session times
EntriesConditions, order type, entry price, direction, and how many positions can be open
ExitsStop and target calculation, trailing rules, time exits, opposite signals, and which exit wins if several apply
SizingThe sizing model and its settings, and what happens at the broker's volume limits
FiltersSpread, session, news or volatility filters, each with its threshold and units
Edge casesGaps, rejected orders, missing data, positions already open when a signal arrives
Test assumptionsCosts, slippage and modelling mode used when the strategy was tested
VersionA version number and date, changed whenever any rule changes

Step 1: Write rules as conditions on named values

Prose rules leave too much open. Compare two versions of the same entry:

  • Vague: "Buy when RSI is oversold and the trend is up."
  • Specific: "At the close of each H1 bar, using the bar that has just closed: if RSI(14) on closing prices is below 30, and that bar's close is above SMA(200) on closing prices, and no position with this EA's magic number is open on the symbol, send a market buy order."

The specific version answers questions the vague one leaves open: which RSI period, what "oversold" means, what "trend is up" is measured against, which bar, and what happens if a position is already open. Every threshold has a number, every indicator has its parameters, and every condition refers to a named value.

A useful habit is to write each rule as a list of conditions joined only by "and" or "or", with brackets wherever both appear. If a rule can't be written that way, it usually hides a decision that hasn't been made.

Step 2: Define every indicator exactly

The same indicator name can mean different calculations. RSI and ATR, for example, can be smoothed in more than one way, and platforms and libraries don't all use the same method or the same number of warm-up bars. Two correct implementations of "ATR(14)" can disagree for the first few hundred bars and still differ slightly after that.

For each indicator, the spec states:

  1. The formula, or a reference to a standard definition, including the smoothing method.
  2. The price it reads: close, typical price, high and low, and from which bars.
  3. The warm-up period: how many bars must exist before its value is used. Signals during warm-up are ignored.
  4. Any custom indicator's source, by name and version, so the builder uses the same one.

Differences in indicator calculation are one of the main reasons a Python backtest and an MT5 test of the same idea disagree; see why Python and MT5 backtests don't match.

Step 3: Pin down timing and bar indexing

Most rebuild disagreements come from timing, not logic. The spec should answer:

  • When are rules evaluated? On every tick, or once when a new bar opens?
  • Which bar do they read? The bar that has just closed, or the bar still forming? A rule that reads the forming bar behaves differently live and in a bar-based test.
  • When does the order go in? At the first tick of the next bar, or immediately when a condition becomes true mid-bar?
  • Which clock is used? Session times must state whether they are in the broker's server time or a named time zone, and how daylight-saving changes are handled.

Reading a bar's close before that bar has finished is the most common way a rebuilt strategy gets a result it could never have had live; see look-ahead bias in EA backtests.

Step 4: Specify order and exit mechanics

Exits cause more disagreement between implementations than entries, because there are more of them and they interact. State each one with its units and its reference price.

  • Units. Say whether distances are in points, pips or price. On five-digit quotes a pip is ten points, and confusing the two moves every stop by a factor of ten.
  • Reference price. Is the stop measured from the entry price, the signal bar's close or an indicator level? For buys and sells, which side of the spread triggers it?
  • Order of checks. If a stop, a target and a time exit could all apply on the same bar, which one is checked first? In a bar-based test, a bar that touches both the stop and the target needs a stated rule, and the cautious choice is to assume the stop was hit first.
  • Trailing and break-even rules. When they activate, how far they trail, and how often they update: on each tick, or once per bar.
  • Opposite signals. Does a sell signal close an open buy, reverse it, or get ignored?

Restarts, saved state and handling of rejected or failed orders also belong in the spec, as one entry that points to the error-handling design; that design is covered in EA restarts, state recovery and order errors.

Step 5: List the edge cases

Edge cases are where two builders are most likely to choose differently. Write down the intended behaviour for each one, even if the answer is "do nothing":

  1. Price gaps beyond the stop at a weekend or market open.
  2. A new signal while a position from an earlier signal is still open.
  3. A stop distance smaller than the broker's minimum, so the order would be rejected.
  4. Missing bars or a data gap in the middle of an indicator's look-back period.
  5. A spread wider than the strategy's filter at the moment a signal fires.
  6. Too little history on the chart for the indicators to warm up.

Step 6: Keep the spec in a structured form

A document in fixed sections is easier to check, compare and version than free text. A short template, filled in for a hypothetical strategy:

strategy: rsi-pullback-example        # hypothetical example, not a real strategy
spec_version: 1.3
date: 2026-11-04
scope:
  symbol: EURUSD
  timeframe: H1
  designed_for: hedging account, market execution
inputs:
  rsi_period:   {default: 14,  range: [7, 28],    units: bars}
  rsi_entry:    {default: 30,  range: [20, 40],   units: RSI level}
  trend_period: {default: 200, range: [100, 300], units: bars}
  stop_atr:     {default: 2.0, range: [1.0, 3.0], units: x ATR(14)}
indicators:
  rsi: "RSI(rsi_period), closing prices, Wilder smoothing, 3 x period warm-up"
  sma: "simple moving average(trend_period), closing prices"
  atr: "ATR(14), Wilder smoothing"
timing:
  evaluate: once, on the first tick of a new H1 bar
  reads: the bar that has just closed (bar 1)
  clock: broker server time
entry_long: "rsi[1] < rsi_entry AND close[1] > sma[1] AND no open position (this magic)"
exits:
  stop: "entry price - stop_atr x atr[1], set on entry, never widened"
  target: none
  time_exit: "close at the first tick after 48 bars in the trade"
  same_bar_conflict: assume stop first
edge_cases:
  stop_below_broker_minimum: skip the trade and log it
  spread_above_filter: skip the trade and log it
restart_and_errors: see the separate error-handling design document
tested_with: [modelling mode, cost assumptions, data source and date range]

Every value the code uses should appear somewhere in this file, and nothing in the code should depend on a value that isn't in it.

Step 7: Test the code against the spec

A specification is only useful if the code is checked against it. Three checks, from cheapest to most thorough:

  • Hand-worked test vectors. Take a handful of bars, work out by hand what the spec says should happen on each one, and confirm the EA does the same.
  • A reference trade list. Once one implementation is accepted, its trade list on a fixed data set becomes the reference. Any rebuild or port is run on the same data and compared trade by trade.
  • An independent rebuild. For a strategy that matters, a second person builds it from the spec alone. Every place the two versions disagree is either a bug or a gap in the document.

A set of test vectors for the long entry above might look like this:

Bar (server time)RSI of closed barClose vs SMA(200)Open position?Expected action
10:0028.4AboveNoBuy at the first tick of the 11:00 bar
11:0029.1AboveYesNone: a position is already open
14:0031.0AboveNoNone: RSI is not below 30
15:0026.7BelowNoNone: close is below the SMA

Illustrative teaching example: hypothetical values, not from any strategy or account.

The comparison itself, trade list against trade list, is covered with code in reproducible EA backtests, along with how to record which spec version and code version each run used.

Step 8: Change the spec first, then the code

When a rule changes, update the specification, give it a new version number, then change the code to match. Record both versions with every test run. That keeps the document and the code in step, and it means every result can be traced to the exact rules that produced it.

Changing the code first and updating the document "later" is how specifications drift out of date. Once the spec and the code disagree, the spec stops being useful as a reference, because nobody knows which one to trust.

What a specification doesn't do

  • It doesn't make the strategy any good. A clear spec for a strategy with no edge is still a strategy with no edge. It just makes that easier to find out.
  • It doesn't replace testing. It tells you what to test against.
  • It doesn't capture everything about live trading. Execution, costs and slippage still differ between a test and a live account, and the spec can only state what was assumed.

Common specification mistakes

  1. Using the code as the spec. Bugs become rules.
  2. Leaving indicator definitions as names. "ATR(14)" is not enough on its own.
  3. Not stating which bar a rule reads. The most common source of rebuild differences.
  4. Leaving units implicit. Points, pips and price get mixed up.
  5. Leaving exit priority open. Two exits on one bar need a stated order.
  6. Writing "handle errors appropriately". Each case needs a stated behaviour.
  7. Updating the code without updating the document.

Strategy specification checklist

  • Scope stated: symbol, timeframe, account and execution type, test data
  • Every input listed with default, range and units
  • Every indicator defined: formula, smoothing, price source, warm-up
  • Evaluation timing, bar read and clock stated
  • Entries written as conditions on named values
  • Exits stated with units, reference price and order of checks
  • Sizing model and volume-limit behaviour stated
  • Edge cases listed, each with an intended behaviour
  • Test assumptions recorded: costs, slippage, modelling mode
  • Hand-worked test vectors confirmed against the EA
  • Spec version recorded with every test run, and changed before the code

Frequently asked questions

What is a trading strategy specification?

It is a written document that defines a strategy's rules precisely enough to build it without asking the author any questions: the indicators and their exact definitions, when rules are evaluated, how orders and exits work, how positions are sized, and what happens in edge cases. The code is then built and tested against it.

What should I give a developer who is building my EA?

A specification covering scope, inputs, indicator definitions, timing, entries, exits, sizing, filters, edge cases and test assumptions, plus a few hand-worked examples of bars and the action you expect on each. The more of those questions the document answers, the fewer guesses the developer has to make.

Why do two versions of the same EA give different trades?

Usually because something the rules didn't state was decided differently in each version: which bar a signal reads, how an indicator is smoothed, which exit is checked first, or the units of a stop distance. A specification that pins those down, and a trade-by-trade comparison, shows exactly where they diverge.

How detailed does a strategy specification need to be?

Detailed enough that two people building it independently would get the same trades on the same data. If a builder would have to ask a question to write the code, the answer belongs in the spec.

Does a written specification make a strategy more profitable?

No. It makes the strategy's behaviour clear and testable, which helps you find bugs and judge results correctly. Whether the rules have an edge is a separate question that only testing can answer.

Want a second pair of eyes?

Start with our free Sample Stress-Test Report. It walks one anonymized, illustrative strategy through a full stress test, start to finish, so you can see what rigorous validation looks like before you test your own.

Read the Sample Stress-Test Report

Want your own backtest checked? The Strategy Audit + 60-minute call is a paid service at a launch price of £100, credited in full against our build and portfolio offers. You send an MT4/MT5 Strategy Tester report or trade-list CSV; what we can check depends on the files you supply, and walk-forward and parameter sweeps are not included because they need the strategy itself. It is analysis of strategy testing, not investment advice, and does not promise any trading or evaluation outcome. See the Strategy Audit

Disclaimers

CollosoTrading provides educational content and analytical services for retail and professional algorithmic traders. We do not provide regulated investment advice, financial advice, or personal recommendations. Trading derivatives, leveraged products, and CFDs carries a high level of risk and may result in losses exceeding deposits. Past performance, including any verified or unverified historical results referenced on this site, is not indicative of future results. Consult an independent regulated financial adviser before making investment decisions.

All figures are backtests or simulations unless marked LIVE. Hypothetical or backtested performance results have inherent limitations and may not reflect actual trading. No representation is made that any account will or is likely to achieve profits or losses similar to those shown. Individual results vary. Any figures in this article are hypothetical arithmetic for teaching purposes, not results from any strategy or account. We do not guarantee the outcome of any prop firm challenge.