Skip to content
ForexBob

Automated trading8 min read

How to turn your trading strategy into an EA

Turn a trading idea into exact EA rules, test it properly and hire a developer with confidence: the specification, the testing and the red flags.

By Sukhwinder Singh

To convert a trading strategy to an EA, you turn each trading decision into a rule that MetaTrader can test without asking you what you meant. A human can sense that momentum looks strong, but a computer needs a number, a time and a condition it can check on every candle. If you can write those rules on one page, a developer can build, test and fix the EA from them.

Convert a trading strategy to an EA in five stages

The work moves in five stages:

  1. You write the rules in plain words.
  2. You turn those words into exact conditions, numbers and limits.
  3. A developer codes the EA from that specification.
  4. You test it in the Strategy Tester and on a demo account.
  5. You decide whether to trade it live, revise it or drop it.

This order matters because testing cannot fix a vague idea. If the entry rule is unclear, the backtest will test one version of your idea while you imagine another.

Five stages from trading idea to EA: write the rules, make them exact, code the EA, test it, then go live, revise or drop it.

Write rules a computer can follow

An EA needs a complete answer to six questions on every candle: what opens a trade, what closes it, where the stop loss sits, how large the position is, what filters can block a trade, and which sessions are allowed. If any answer is missing, the developer must guess, and different developers will guess differently.

Start with the entry. Name the chart, the pair, the indicator and the exact trigger. For example, a long entry might require the 50-period moving average to be above the 200-period moving average, the 14-period RSI to close above 50, and price to close above the previous candle's high. That is testable. A rule that says to buy when the trend looks strong is not, because two traders will read the same chart in different ways.

Then define the exit with the same care. A trade can close at a stop loss, a take profit, a trailing stop, an indicator signal or a time limit. State which rule has priority if two signals appear at once.

Vague rules versus exact rules

Small words cause most problems. Words such as strong, soon, near, a little and usually work in conversation, but they do not work in code. Each one hides a decision that the EA must make for you, so replace each one with a number or a condition.

  • Vague: buy when EUR/USD breaks out after a pullback, with a sensible stop.
  • Exact: on the one-hour EUR/USD chart, buy when price closes above the high of the last 20 candles after closing below the 20-period moving average at least once in the previous five candles, with the stop 15 pips below the lowest low of the last five candles.

The second version can be coded and tested. The first cannot.

A vague trading rule that can't be coded next to the exact version of the same breakout rule that an EA can follow.

Risk needs the same treatment. An exact rule says to risk 1% of the account balance per trade, calculated from the stop distance. On a $10,000 account, 1% risk is $100. If the stop is 50 pips on EUR/USD and you trade 0.20 lots, the pip value is $2, because 1.00 lot is $10 per pip and 0.20 × $10 = $2. The risk is 50 × $2 = $100. With a 25-pip stop, the same $100 risk allows 0.40 lots, because 0.40 × $10 = $4 per pip and 25 × $4 = $100. A position size calculator runs this maths for other pairs, but the principle stays the same: risk first, size second.

Filters also need numbers. State any news rule, such as no new trades 30 minutes before and after high-impact news, and name the indicator, period and comparison for any trend filter.

Your EA specification checklist

A useful specification fits on a few pages and leaves no major decision open. Send it to a developer as the document for pricing, and keep it as the record of what version one was meant to do. Later changes are easier when you note the date, the changed rule and the reason.

  • Strategy name, chart timeframe, pairs and the MetaTrader version, MT4 or MT5
  • Entry rules for long and short trades, including indicators, periods and the confirming candle
  • Exit rules, including stop loss, take profit, trailing stop, time exit and priority
  • Position sizing rule, including risk per trade and maximum risk across open trades
  • Filters, including trend, volatility, spread, news and session rules, with numbers
  • Trade management rules, including maximum open trades and behaviour after a loss
  • Order handling, including pending or market orders, slippage and spread limits, and behaviour after a restart
  • What the EA must not do, such as trading during named events or opening a second trade in the same direction

