Can an AI write a profitable trading strategy? An honest test

Ask a chatbot for a profitable ai trading strategy and you get one in seconds: clean code, a confident explanation, sometimes even an expected win rate. The real question is whether any of it holds up against data. To find out, I gave the same request to three general-purpose AIs and ran what they returned through ProBacktest under identical conditions. Then I did the part most people skip, which is a walk-forward test. This post is more about the method than the verdict, because you can reuse the method on every generated strategy you come across. If you are new to the topic, start with our complete guide to coding ProRealTime indicators and strategies with AI, then come back here.

ai trading strategy — Can an AI write a profitable trading strategy? An honest test

The ask: one prompt, three AIs, identical conditions

I kept the prompt deliberately naive, because that is how most people phrase it:

Write me a profitable trading strategy in ProRealTime ProBuilder code for the DAX on a 1-hour chart. Include a stop loss and a take profit.

I sent it to ChatGPT, Claude and Gemini, each time in a fresh conversation with no follow-up hints. Before testing any ai trading strategy, though, you have to fix the test bench first. So I set the rules before looking at a single result:

  • Same instrument and timeframe for all three (DAX, 1 hour).
  • Same history, with the most recent part set aside and never touched during development.
  • Same spread and same position size of one contract.
  • No changes to the logic, except syntax fixes needed to make the code run.

That last rule matters. If you start “improving” a generated system while you watch its equity curve, you are no longer testing the AI. Instead, you are testing your own ability to fit a curve, and that game is much easier to win.

What came back: ChatGPT trading strategy code and its cousins

All three answers were variations on the most common patterns in trading literature. In other words, the AIs returned what shows up most often in their training data, not what works best on the DAX. The first was a moving average crossover with an RSI filter:

// Strategy A: trend following, as returned by the AI
DEFPARAM CumulateOrders = False

fastMA = ExponentialAverage[20](close)
slowMA = ExponentialAverage[50](close)
myRSI = RSI[14](close)

IF NOT LongOnMarket AND fastMA CROSSES OVER slowMA AND myRSI > 50 THEN
   BUY 1 CONTRACT AT MARKET
ENDIF

IF LongOnMarket AND fastMA CROSSES UNDER slowMA THEN
   SELL AT MARKET
ENDIF

SET STOP pLOSS 40
SET TARGET pPROFIT 80

The second was a short-term mean reversion system. It buys a deep pullback inside an uptrend and exits on the bounce:

// Strategy B: short-term mean reversion, as returned by the AI
DEFPARAM CumulateOrders = False

myRSI = RSI[2](close)
trendMA = Average[200](close)

IF NOT OnMarket AND close > trendMA AND myRSI < 10 THEN
   BUY 1 CONTRACT AT MARKET
ENDIF

IF LongOnMarket AND myRSI > 70 THEN
   SELL AT MARKET
ENDIF

SET STOP pLOSS 25

The third was a channel breakout. It buys above the highest high of the last N bars, with a stop in points and a target at twice the stop. As a result, it belongs to the same family as the first system, with a different trigger.

First observations, before any backtest

  • Every parameter is a textbook default: 2, 14, 20, 50, 200. Nothing about the DAX on one hour justifies those values. They are simply popular.
  • Stops and targets are fixed in points, with no link to volatility. Therefore a 40-point stop means one thing in a quiet summer and something else entirely during a sell-off.
  • None of the three answers mentioned spread, slippage or overnight costs.
  • One answer borrowed syntax from another platform, with functions that look like Pine Script, so it did not compile until I replaced them with ProBuilder equivalents.
  • Each came with a reassuring explanation of why it “should” work. However, none came with evidence.

This is the typical chatgpt trading strategy code experience: it reads well, it is often close to correct, and it contains no specific knowledge of your market. That is not really a criticism of the tools. After all, an ai trading strategy written from a one-line prompt cannot know anything you did not tell it.

Backtest: why the AI trading strategy looks too good

With the parameters as delivered, none of the three systems was impressive. Then I did what the typical user does next and opened the optimizer.

The first system had two moving average lengths, an RSI threshold, a stop and a target to tune, which adds up to thousands of combinations. Unsurprisingly, the best of them produced a smooth equity curve, a high profit factor and a drawdown that looked comfortable. The mean reversion system did the same once the RSI levels and the stop were optimized. This is exactly the report people take a screenshot of and post.

Why it looks good

None of those reports came from a bug. Instead, they looked good for structural reasons:

  • Selection bias. If you test thousands of combinations, the best one is partly luck by construction. The optimizer does not find an edge. It finds the combination that best matched the noise of that particular period.
  • Too many free parameters for too few trades. Five variables tuned on a few hundred trades leave very little room for the result to mean anything.
  • Regime luck. A trend system tested over a strongly trending period will shine. As a result, the choice of dates alone can make a mediocre idea look excellent.
  • Costs left out or underestimated. On an hourly index system, the spread on every round trip eats a real share of the average gain per trade. If you ignore it, a losing system can look profitable.
  • Fixed targets. A 2:1 target-to-stop ratio sounds disciplined, although it only works if the hit rate holds. In practice, optimization quietly tunes the ratio to the hit rate of the past.

In other words, a great in-sample backtest of an ai trading strategy proves that the optimizer works. It says almost nothing about the strategy itself.

