Skip to content

Guides · · 6 min

Can You Automate a Discretionary Trading Strategy?

Which parts of a discretionary strategy translate into an EA or Pine Script, how to define judgement calls objectively, and how to test the result honestly.

Black toy robot over a printed candlestick chart with a pencil and ruler, illustrating automating a trading strategy

Yes, you can automate a trading strategy that started out as discretionary, but usually only part of it. Session times, ATR-based stops and fixed R targets translate cleanly into an EA or Pine Script. Judgement calls such as "a decisive candle" have to be turned into measurable rules first, and the backtest only tests your definition, not the original trader's eye.

The short version

  • Mechanical parts (times, levels, stops, targets, position size) are easy to code.
  • Visual judgement has to be rewritten as numbers, such as candle body and wick ratios, before it can be tested.
  • Every definition you choose is a parameter, and more parameters mean more risk of curve fitting.
  • Backtests overstate results when fills, slippage and look-ahead bias are ignored, so forward test before trusting one.

Which parts of a discretionary strategy can you code?

Automating usually means one of two things: an Expert Advisor (EA) written in MQL that trades inside MetaTrader, or a Pine Script indicator or strategy on TradingView that draws signals, runs a backtest and sends alerts. Either way, the code can only follow rules it can measure, as our guide to how automated trading works explains.

Start by writing the strategy down and sorting each rule by how objective it already is:

Rule elementCodes cleanly?How it is usually coded
Session window, e.g. 9:30–11:00 a.m. ETYesTime filter in the exchange's time zone, allowing for daylight saving changes
Reference price at a set timeYesStore the last price before the chosen time
ATR-based stop sizeYesATR thresholds mapped to stop, target and size
Fixed R targetYesBracket order placed at entry
"Decisive" or displacement candleOnly once definedBody, wick and range ratios
Break of structurePartlyClose beyond a swing point defined by a pivot rule
"The move looks exhausted"HardA proxy, such as distance travelled plus a structure break
Skipping a day on instinctRarelyEconomic calendar filter, or left as a manual override

How do you turn judgement calls into rules?

The aim is a definition two people would apply in the same way to the same chart. For a "decisive" candle, an objective version might be:

  1. The candle closes in the direction of the trade.
  2. Its body is at least a set share of its full range, for example 70%.
  3. The wick against the trade direction is small, for example no more than 15% of the range.
  4. Its range is larger than the average of the previous few candles, for example 1.5 times the last ten.

Those numbers are illustrations, not tested values. The point is that each threshold becomes a setting you could change, and each one you add gives the backtest more room to fit past noise. Keep the count low, choose values before looking at results, and check that nearby values (65% or 75% instead of 70%) give similar outcomes. If performance collapses when a threshold moves slightly, the rule is probably fitted to history.

Structure rules need the same care. A swing high is often defined as a high with a set number of lower highs on each side, but that means the swing is only confirmed several bars after it forms. Code that treats it as known at the moment it printed is using information the trader did not have.

Worked example: rebuilding the JJ Simons NQ strategy

The JJ Simons strategy for Nasdaq-100 futures (NQ and MNQ) is a good test case because it mixes mechanical and visual rules. It marks the price just before the 9:30 a.m. ET cash open as "fair value", trades 9:30–11:00 a.m. ET on the 1-minute chart, and has two setups from that line: continuation of the opening push, and reversion back towards fair value once the push fades.

The mechanical parts code directly. Stops scale with ATR: above 20, a 50-point stop with one NQ contract; between 7 and 20, 25 points with two; below 7, 16.5 points with three. Each target is about 1.5R, with no partial exits. Even here, the rebuild has to choose an ATR length and timeframe, which the description leaves open.

The visual parts needed definitions. Entries require a displacement candle plus a break of structure for continuation, or a market structure break for reversion, and both had to be expressed as rules like those above. Trade Edge Alpha, which is not affiliated with JJ Simons, rebuilt the rules as a TradingView indicator and strategy; its full rules and results are set out in the JJ Simon strategy backtest. Over 365 days it reported a profit factor of 1.94, 56.7% profitable trades and a 2.38% maximum drawdown. Those figures are hypothetical: one instrument, one year and one interpretation of the rules, and fills, fees and slippage would change them.

The numbers are at least internally consistent. At a fixed 1.5R target, a 56.7% win rate implies a profit factor of about 1.96 before costs (0.567 × 1.5 ÷ 0.433), close to the reported figure. Checking that win rate, R multiple and profit factor agree is a quick sanity check on any backtest. Continuation and reversion trades should also be tracked separately, as one can carry the other.

Backtesting pitfalls when you automate a trading strategy

A backtest is only as honest as its assumptions. The common problems are:

  • Curve fitting. Optimising thresholds until the equity curve looks smooth. The more settings you tune, the less the result tells you.
  • Fill assumptions. A limit order touched by price is not always filled. If a stop and a target both sit inside one bar, the tester has to guess which came first.
  • Slippage and costs. Entries in the first minutes after an open often fill worse than the chart price. Add realistic commission and slippage per trade.
  • Look-ahead bias. Using a bar's close, a confirmed swing or higher-timeframe data before it was actually available.
  • Short samples. One year on one market may cover a single volatility regime.

Our guide to backtesting an EA in the MT4 Strategy Tester walks through the settings that matter, such as modelling quality and spread.

Forward testing, and what the robot archive shows

Forward testing means running the finished code on data it has never seen, ideally live on a demo account and then at small size. MT5 strategy testing help describes a forward mode that holds back part of the period, so settings optimised on the first part are checked on the rest. Compare win rate, average win and loss, and drawdown with the backtest. A large gap usually points to a coding error, an unrealistic fill model or a fitted rule.

The robot archive on this site is a reminder of why. Of the 230 robots rated in our forex robot reviews, the average score was 4.35 out of 10. Only 5 scored 8 or more, 42 scored 6 or more, and 125 scored below 4.5. Automation removes hesitation and enforces rules, but it does not create an edge that the rules lacked. Our analysis of whether forex robots work goes into the patterns behind those scores.

Limitations

An automated version of a discretionary strategy is a new strategy built on your interpretation. It may behave differently from the original trader's results, and it needs monitoring for platform outages, data errors and changes in market conditions. Leveraged products such as futures and CFDs can lose money quickly.

FAQ

Can you automate a trading strategy without coding?

Partly. Visual strategy builders and alert-based tools reduce the coding, but you still need fully objective rules, and you still need to check how the tool models fills and costs.

Is Pine Script or MQL better for automation?

Pine Script is convenient for charting, backtesting and alerts on TradingView, while MQL runs EAs directly inside MetaTrader with a broker that supports it. The better choice depends on where your broker's execution happens.

How long should you forward test an automated strategy?

There is no fixed period, but you need enough trades to compare with the backtest, which for a strategy that trades once or twice a day usually means months rather than weeks.

Will an automated strategy match its backtest?

Rarely. Live results tend to be weaker because of slippage, missed fills and conditions the test period did not cover, so treat the backtest as a best case.

More guides

All →