An honest, technical answer to whether ChatGPT or any AI can write a profitable trading strategy: it can write strategy code — often subtly broken — and the correctness of that code is checkable, but profitability is not something any AI, backtest, or human can guarantee. Covers the typical failure modes of LLM-generated Pine Script and MQL, why 'looks profitable in a backtest' is a weak claim, and a sane workflow for using AI assistance. Educational only, not financial advice; trading carries a real risk of loss.
ChatGPT can write a trading strategy — code that compiles, takes entries and exits, and produces a backtest. What it cannot do, and what nothing can honestly promise, is write a provably profitable one. Those are two different claims, and almost every hyped answer to this question blurs them: correctness (does the code do what it says, without repainting, lookahead, or broken risk logic?) is objectively checkable; profitability (will it make money in live markets?) is a prediction about the future that no backtest, human, or model can guarantee.
This distinction is the whole answer, so it is worth sitting with. If a large language model hands you a strategy with a gorgeous equity curve, two independent things could be wrong. The code could be measuring something false — a repainting higher-timeframe input, an unwired stop-loss, an entry that peeks at data unavailable in real time — in which case the backtest is fiction. Or the code could be perfectly correct and the result still be curve fitting: a pattern in past noise that carries no information about the future. AI assistance changes neither failure mode; if anything it amplifies the first, because generated code fails in confident, plausible-looking ways.
So the useful reframing is: use AI where its output is verifiable, and stay skeptical where it is not. The sections below cover what LLMs genuinely do well in this domain, the specific bugs they most often introduce into Pine Script and MQL, and why "the backtest is green" was never the finish line. Nothing here is financial advice, and no strategy — AI-written or otherwise — should be assumed profitable.
Credit first. Modern LLMs are genuinely useful for translating a described idea into scaffold code ("long when the 10 SMA crosses the 30, ATR stop, close on cross-down"), for explaining unfamiliar syntax, for porting logic between platforms, and for boilerplate — inputs, plotting, alert plumbing. For an author who knows what correct output looks like, this is a real speed-up.
The failures are just as consistent. Version drift is the most common: training data is saturated with Pine v4 and v5, so models emit study() instead of indicator(), bare sma() and crossover() instead of the namespaced ta.sma() and ta.crossover() that Pine v6 requires, or mix conventions from several versions in one script. Some of this fails to compile — annoying but visible. The dangerous cases compile fine. Hallucinated functions and parameters appear with plausible names and signatures that never existed. Repainting defaults slip in because the model reproduces the most common pattern on the internet, not the most correct one — request.security() without a bar offset or lookahead handling is the classic. Dead risk inputs are endemic: the script declares a stop-loss input, the settings panel shows it, and no strategy.exit() ever uses it, so the backtest silently runs unprotected. And sycophancy compounds everything: ask "is this strategy good?" and the model that wrote it will usually say yes.
None of this means avoid AI. It means the bottleneck has moved from writing code to verifying it — which is exactly the layer where tooling like ForexCodes' Code Fixer and Strategy Validator operates, because these bug classes are mechanical and detectable.
Here is the single most common serious defect in assistant-generated Pine Script. Asked for "the daily close on an intraday chart," models frequently produce something like this:
// ❌ WRONG — typical AI-generated pattern. Do not use.
// lookahead_on with no bar offset lets historical bars read a daily
// close that had not printed yet in real time. The backtest sees the
// future; live trading will not.
dailyClose = request.security(syminfo.tickerid, "D", close,
lookahead = barmerge.lookahead_on)On historical bars this returns the daily close before the day is finished — information no live trader had at that moment. Every backtest built on it is quietly reading the future, which inflates results in a way that looks like edge and is actually a bug. The strategy then "stops working" the moment it runs live, because the future stops being available.
The correct pattern requests the previous, confirmed daily value with lookahead off:
//@version=6
// Educational only — validate before trading; not financial advice.
indicator("Non-repainting daily close", overlay = true)
// Correct: previous completed daily close, no lookahead.
dailyClose = request.security(syminfo.tickerid, "D", close[1],
lookahead = barmerge.lookahead_off)
plot(dailyClose, "Prev daily close", color = color.orange)The [1] offset asks for the last completed daily bar, and barmerge.lookahead_off ensures historical and realtime bars see the same thing. You give up immediacy — the value is one daily bar old — in exchange for a backtest that measures reality. An LLM will happily produce either version depending on phrasing and luck, and both compile, which is precisely why generated strategy code needs mechanical validation rather than a visual once-over.
Suppose the generated code is flawless: no repainting, no lookahead, risk inputs all wired. Is the strategy now profitable? Nobody knows — and this is not a temporary limitation that a smarter model fixes, it is the structure of the problem.
A backtest is a single realization of history. As Bailey, Borwein, López de Prado, and Zhu showed in "Pseudo-Mathematics and Financial Charlatanism" (2014), searching enough strategy variants guarantees an impressive backtest on pure noise, and the expected best result grows with the number of trials. An LLM conversation is a fast, cheap way to run many trials — every "make it better" iteration is another draw from the noise lottery, with the model as an eager optimizer that never charges you for the attempts. The Deflated Sharpe Ratio and the Probability of Backtest Overfitting framework (Bailey and López de Prado) exist precisely because reported performance must be discounted by search depth, and chat-driven iteration makes search depth explode while feeling like careful refinement.
There is also a subtler issue: the model has no access to the future data-generating process. Markets are adaptive; regimes shift; an effect real in the training data can be arbitraged away or simply end. No amount of reasoning over historical text and prices escapes this. When an AI (or a vendor) asserts a strategy "is profitable," the honest translation is "performed well on the history it was tuned on" — which the previous paragraph explains is weak evidence on its own.
What is fully verifiable is the correctness layer: syntax, repainting, lookahead, unit errors, dead inputs, mirrored short-side logic. That layer is where AI-assisted authors should demand proof, because proof is actually available there.
Putting it together, a workflow that uses LLMs for what they are good at without inheriting their failure modes:
request.security() offsets and lookahead, signals gated on confirmed bars, every declared risk input wired into an actual exit. This is what ForexCodes' Code Fixer and Strategy Validator automate — the checkable layer.The bottom line, stated plainly: ChatGPT can write a trading strategy, and with discipline it can help you write a correct one faster. Neither it nor anyone else can hand you a provably profitable one. This article is educational only, not financial advice; a green backtest is not a forecast, and trading carries a real risk of losing money.
Educational only — not financial advice. Trading involves substantial risk of loss.