equitiesswing-tradingintermediate

A fluent answer is still an unchecked test

ChatGPT can help backtest a trading strategy by writing the code and questioning your rules. You still supply clean data and check for look-ahead bias yourself. The real risk is a result that reads well and was never run at all.

Can ChatGPT backtest a trading strategy?

Partly: ChatGPT can turn written rules into code, and some versions can run it on a data file you upload. What it can't do is promise the data is right, or that the code never peeks at the future.

The biggest trap is asking for results without code. A chat model can describe a plausible win rate and equity curve in plain text. If no code ran on real data, those numbers came from nowhere.

So treat it as a fast junior programmer. It writes quickly and makes confident mistakes. You stay responsible for the data going in and for checking what comes out.

Expect it to forget your rules between chats unless you paste them in again. Save the rule sheet and the exact prompt you used. Then the next run tests the same strategy, and you can compare the two honestly.

The rest of this piece covers what to hand over, then how to check what comes back.

What a chat model does well: code and rule-checking

Hand it the translation work. Describe the rules in plain words and ask for Python or Pine Script. It'll produce something runnable faster than you could type it.

It's also good at finding holes. Ask it what your rules leave undefined. A decent answer raises questions like these. What happens if the stop and target are both hit inside the same bar? Do you enter at the signal bar's close or the next bar's open? What if price gaps past your stop overnight?

Those questions are worth more than the code. Each one changes the result, and a vague rule sheet hides all of them.

Keep the prompt specific. Give the timeframe, the symbol list, the cost per trade and the exact entry and exit conditions. Ask for a list of individual trades as well as the summary.

What it can't do: vouch for the data

A test is only as good as the price history under it. The model has no reliable way to know if yours is clean.

Check for missing bars, duplicated bars and odd spikes from bad prints. Check whether prices are adjusted for splits. An unadjusted split looks like a crash, and a short strategy will look brilliant on it. For holds of weeks or months, check whether dividends are in the prices too.

Then ask what's missing entirely. A list of today's index members leaves out companies that were dropped or went bust. Testing only the survivors tends to make long strategies look better than they were.

Time zones do their damage in silence. If the file is in UTC and your rules say 10:00, the code may trade the wrong hour every day. None of this shows up in a neat summary table. Look at the raw file yourself before any code touches it.

Look-ahead bias hides in a single line

Look-ahead bias means the code uses information that didn't exist yet when the trade was taken. It's a classic way for a test to print money it could never have made.

The textbook version: the signal uses today's close, but the trade enters at today's open. On paper you bought before the information arrived. In pandas code, the fix is often a missing shift by one bar.

Another version uses a daily high or low to decide an intraday entry. You only know the day's high once the day is over.

A subtler version sits in the exit logic. When stop and target both fall inside one bar, the code may assume the target filled first. Rerun it assuming the stop filled first, and see how much the result drops.

A model can write this bug and then fail to spot it, because the code runs without errors. Ask it directly where look-ahead could creep in. Then check those lines yourself, since a wrong answer sounds exactly like a right one.

Make it show its work, then check five trades by hand

Never accept a result you can't trace to code and data. Ask for the code, run it yourself, and have it print every trade with timestamps.

Pick five trades at random from that list. Open each one on a chart and find the bar where the signal fired. Was the condition really true using only data up to that bar? Did the entry price exist at that moment?

Then move the main setting a notch either side. If the result collapses when 20 becomes 18 or 22, the test is fitted to noise.

Finally, add costs. Ask for a version with commission and a tick or two of slippage per side. A strategy that only works at zero cost won't work in an account. Once it passes all of this, trade it small and compare. Keep the code and the data file together in a dated folder. That way you can rerun the exact test months later.

Checking a chatbot-made test, step by step

Run through all ten before you trust a single number.

  • Confirm the result came from code that actually ran.
  • Get the full trade list with timestamps.
  • Check the data for missing, duplicated or spiked bars.
  • Confirm prices are adjusted for splits.
  • Ask whether dropped and delisted symbols were included.
  • Check the data's time zone against your rules.
  • Find every line that uses a close, high or low and confirm its timing.
  • Hand-check five random trades on a chart.
  • Shift the main setting both ways and rerun.
  • Rerun with commission and slippage included.

Frequently asked questions

It can write the code and, in some versions, run it on a file you upload. It can't vouch for the data or reliably catch look-ahead bias, so check the code and five trades yourself.

It means applying fixed rules to past price data to see how they would have done. The result only counts if the rules used no future information and the costs are realistic.

Use a chart's bar replay to step through old price one candle at a time. Trade a written rule sheet by hand, and log at least 50 trades with costs subtracted.

Measure the live version in TraderLog

A simulated result is a forecast, and your fills are the outcome. Import them from Schwab, IBKR or a CSV. The stats page shows win rate, profit factor, expectancy and max drawdown on what really happened. Start a 14-day trial with no card.

Every trading morning at 8:40 ET our model draws the SPY, QQQ and IWM zones it expects to matter, on a TradingView chart, before the open. Where price reaches one, it has turned 74 percent of the time. Free, no account. See today's map