How to Backtest a Simple Trading Strategy Using ChatGPT

1 min read Original article ↗

Anup Shinde

We will have a hands-on walkthrough demonstrating how I utilized ChatGPT to backtest a straightforward EMA + ATR strategy, complete with stop-loss, take-profit, slippage, and realistic P&L tracking.

Originally published at anupshinde.com

Press enter or click to view image in full size

Simple strategy using ChatGPT

Pre-requisites and tools:

  1. CSV data file with OHLC data. In this case, it was NQ data downloaded from TradingView, but you could use any source.
  2. ChatGPT-4o. (Or you could try with whatever LLM you have access to.)

Prompts

Next, let’s look into the prompts used. These are presented as is.

Prompt 1

I attached the CSV file with stock OHLCV columns, and started the conversation like this:

“Read the file and show me whats inside”

Press enter or click to view image in full size

ChatGPT reading the CSV file

Prompt 2

Explaining the simple strategy so that ChatGPT can code it.

Add a 9 period EMA to this.
Add 9 period ATR
When the price closes above 9 EMA, take a long.
When the price closes below 9 EMA, take a short.
Stoploss =…