Pine Script backtesting inside ChatGPT

Create, run, and analyze compatible Pine Script v6 strategy backtests from ChatGPT.

Describe a strategy in plain English or paste Pine Script v6. PineScript API generates or validates the code, runs a close-only OHLC backtest, and returns the exact script, resolved settings, dataset coverage, risk metrics, and trades.

A Pine Script backtesting GPT powered by a dedicated execution API

Example backtest Complete
Prompt

Test a 20/50 SMA crossover on BTCUSD from 2021–2024.

strategy.pinePine Script® v6
1  //@version=6
2  strategy("SMA 20/50 Crossover", overlay=true)
3
4  fast = ta.sma(close, 20)
5  slow = ta.sma(close, 50)
6  long = ta.crossover(fast, slow)
Net Profit+18.4%
Max Drawdown6.2%
Win Rate53.1%
Trades128

Illustrative result for interface demonstration.

01Natural-language creation
02Actual backtest execution
03Input optimization
04Auditable run receipts

Two ways to begin

Start with an idea or bring an existing script.

PATH A · PLAIN LANGUAGE

Start with an idea

Describe the entry, exit, risk, and market rules. The GPT creates a compatible Pine Script v6 strategy and runs the first backtest.

PATH B · EXISTING CODE

Bring an existing script

Paste Pine Script v6. The GPT preserves the original logic, checks known compatibility surfaces, and does not silently replace unsupported behavior.

Reliability first

Understand the public execution contract.

A high return means little if the strategy used information that was unavailable at the time. The public environment is designed to reduce common repainting and lookahead paths.

01

Completed chart-timeframe bars

Evaluate strategy logic once per completed chart-timeframe bar using the public close-only OHLC execution model.

02

No tick or after-fill recalculation

Live tick recalculation and immediate strategy recalculation after simulated fills are disabled in public mode.

03

Restricted cross-context data requests

Multi-timeframe and cross-symbol requests are rejected because their timing, alignment, and coverage are outside the current parity contract.

04

Auditable run receipts

Each run records the exact script, resolved settings, engine build, dataset ID, loaded coverage, trade window, and request fingerprints.

IMPORTANT A later rerun may differ if the underlying dataset or engine build has changed. The receipt identifies the environment used for the original result. Read the execution model →

How it works

Run a Pine Script backtest from ChatGPT.

Start in natural language or bring your existing script. PineScript API keeps the strategy, test, and revision loop in one GPT conversation.

01

Describe or paste

Start from natural language or provide a Pine Script v6 strategy() script whose original logic should be preserved.

IDEA / SCRIPT
03

Run the backtest

The GPT inspects known surfaces first. The engine performs the authoritative compile, runtime, setting, and broker-state checks.

SUBMIT / EXECUTE
04

Analyze or optimize

Ask follow-up questions about risk and trades, or compare up to 30 input variants without leaving the conversation.

ANALYZE / OPTIMIZE

Capabilities

Pine Script v6 backtesting built for iteration.

Purpose-built around the moments that usually interrupt momentum: translating rules, running a test, reading the numbers, and revising the idea.

EXECUTION

Completed OHLC bars

Signals are evaluated from confirmed chart-timeframe bars rather than live intrabar tick changes.

strategy("Momentum v2")
COSTS

Commission and slippage

Model trading costs as part of the run instead of evaluating an unrealistically frictionless strategy.

Profit+Risk6.2%Trades128
ORDERS

Common order types

Test market, limit, and stop entries with simple stop-loss, take-profit, and full-position exits.

Long + short · stop · limit · exit
INPUTS

Repeatable configurations

Override Pine inputs while preserving the script and settings used to create each result.

AB

Learn the workflow

Pine Script backtesting guides and examples.

Use focused documentation to check compatibility, understand execution assumptions, and start from a strategy example you can inspect line by line.

Review the run

Review backtest performance, risk, and trades.

Evaluate return, risk, sample size, long and short behavior, and the trades that produced the summary.

PERFORMANCE SUMMARY

Outcome and risk

  • Net profit and return
  • Maximum drawdown
  • Win rate and Profit Factor
  • Average profit or loss per trade
DETAILED ANALYSIS

Behavior over time

  • Equity and cumulative return
  • Monthly and yearly returns
  • Long and short performance
  • Best, worst, and recent trades
TRADE HISTORY

Every completed trade

  • Entry and exit time and price
  • Long or short direction
  • Profit or loss and holding period
  • Paginated completed trade history

Analyze and optimize

Compare strategy inputs without leaving the conversation.

Ask follow-up questions about one completed run, or test up to 30 input configurations in a single optimization request.

CONVERSATIONAL ANALYSIS

Interrogate the completed run

Review monthly and yearly returns, long-versus-short behavior, the maximum-drawdown period, trade statistics, and selected best, worst, or recent trades.

