Can Claude or Codex Backtest With TradingView? What Works in 2026
Can Claude Code or Codex backtest a strategy through TradingView MCP? What the official server can do since its Pine Script tools, the daily call limits, the three routes and how to check the result.
By Tom Evans · Updated · 6 min read

Yes, within limits, since 16 November 2026. TradingView's official MCP server now has Pine Script tools: Claude, Claude Code and Codex can check, read, save and run Pine Script, and run_pine_backtest returns a compact Strategy Tester report. Every call counts towards a daily allowance set by your TradingView plan, from 10 calls a day on Essential, and the toolset is still in beta. There are three routes to a backtest with an AI assistant and TradingView data: have the assistant write a Python backtest on bars it pulls through the MCP server, have it run a Pine Script strategy through run_pine_backtest, or export the Strategy Tester's list of trades and have the assistant (or a backtesting tool) analyse it. Each has limits worth knowing before you trust the number it gives you.
If you haven't connected it yet, the setup commands are in our guide to connecting Claude or Codex to TradingView, and what the TradingView MCP server can and can't do lists the tools.
AI-written backtests are as likely to contain mistakes as any other code. Backtests are not future results, and leveraged trading carries a high risk of loss.
What the official TradingView MCP server gives an AI
What changed in November 2026
On 16 November 2026 TradingView added eight Pine Script tools to its MCP server and said that from 17 November 2026 the MCP calls included in paid plans are limited per day. Before that, the official server had no Pine Script or Strategy Tester tools, which is what an earlier version of this guide said. Its documentation now lists 38 tools in nine groups and says "The toolset is in beta and expands over time" (both pages checked 27 November 2026).
| It can | It can't |
|---|---|
| Pull OHLCV bars (at most 5,000 per call as rows) | Place, change or cancel orders |
| Run the screener and read technical ratings | Return equity curves from a backtest |
| Read news, filings and the economic calendar | Read protected or invite-only script source |
| Read and change your watchlists and price alerts | Run beyond your plan's daily call allowance |
| Check, read, save and run Pine Script | |
Return a compact Strategy Tester report with run_pine_backtest |
The Pine Script tools are validate_pine_script, get_pine_script_info, get_pine_script_source, search_pine_scripts, create_pine_script, update_pine_script, run_pine_indicator and run_pine_backtest. According to the docs, the backtest report covers net and gross profit and loss, profit factor, trade counts, percent profitable, average trade and largest win and loss, split into all, long and short, plus max drawdown, Sharpe and Sortino for the whole test. It returns the latest closed trades (20 by default, at most 200) and the tested period, but "Equity curves are never returned". With a start date it runs in Deep Backtesting mode, which depends on your plan.
Daily call allowances
| TradingView plan | MCP calls included per day |
|---|---|
| Essential or any legacy plan | 10 |
| Plus | 20 |
| Premium | 50 |
| Ultimate | 500 |
| AI subscription on a paid plan | 500 a day, 50 a minute |
TradingView's post says "every validation, run, and backtest counts as a call" (checked 27 November 2026). Its docs also say not to use the MCP server for automated trading or trading decisions.
Community "desktop bridge" servers that control the TradingView Desktop app can also read Strategy Tester data, including trades and equity, but they use undocumented internal interfaces and TradingView doesn't support them. Read what any community server or "skill" does before you install it, and never give one your broker credentials.
Route 1: Claude or Codex writes a Python backtest on MCP data
Ask the assistant to pull bars with get_ohlcv and write a backtest in Python.
Good for: a quick first look at a simple idea.
Watch for:
- Short history. On a market that trades 23 hours a day, 5,000 bars is about three and a half days of 1-minute data or about 18 days of 5-minute data. That's far too little for an intraday strategy.
- Look-ahead bias. AI-written backtests often use the close of a bar to enter on the same bar, or use higher-timeframe values before that bar has closed.
- No costs or fills. Unless you ask, most generated backtests ignore commission, spread and slippage, and assume every limit order fills.
- Rule drift. The code may not match what you asked for. Ask the assistant to list the exact rules it implemented and check them.
Route 2: the assistant runs Pine Script through run_pine_backtest
Since 16 November 2026 an assistant connected to the official server can check a Pine Script v6 strategy with validate_pine_script and run it with run_pine_backtest, which returns a compact Strategy Tester report rather than a full one.
Good for: a summary of how a Pine strategy scored on TradingView's data and fill model, without copying code across by hand.
Watch for:
- Call limits. A round of "fix the error, check, backtest, adjust" is often three or four calls. On Essential's 10 a day that is two or three rounds, and tuning that many rounds against the same history is a fast way to overfit anyway.
- A summary, not the full picture. You get the headline metrics and up to 200 recent closed trades, with no equity curve, so the report alone won't show where a strategy breaks.
- The usual Pine traps.
request.securitylook-ahead, and settings that flatter results, such as zero commission or "on bar close" fills that aren't realistic. Our guide to Claude for Pine Script covers prompts and checks. - Beta. TradingView's post warns some tools "may not work as smoothly as expected".
Route 3: export the trades and validate them
Once the Strategy Tester has run, export the list of trades (how to export Strategy Tester results) and analyse it: by session, weekday and volatility, with Monte Carlo, and on the period the strategy wasn't tuned on.
Good for: finding out whether the result is real before you automate it. Our backtest validation checklist lists the ten checks.
Or skip the code
If what you want is "describe a strategy in plain English and get an honest backtest", Strategy Lab does that without code: you describe the strategy to TES, the AI strategy coach, Strategy Lab reads the rules back in plain English before it runs, and the backtest runs on 1-minute to daily candles over up to 20 years of data, with an unseen period, Monte Carlo, costs and other-market tests. A strategy that holds up exports to TradingView as Pine Script v6 on paid plans.
A checklist for any AI-made backtest
- Ask the assistant to list the exact rules it implemented. Compare them with what you meant.
- Check the data length covers different market conditions.
- Check entries can't use information from the future.
- Add realistic commission, spread and slippage.
- Hold back an unseen period and look at it once.
- Count the trades. Fewer than about 100 tells you very little. See how many trades a backtest needs.
Frequently asked questions
- Can Claude backtest a strategy with TradingView MCP?
- Yes, since 16 November 2026. The official MCP server's
run_pine_backtesttool runs a Pine Script strategy and returns a compact Strategy Tester report, and each run counts towards your plan's daily call allowance (10 a day on Essential, 500 on Ultimate, as of 27 November 2026). Claude can also pull up to 5,000 bars per call and write a Python backtest on them. If you want to test a strategy idea without code or call limits, describe it to TES in Strategy Lab. - Can Codex connect to TradingView?
- Yes. Codex can connect to TradingView's official MCP server with
codex mcp add tradingview --url https://mcp.tradingview.com/mcp, on an Essential TradingView plan or above. It gets the same tools as Claude: market data, screener, news, filings, the economic calendar, watchlists, alerts and, since 16 November 2026, the Pine Script tools. - Is there a TradingView skill or plugin for Claude or Codex?
- TradingView's own integration is its MCP server. Community "skills", plugins and desktop bridges also exist; they are not supported by TradingView, and some control the desktop app through undocumented interfaces. Read what one does before installing it.
- Can AI read my TradingView Strategy Tester results?
- Partly, since 16 November 2026. The official MCP server's
run_pine_backtestreturns a compact report with summary metrics and up to 200 recent closed trades, but never the equity curve. For the full list of trades, export it from the Strategy Tester and give the file to an assistant or a backtest analysis tool.
Backtested strategies that held up
Each one was searched from hundreds of variants, then tested once on a locked final year it was never tuned on. Full rules, every trade and a free prompt to rebuild it.
- ETHUSDT
+1,893.2%
Sep 2019 to Nov 2026
Profit factor
1.39
Win rate
35.2%
Max DD
−18.9%
Breakout · 4 hours
ETHUSDT 4h Bollinger band breakout
Enter when the candle closes above the upper Bollinger band(30, 2) for longs, below the lower band for shorts, with the 200 EMA trend. ETHUSDT 4-hour candles, long and short, 3R target.
See the rules and results - EURUSD
+1,339.5%
Nov 2006 to Nov 2026
Profit factor
1.66
Win rate
53.0%
Max DD
−16.0%
Momentum · Daily
EURUSD daily CCI cross
Enter when CCI(14) crosses above -100 for longs, below 100 for shorts. EURUSD daily candles, long and short, 1.5R target.
See the rules and results - ADAUSDT
+937.9%
Sep 2019 to Nov 2026
Profit factor
1.50
Win rate
34.5%
Max DD
−15.0%
Breakout · 4 hours
ADAUSDT 4h Bollinger band breakout
Enter when the candle closes above the upper Bollinger band(20, 2) for longs, below the lower band for shorts, with the 200 EMA trend. ADAUSDT 4-hour candles, long and short, 3R target.
See the rules and results
Keep reading
AI and Pine ScriptHow to Connect Claude to TradingView (Official MCP Server, 2026)
Add TradingView's official MCP server to Claude, Claude Code or Codex step by step: the commands, the plan you need, daily call limits and what it can do.
AI and Pine ScriptTradingView MCP Server: What It Can and Can't Do (2026)
The official TradingView MCP server and the community ones compared: what each can read, which can touch Pine Script, the plan you need and which to use.
AI and Pine ScriptHow to Test a Trading Strategy ChatGPT or Claude Wrote
A step-by-step way to check an AI-written Pine Script strategy: catch lookahead and repainting, set realistic costs, test out of sample and by market condition.