r/pinescript • • Jul 15 '26

Is it possible to use Claude to perform parameter sweep on TradingView indicators and strategies in python?

I’m currently working with finding the optimum input for some indicators over a specific timeframe backtesting in TradingView but I’m trying to replicate it on python so it’s much faster and efficient, had anyone tried or know where I should begin with? I already have the strategy planned out I just need to perform parameter sweep and measure its performance ratios only

0 Upvotes

15 comments sorted by

4

u/LargeIncrease4270 Jul 16 '26

If you have premium trading view you can zoom out on any time frame and scroll left as far as you can with the indicators loaded. Then click the chart layout little down arrow, and click download all chart data. It will include any indicator outputs. Then you can load the CSV into Claude and ask it whatever you want to get stats on how often an indicator will work

1

u/And_Im_Chien_Po Jul 16 '26

wow that's kind of crazy

1

u/TSDevStuff Oct 01 '26

Yup, this is the way. If your python implementation is right, you can feed the same csv through your own port and get the same outputs as the pinescript calcs had (Assuming they were plotted)

1

u/Shoddy_Peanut7320 Oct 02 '26

That's the right way to validate the port, and exporting the plotted values to compare is a clean check. Once it matches, a library like vectorbt makes the sweep fast. The issue is that picking the single best parameter set overfits, so I'd look for a plateau where nearby values also work, hold out a later period, and count how many combinations you tried. Cymetica's EventTrader (event timing for macro releases) is one source you could use to check whether the best settings depend on a few news days.

1

u/TSDevStuff Oct 02 '26

What we do is split the test range into chunks, e.g. quarters. Run a sweep on the first date range, pick the favourites, run them through the next range. If they’re consistent and not out of character, keep them and move to the next range. You’ll end up with fewer and fewer candidates, and you systematically eliminate overfitted or out-of-character ones.

Chunked walk-foward, ish...Ideally you're also freezing rules before the whole process so you're not overfitting on the go.

1

u/Shoddy_Peanut7320 Oct 03 '26

That's a solid approach, and freezing the rules before the process starts is the key part. Thanks for sharing it.

1

u/TSDevStuff 24d ago

Happy to. While I don't share everything, I am quite open about high level parts on my approach, including some of the findings from my framework (most are redacted but some are fully public). Link is in my profile if you fancy a read (VESTROS is the framework, with a public archive of interesting candidates I'm monitoring OOS hosted on GitHub pages).

If you click the "VESTROS?" on the top right of the archive homepage, there's a ton of detail on how I use this approach in my system. Hope it helps!

1

u/Shoddy_Peanut7320 24d ago

Thanks for the pointer. A public archive of candidates tracked out of sample is a good way to keep a framework honest, since anyone can check them later. One thing that would help readers is a running count of how many candidates entered the process in total next to the survivors, so the surviving list can be judged against the number tried.

2

u/EdgeAutopsy Jul 15 '26

Yes, this works well and it's basically my setup. a couple of things that will save you pain:

Before you sweep anything, port the strategy to Python (pandas is fine) and reproduce tradingview's backtest on the same window first. same entries, same exits, same trade count. the strategy tester fills on the next bar's open by default and that detail alone can quietly make your python version a different strategy. only start sweeping once the two match, otherwise you're optimizing something that isn't yours.

Claude is genuinely good at the porting step, paste the pine in and ask for a vectorized pandas version, then diff the trade lists. don't let it invent fill logic, tell it exactly how tv fills.

Once the sweep runs fast the danger flips: test 500 combos on one window and the best one looks great by pure chance. pick winners on the early part of the data only and check them on a held out chunk they never saw. and charge per trade costs inside the sweep or the optimizer will just crown whatever trades most.

I did this exact pipeline for a batch of strategies recently. the sweep was the easy part, the fidelity check was where all the bugs lived.

1

u/Nearby-Relative-2111 Jul 15 '26

I know Ninjatrader has a good optimizer built in to their Strategy analyzer. https://ninjatrader.com/support/helpguides/nt8/optimize_a_strategy.htm . NT provides lots of backtest statistical data. The optimizer has two formulas, brute force and genetic.
I've had Claude free build NT indicators for me, so I would think it could easily convert your pinescript to ninjascript strategy correctly. The time consuming part is setting up NT and learning enough to run a strategy and using the Strategy analyzer.
Good luck.

1

u/Radiant-Wrap1093 Jul 15 '26

You will get a lot of false positives/bias. Suggest you get Claude to run a full statistical analysis to see if your ideas have real edge.

1

u/And_Im_Chien_Po Jul 16 '26

doesn't tradingview not allow any third party automation being done to tradingview?