---
name: al-307-build-and-test-a-trading-strategy-by-talking-to-claude-co
description: "Writing a trading strategy in Pine Script and reading the backtest used to take coding skills. Davidd Tech shared on X (Oct 23, 2026) a step-by-step setup that drew 130+ bookmarks: install Claude Code, connect it to TradingView through the open-source TradingView-Unified-MCP project, log into TradingView and open a saved chart, then ask Claude to write a Pine Script v6 strategy (his example: BTCUSDT on the 4-hour chart, Supertrend for direction, ATR stop loss and take profit, fees and slippage on), compile it, attach it to the chart and read back the Strategy Tester numbers. His pass rules before a forward test: over 100 trades, drawdown under 20%, profit factor above 1.1 and beating buy-and-hold; otherwise tweak the settings and rerun, then paper-trade for about 3 months with no money before going live. This prompt keeps the agent in test-only mode. Use when the user wants help with investing & trading (finance) for a small business."
---

# Build and test a trading strategy by talking to Claude Code: connect it to your TradingView chart, have it write and backtest the strategy, and only forward-test what passes clear rules

Writing a trading strategy in Pine Script and reading the backtest used to take coding skills. Davidd Tech shared on X (Oct 23, 2026) a step-by-step setup that drew 130+ bookmarks: install Claude Code, connect it to TradingView through the open-source TradingView-Unified-MCP project, log into TradingView and open a saved chart, then ask Claude to write a Pine Script v6 strategy (his example: BTCUSDT on the 4-hour chart, Supertrend for direction, ATR stop loss and take profit, fees and slippage on), compile it, attach it to the chart and read back the Strategy Tester numbers. His pass rules before a forward test: over 100 trades, drawdown under 20%, profit factor above 1.1 and beating buy-and-hold; otherwise tweak the settings and rerun, then paper-trade for about 3 months with no money before going live. This prompt keeps the agent in test-only mode.

## Inputs to collect first
Ask the user for anything below that they haven't already given you. Don't guess missing facts.

- E.g. BTCUSDT, 4 hour
- E.g. Supertrend for direction, ATR-based stop loss and take profit…
- E.g. 2 ticks
- 3 months

## Instructions

Do the task below with the user's inputs in place of each [bracket].

You are connected to my open TradingView chart through an MCP server. You are in TEST-ONLY mode: never place, send or connect to real orders or a broker. Market and timeframe: [e.g. BTCUSDT, 4 hour]. Strategy idea: [e.g. Supertrend for direction, ATR-based stop loss and take profit, no trailing stop]. Do this: 1) Write a Pine Script v6 strategy for that idea with fees of [e.g. 0.1%] and slippage of [e.g. 2 ticks] turned on, and explain each rule in plain words. 2) Compile it, attach it to the chart and read back the Strategy Tester report: net profit, max drawdown, profit factor, number of trades, and buy-and-hold return. 3) Grade it against my pass rules: at least [100] trades, max drawdown under [20%], profit factor above [1.1], and beats buy-and-hold. 4) If it fails, change at most two settings at a time (e.g. Supertrend length, ATR multiplier), rerun, and show a table of every attempt so I can see if we're just curve-fitting. Stop after [5] attempts. 5) If it passes, tell me the risks you see and remind me to paper-trade it for [3 months] before using real money. This is not financial advice.

## Safety checks (share these with the user)

- Read and edit the draft before it reaches a customer or goes public. If you later automate this prompt, start with "draft and notify me", not "send automatically".
- Check names, dates, numbers and any claim against your own source material before you use the answer. AI can misread or invent details.
- Say clearly which parts need a person to review or approve before anything is sent, paid, posted or filed.

## About this skill

- Works with: Claude Code, TradingView, TradingView-Unified-MCP, Pine Script
- Based on this real-world example: https://x.com/DaviddDotTech/status/2113677833566585180
- Free prompt from AgentPlaybook Real Estate: https://agentic-library.netlify.app/prompt/al-307-build-and-test-a-trading-strategy-by-talking-to-claude-code/
- To install in an agent that supports Agent Skills, save this file as SKILL.md in a folder with the same name as `name` above (for example in your skills directory). Install steps for Claude.ai, Claude Code, Cursor and Codex: https://agentic-library.netlify.app/skills/
