A Pine Script v6 prompt pattern that reduces version mixing, repainting mistakes, invalid JSON alerts and untestable strategy logic.
In plain English
This guide uses AI to help plan, write, review or debug code. Generated output still needs version checks, compilation, tests and human-defined production rules.
Always specify the Pine version
TradingView's current major language is Pine Script v6. Ask explicitly for v6 and tell the model not to mix v4/v5/v6 syntax. TradingView warns that AI-generated Pine can invent language features or combine syntax from different versions.
A stronger Pine prompt
Use Pine Script v6 only.
Create a strategy, not an indicator, because I need Strategy Tester results.
Do not use lookahead, future bars or repainting logic.
Use confirmed-bar conditions unless I explicitly request intrabar behavior.
Entry rules:
- [exact rule 1]
- [exact rule 2]
Exit rules:
- [exact exit]
Risk model:
- [exact sizing / stop / filter]
Plot every signal component so I can visually verify it.
Create a valid JSON alert with:
event_id, symbol, action, timeframe, strategy_version, bar_time.
Do not include credentials.
After the code:
1. list all assumptions,
2. identify possible repainting sources,
3. explain alert timing,
4. give five manual test cases,
5. point out any Pine feature you are uncertain about.
Ask for observability, not only entries
AI code is easier to debug when the script plots the components that produced a decision. Ask for background colors, labels or a small table that exposes the state of each filter. Remove extra visuals only after the logic is verified.
Webhook JSON prompt
Make the TradingView alert message valid JSON.
Use double quotes and no trailing commas.
The receiver expects:
{
"event_id": "...",
"symbol": "...",
"action": "buy|sell|close",
"timeframe": "...",
"strategy_version": "v1",
"bar_time": "..."
}
Do not put API keys, broker logins or passwords in the payload.
Second-pass review prompt
Audit this Pine Script v6 code against the current TradingView language.
Do not rewrite it unless needed.
Check for version-mixing, nonexistent functions, lookahead, repainting,
bar-state mistakes, alert timing differences, unrealistic backtest assumptions,
and JSON that is not syntactically valid.
Return a table: issue, severity, evidence, smallest fix, test.
Official references
Before you rely on this in production
- Prompt states exact language/platform version.
- Generated APIs/functions are verified against documentation.
- Secrets are removed from prompts.
- Generated code is compiled/run and tested before deployment.