If a rule is still uncertain, mark it as a question rather than leaving it blank. An open question is easier to resolve than a hidden assumption found during testing. If you are still choosing a platform, read MT4 vs MT5 first.

What to expect in testing

Testing has two parts, and both are needed. The Strategy Tester shows how the coded rules would have behaved on past data, and a demo account shows how they behave with live prices, spreads and order fills. Our guide to how to backtest a trading idea explains the steps, including how to avoid testing one idea so many times that the result fits the past by chance.

Expect the first test to reveal mistakes in the specification. A common result is that the EA trades far more often than you expected, because a signal you saw once a week appears on every qualifying candle. Another is that the stop is hit more often than planned, because the stop distance in pips does not match the distance you used in manual trading. Change the specification, record the change and test again.

Do not judge an EA from a short test alone. A few weeks of good demo results can reflect a market phase that suited the strategy rather than a lasting edge. Look at the number of trades, the largest losing run and the largest drawdown. Our guide on how to judge an Expert Advisor sets out the same checks.

Questions a good developer will ask

A careful developer will ask questions that protect you from a vague build. Expect questions about the timeframe, the exact indicator settings, what happens when a signal repeats, how the EA should behave after a losing trade, and what maximum drawdown would make you stop using it. These questions are a good sign, because they show the developer is trying to code your intent, not just produce a file that runs.

Expect questions about risk and limits too, including maximum risk per trade, maximum open trades, spread limit and session limits. Decide any unknown answer together before coding starts.

Red flags when hiring a developer

Be cautious if a developer promises a result, asks for only a one-line idea, refuses to explain the code in plain terms or will not provide a test report. Be cautious too if the price is agreed before the specification is written. A clear agreement should state what will be delivered, how many revisions are included, how testing will be reported and who owns the source code.

Common mistakes

  • Writing the entry in detail but leaving the exit, stop and position size vague.
  • Using words such as strong, soon, near or usually instead of numbers and conditions.
  • Testing on one pair and one short period, then assuming the result applies everywhere.
  • Changing several rules at once after a poor test, so you cannot tell which change helped.
  • Adding a larger size after a loss without writing that rule into the specification.
  • Judging an EA from a demo run alone, without a backtest and a drawdown review.
  • Hiring from a short message instead of a written specification, then disputing what was agreed.

FAQ

Can I create an EA without coding?

Yes. You can create an EA without coding by writing a clear specification and asking a developer to code it for you. Your job is to define the rules, risk limits and testing criteria in exact terms.

How long does it take to turn a strategy into an EA?

A simple EA with one entry, one exit and fixed risk rules can often be coded and first tested within days, once the specification is complete. A more complex EA with filters, session rules and trade management takes longer, and testing usually takes more time than coding.

Should I test on MT4 or MT5?

Use the platform you plan to trade on, because MT4 and MT5 handle some order and testing details differently. The right choice depends on your account, your indicators and the features you need.

What should I do if the backtest looks good but the demo result is poor?

First, check whether the rules, timeframe, pair, spread and risk settings match between the two tests. Then check the number of trades and the market phase. If the settings match and the gap remains, the strategy may suit one market phase better than another.

Do I need to keep the source code?

Yes. Keep the source code, the specification and the test reports together. The source code lets another developer fix a bug or add a rule you approve later. Without it, you may have to pay for a full rebuild, even for a small change.

If you have a strategy written in plain words and want help turning it into a coded, tested EA, read our EA development page for how the process works, then contact us with your specification or your questions. A clear first draft, even with a few open questions marked, is enough to start a useful discussion.

Keep reading: custom EA development, how to backtest a trading idea and how to judge an Expert Advisor.

Risk note: trading forex carries a high level of risk and may not be suitable for everyone. This article is for education only and is not financial advice.

Have a strategy you want automated?

We turn trading rules into tested Expert Advisors for MT4 and MT5. Tell us how you trade and we'll send a specification and a quote.