Walk-forward: reality

Walk-forward analysis asks a narrower and more honest question. If I had optimized this system on the data available at the time, and then traded it on the next unseen period, what would have happened? ProBacktest has it built in. First, open the optimization window with the wrench icon in the ProBacktest window and define your variables. Then activate the Walk Forward option. You can choose an anchored mode, where every optimization window starts at the same date, or a non-anchored mode, where the window rolls forward.

The platform splits the history into successive in-sample and out-of-sample segments. It optimizes on each in-sample segment, then reports how the best parameters performed on the segment that follows. Consequently, the out-of-sample curve is the only part of the report that resembles live trading.

A manual hold-out you can add to any system

On top of the walk-forward, I like to keep one final period that nothing has ever seen. A date switch in the code does the job. First optimize with testWindow = 1 and freeze the parameters. Then set it to 2 and run the test once. Only once.

// Manual in-sample / out-of-sample switch
DEFPARAM CumulateOrders = False

// 1 = optimise on in-sample only, 2 = run out-of-sample only
testWindow = 1
splitDate = 20240101

IF testWindow = 1 THEN
   allowed = Date < splitDate
ELSE
   allowed = Date >= splitDate
ENDIF

fastMA = ExponentialAverage[20](close)
slowMA = ExponentialAverage[50](close)

IF allowed AND NOT LongOnMarket AND fastMA CROSSES OVER slowMA THEN
   BUY 1 CONTRACT AT MARKET
ENDIF

IF LongOnMarket AND (fastMA CROSSES UNDER slowMA OR NOT allowed) THEN
   SELL AT MARKET
ENDIF

SET STOP pLOSS 40

Note the exit on NOT allowed. Without it, a trade opened just before the split date would carry over into the other window and contaminate it.

What happened to the three systems

The out-of-sample segments told a very different story from the optimized reports. The smooth curves turned into a sequence of good and bad windows with no consistent pattern. Once costs were included, the overall out-of-sample result was a fraction of the in-sample one, or simply negative. In addition, the best parameters moved a lot from one window to the next. That instability is the clearest warning sign: if the optimal moving average jumps from 15 to 45 and back, there is no stable effect for the parameters to capture.

None of this is specific to AI. A human copying the same textbook crossover would get the same result. The difference is in presentation. The AI wrapped a generic idea in confident prose, and then the optimizer wrapped it in a beautiful report. Walk-forward strips away both layers, and that is why every ai trading strategy should go through it before anything else.

What an AI trading strategy assistant is actually good at

After a test like this, it is tempting to conclude that AI is useless for system development. That would be the wrong lesson. The AIs failed at one specific task: inventing an edge from nothing. No tool can do that from a one-line prompt. On the other hand, they were genuinely useful elsewhere:

  • Translating your idea into code. Describe a precise rule (“enter on the first close above yesterday’s high after 10:00, exit at 17:30”) and you get a working draft in seconds.
  • Writing the test harness. The in-sample/out-of-sample switch above is exactly the kind of boilerplate an AI writes well when you ask for it explicitly.
  • Generating variants. Ask for the same logic with an ATR-based stop, a time filter or a short side. That way you test robustness instead of tuning numbers.
  • Explaining and reviewing code. For example, pasting a system from the library and asking what each line does is a fast way to learn ProBuilder.
  • Arguing against itself. Ask it to “list the reasons this strategy would fail out of sample”. The answers are usually more useful than the original pitch.

Keep in mind that general-purpose chatbots still invent functions or borrow syntax from other platforms. Therefore, treat every generated block as a draft that has to compile and that you have to read line by line.

How to evaluate any generated AI trading strategy

Here is the checklist I now apply to every ai trading strategy, whether it comes from a chatbot, a forum post or a paid course. Because the source does not matter, the protocol is the same for all of them.

  1. Read the code before running it. Check the entry and exit conditions, the order types and whether positions can accumulate. If you cannot explain a line, do not trade it.
  2. Lock away an out-of-sample period first. Decide the split date before the first backtest, not after.
  3. Set realistic costs. Enter your broker’s actual spread and fees in ProBacktest. Then compare the average gain per trade with them.
  4. Run the parameters as delivered. If the default version is not at least reasonable, optimization is unlikely to rescue it honestly.
  5. Optimize as few variables as possible. Two is fine, five is a curve-fitting machine. Make sure you keep plenty of trades per optimized parameter.
  6. Look at the neighbourhood, not the peak. A robust system performs similarly when you move a parameter a few steps either way. By contrast, a sharp isolated peak is noise.
  7. Walk-forward it. Judge the out-of-sample segments only, and check that the optimal parameters stay roughly stable between windows.
  8. Run your hold-out period once. If it fails, the honest answer is to drop or rethink the idea, not to re-optimize until it passes.
  9. Forward test in demo. Finally, let it run on a paper account long enough to see several different market phases.

The real answer to the title question

So, can an AI write a profitable trading strategy? It can write a strategy quickly and mostly correctly. However, your testing protocol decides whether it is profitable, not the model. Use AI to move faster through ideas and code, then let walk-forward and untouched data decide what survives. In other words, the AI is a fast junior programmer, and you remain the one who signs off on the risk.

ProRealCode ProRealCode
Loading...