Oisigma/Blog
Research & notes

How to Test a Trading Idea on TradingView With Claude

For most of the history of retail charting, the hard part of testing a trading idea was writing the code. A trader with a rule in mind had to learn Pine Script, or pay someone who knew it, before a single historical trade could be counted. An AI assistant such as Claude has removed most of that cost. A rule described in plain English, or an indicator's source pasted into a chat, comes back as a working test in minutes.

That shifts the difficulty rather than removing it. When the code is cheap, the scarce skill is knowing what a test result does and does not show. This article describes the workflow as we ran it, the limit we hit on TradingView, and four checks that separate an equity curve from evidence. It is a procedure for examining an idea, not a way of trading one.

What the assistant changes

TradingView separates two kinds of script. An indicator draws things on a chart. A strategy places simulated orders, and the Strategy Tester reports on strategies only. A buy-and-sell indicator therefore cannot be tested as it stands; someone has to turn its signals into orders, or compute the results another way.

That translation is the step an assistant handles well. In our run we asked Claude for a script that takes buy and sell signals, follows them, and draws the resulting equity curve next to buy and hold of the same symbol, with a Sharpe ratio for each. It wrote the script, compiled it against TradingView and ran it on a chart's history without a line of code being typed by hand.

The limit we hit: one script cannot read another's labels

The original plan was a universal tester, a script that connects to any signal indicator already on the chart. TradingView does let one script take another's plotted series as an input. In our run that broke down at once. The open-source indicator we tried drew its BUY and SELL markers as shapes, and shapes did not appear in the tester's source menu. Only series drawn with the ordinary plot function did.

The repair was two added lines in a copy of the indicator, which the assistant wrote after reading the source. That is the practical lesson. The simple route is not a clever universal tool. It is handing the assistant the indicator's code and asking for the test. For a closed-source script that plots no numeric signal, we found no route at all, which is one more reason hidden code and checkable claims are separate questions.

An illustration: a moving-average cross on SPY

To check the script, it was run on a rule nobody owns: long when the 20-day simple moving average crossed above the 50-day, flat when it crossed back below. The symbol was SPY on daily bars over the full history the chart supplied. Orders were filled at the next bar's open, with a cost of 0.05% per side.

Starting from 100, the rule ended near 417 across 178 position changes. Buy and hold of the same price series ended near 1,658. The Sharpe ratios, computed from daily returns with a zero risk-free rate, were about 0.42 for the rule and 0.54 for buy and hold. Both series are price only, with no dividends.

This is one run of one rule on one symbol, an illustration of the workflow and not a study. It supports no general statement about moving averages, and past behavior is not a guarantee of future results. Its use here is narrower: the comparison line changed the reading. An equity curve that rises from 100 to 417 looks like success until the same chart shows what doing nothing produced.

Four checks before believing an equity curve

When the orders were filled. A signal is known only once its bar has closed. A test that trades at that same close, or at any price inside the signal bar, is using information that was not available in time. Filling at the next bar's open is the conservative convention, and it is worth asking the assistant to state in a comment which one the script uses. The same single-offset error is the main hazard in backtesting a band.

What it was compared against. Net profit on its own says little in a market that rose over the test period. Buy and hold on the same bars is the minimum comparison, and a cost per trade belongs in the test from the first run rather than as a later refinement.

Whether chance does as well. A rule that is long 60% of the time in a rising market collects much of that rise by being present. A baseline of random entries, matched to the rule's trade count and holding time, shows what presence alone earned. An assistant can add one on request. Our illustration did not include it, and so it shows a comparison with buy and hold and nothing about chance.

What the exit contributed. Many signal scripts mark entries only. A test then needs an exit, and that choice is the tester's, not the indicator's. A result that appears under one exit rule and vanishes under two others describes the exit.

The iteration trap

The same speed that makes an assistant useful makes one mistake nearly free. A disappointing curve invites a follow-up request to adjust the lengths, add a filter, or try another timeframe, and each revised script arrives in seconds. Ten rounds later the curve looks good, and nothing in the final script records the nine versions that were discarded.

Every retry is a hidden parameter. A result reached that way describes the search, not the rule, as the post on overfitting sets out, and the published research on trading rules has the same problem at scale under the name data snooping. Two habits limit the damage: writing down the rule and the pass mark before the first run, and holding back part of the history that no version is allowed to see until the end.

What a chart test can and cannot say

A test of this kind is bounded by the chart. It covers one symbol and only the bars the platform loads, which on intraday timeframes can be a short sample. A few dozen trades produce a number, but not one that separates a real effect from noise.

Within those bounds the result is a description of history. It says what following a rule would have returned on those bars under stated assumptions. It is not a forecast of what the rule returns next, and a favourable result is a reason to test further, on other symbols and other periods, not a conclusion.

The same standard, applied to our own tool

Oisigma's indicator does not issue buy or sell signals, so an equity curve is the wrong test for it. It draws an expected range, and the claim a range makes is about how often the next close landed inside it. That claim was stated first and then measured, and the results, including where the range falls short, are on the Proof page. The working paper validates the range's calibration, not the profitability of any use of it, and whether any use delivers value after costs is an open question.

The takeaway

An assistant has made the code for a backtest nearly free, and it has not made the result any easier to interpret. A test worth reading fills orders after the signal, includes costs, sits next to buy and hold and a chance baseline, shows how much the exit contributed, and was not reached by retrying until the curve looked right. With the code no longer the obstacle, those checks are most of the work.

Frequently asked questions

Can Claude run a TradingView backtest by itself? It depends on how it is connected. In the run described here Claude had a connection to TradingView, so it compiled the script and calculated it on a symbol's history directly. Without such a connection it writes the Pine Script and the reader pastes it into the Pine Editor and adds it to a chart.

Why does a script's Sharpe ratio differ from the Strategy Tester's? The two are computed differently. The script in this article annualises per-bar returns with a zero risk-free rate, while the Strategy Tester applies its own documented method and settings. Neither is wrong, but the two figures are not comparable with each other, so a comparison between a rule and buy and hold needs both computed the same way.

Does a repainting indicator invalidate the test? It can. If a script's historical signals change after the fact, the markers on the chart are not the ones a trader would have seen at the time, and a test built on them overstates the result. Whether a script repaints is a property of how it was written, and with open source an assistant can be asked to point out any function that reads ahead or recalculates on the current bar.

Can an invite-only or closed-source indicator be tested this way? Only partly. Without the source there is nothing for the assistant to convert, and a second script can read the indicator's output only where it plots a numeric series. An indicator that draws labels alone leaves counting signals by hand as the remaining option.

Claude is a trademark of Anthropic, PBC; Oisigma is not affiliated with or endorsed by Anthropic.

If the question behind a test is how far a market has typically moved rather than when to buy, a calibrated expected range answers that one directly. BTM draws it on any TradingView chart, and you can start a free 30-day trial, then $15 a month, to see it on the markets you already follow.

Now, your charts

Curious how this looks on your charts?

Try it free for 30 days and see the range update as new bars print, on whatever symbols and timeframes you actually trade.

Start your free trial
Complete checkout
Read the paper

30 days free, then $15/mo. Cancel anytime from your account.

Pick up where you left off.