“Which side caused the drawdown?”“Show the 10 largest losing trades.”“Compare recent trades with the best trades.”
INPUT OPTIMIZATION

Rank up to 30 variants

Rank completed variants by Profit Factor, Net PnL %, Net PnL minus drawdown, or return over drawdown. Each submitted variant counts as one backtest run.

Read the optimization guide

VALIDATE SEPARATELY Optimization only finds the best result among the tested variants. It does not prove that the selected settings will remain profitable. Validate selected settings on a separate period.

Built for the loop

Stay with the idea while it’s still moving.

For Pine developers, systematic traders, and strategy researchers who want less context switching between an idea and its first useful test.

Start a backtest in ChatGPT

Compatibility

A Pine Script v6 compatibility subset with explicit boundaries.

The public engine is not a complete implementation of every TradingView Pine language, visual, data-request, and broker-emulation feature.

SUPPORTED

Common single-position structures

  • One entry ID per direction
  • pyramiding = 0
  • Market, limit, and stop entries
  • Simple full-position stop and target exits
  • strategy.close and close_all
  • Costs, scalar inputs, and common indicators
SUPPORTED WITH CONSTRAINTS~

Narrowly defined order patterns

  • One simple partial exit plus full remainder
  • One full-position trailing exit
  • Simple OCA Cancel pending pair
  • Simple close_entries_rule="ANY"
  • strategy.order used like an entry while flat
  • Simple cancellation and exit reissue patterns
NOT SUPPORTED

Rejected instead of approximated

  • request.security() and multi-timeframe data
  • Requests for other symbols
  • Live ticks and Bar Magnifier dependencies
  • Pyramiding, DCA, and scale-in
  • Multiple same-direction entry IDs
  • Multiple partial exits or OCA Reduce

Unsupported code is not silently transformed into a different strategy. If compatibility would change the original logic, execution stops and the relevant limitation is identified.

Audit the result

Every completed run leaves an auditable receipt.

Review the exact script, resolved settings, dataset ID and loaded coverage, trade window, engine build, and request fingerprints behind the result.

Run a documented backtest
RUN RECEIPTRECORDED CONTEXT
Script
Exact Pine source · script SHA-256
Market
CRYPTO · BTCUSD · D
Period
2021-01-01 → 2024-12-31
Costs
Commission 0.10% · Slippage 2 ticks
Dataset
Dataset ID · first/last bar · loaded count
Engine
Engine build · settings SHA-256

Receipt field preview — not a live run record.

FAQ

Pine Script backtesting FAQ.

Does this work inside ChatGPT?+

Yes. Open the PineScript API GPT, describe or paste your strategy, and use the conversation to run and refine the backtest workflow.

Which ChatGPT plan and model should I use?+

ChatGPT Plus or higher is required. For the best Pine Script generation, debugging, and backtest interpretation, use the newest model available because newer models generally provide stronger reasoning.

Do I need to know Pine Script?+

You can begin with a plain-language strategy description. If the script matters to a real decision, review the generated rules and code carefully before relying on the output.

Is the environment completely repaint-free?+

No environment can guarantee zero differences in every case. Live tick recalculation and cross-context data requests are restricted, but exchange data, historical revisions, sessions, dataset coverage, fill assumptions, and overfitting can still affect results.

Which markets and timeframes are available?+

Availability follows the managed public dataset catalog, not every TradingView symbol. The current catalog includes selected crypto, gold, and US-equity datasets. Check the dated data availability guide or ask the GPT to resolve the exact dataset before running.

When is an order processed?+

Strategy calculation and order filling are separate. New market orders fill at the next available simulated price by default. Pending stop or limit orders may fill inside a bar under OHLC broker-emulation rules. On-close processing, when enabled, is recorded with the result.

Why are bars loaded before the start date?+

The date range controls when new entries are allowed; it does not truncate indicator history. Earlier bars may load for warm-up, and an open position may be force-closed immediately after the trade window ends.

Is an account required?+

Yes. ChatGPT Plus or higher is required to use the GPT, and the first backtest may ask you to connect your PineScript API account. PineScript API trial credit can permit a run without a separate active API subscription.

How are backtest and optimization runs counted?+

One backtest consumes one run. In an optimization request, each submitted input variant consumes one run. Up to 30 variants can be submitted, subject to available run credits.

Will live trading match the backtest?+

No. Live results may differ because of spreads, liquidity, latency, market impact, funding costs, execution rules, and data differences.

Is this financial advice?+

No. PineScript API is for strategy research and software validation. Backtest results are simulations, not guarantees of future performance.

Test with context

Know what produced
the result.

Review the data, execution settings, risk, and trade history behind the return—not the headline number alone.

Open PineScript API