Crypto news

29.07.2026
11:01

AI backtesting: how to test a trading strategy using Claude and TradingView

Modern trading is increasingly integrating with artificial intelligence, and one of the most practical examples is the combination of the Claude AI model and the TradingView platform for strategy backtesting. This method allows you to evaluate the potential profitability of an approach on historical data before risking real capital.

From Idea to Code: How the Scheme Works

The process begins with finding a trading idea. Ready-made strategies can be found in the public TradingView library, which offers thousands of free Pine Script scripts, or on GitHub, where repositories with ready-made code are located. However, the key innovation is the ability to turn your own verbal idea into working code using Claude. The trader describes their concept in natural language, and the AI translates it into clear rules and then generates a Pine Script script.

It is important to set realistic parameters: a 0.1% commission per trade, a starting capital of $100,000, as well as the correct position size and opening a trade on the next candle. This makes the results as close to real trading as possible. The finished code just needs to be pasted into the Pine Editor on TradingView, and the test can be run.

Result Analysis: Three Key Indicators

After running the backtest, the trader receives a trade history. Errors on the first run are common; a screenshot of them can be sent to Claude, which will suggest a fix. When evaluating the result, I highlight three main parameters: net profit, percentage of profitable trades, and maximum drawdown. Additionally, it is worth looking at the profit factor (above one means the strategy is profitable) and the total number of trades to ensure a sufficient sample size.

The real value of the method, in my opinion, lies in the deep analysis through Claude. The trader exports the trade history from TradingView to CSV, uploads the file to the AI bot, and asks questions: why the strategy performed poorly, which market conditions caused the largest losses, and how to reduce drawdown without overfitting the model. Most traders miss this step, but they shouldn't—this is where the main benefit lies.

Repetition and Scaling

The final stage is repeating the "find, test, refine" cycle at least three to five times. The best version of the strategy should be saved. This process can be automated: a separate research pipeline can run the entire cycle without human intervention—for example, 432 strategies were tested this way.

The essence of the approach is simple and pragmatic: the trader must verify the strategy's profitability on historical data before risking real money, not after. This reduces the cost of mistakes and allows weak points to be identified in advance.

Expert Opinion: This method is an excellent example of how AI can democratize access to quality backtesting. However, it is important to remember: past results do not guarantee future profits. The market changes, and a strategy that showed brilliant results on historical data may fail under new conditions. Therefore, I recommend combining automated analysis with regular manual checks and adaptation to the current market environment.