pine-debugger
Troubleshoots Pine Script issues and adds debugging capabilities. Use when scripts have errors or unexpected behavior.
Implements comprehensive backtesting and performance metrics. Use when adding trade analysis, equity curves, or statistical validation.
$ npx -y skills add traderspost/pinescript-agents --skill pine-backtester --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/pine-backtesterContext preview
The summary Claude sees to decide when to auto-load this skill.
Implements comprehensive backtesting and performance metrics. Use when adding trade analysis, equity curves, or statistical validation.
name: pine-backtester description: Implements comprehensive backtesting and performance metrics. Use when adding trade analysis, equity curves, or statistical validation. allowed-tools: Read, Edit, Grep, Glob
Specialized in adding comprehensive testing and validation capabilities to Pine Script indicators and strategies.
Now possible: comprehensive multi-section reports:
// Build detailed performance report (up to 40K chars!) var string fullReport = "" fullReport := "═══════════════════════════════════════════\n" fullReport += " COMPREHENSIVE BACKTEST REPORT \n" fullReport += "═══════════════════════════════════════════\n\n" fullReport += "PERFORMANCE SUMMARY\n" fullReport += "───────────────────\n" fullReport += "Win Rate: " + str.tostring(winRate, "#.##") + "%\n" fullReport += "Profit Factor: " + str.tostring(pf, "#.##") + "\n" fullReport += "Sharpe Ratio: " + str.tostring(sharpe, "#.##") + "\n\n" fullReport += "TRADE DISTRIBUTION\n" fullReport += "───────────────────\n" // ... Can include much more detailed analysis
The preferred way to iterate over trade data arrays:
// ✅ BEST: Use for...in for arrays (safe, clean)
for tradeReturn in tradeReturns
// Process each return directly
// ✅ BEST: With index when needed
for [i, tradeReturn] in tradeReturns
// Have both index and value
// ❌ AVOID: Traditional for with dynamic boundary
for i = 0 to array.size(tradeReturns) - 1
array.push(newArray, processedValue) // Can infinite loop!
// ✅ FALLBACK: If traditional for needed, cache boundary
arrSize = array.size(tradeReturns)
for i = 0 to arrSize - 1
// Safe processingUse `active` parameter to show relevant settings:
showAdvancedMetrics = input.bool(false, "Show Advanced Metrics", group="Backtest")
sharpeRiskFreeRate = input.float(0.02, "Risk-Free Rate",
group="Backtest",
active=showAdvancedMetrics, // Only show when advanced enabled
tooltip="Annual risk-free rate for Sharpe calculation")Differentiate backtest visualization with line styles:
// Primary metrics: solid plot(strategy.equity, "Equity", color.blue, linestyle=plot.linestyle_solid) // Benchmarks: dashed plot(benchmarkEquity, "Benchmark", color.gray, linestyle=plot.linestyle_dashed) // Projections: dotted plot(projectedEquity, "Projected", color.yellow, linestyle=plot.linestyle_dotted)
**For comprehensive trade analysis, use UDTs to track individual trades.**
// Define Trade UDT for detailed tracking
type Trade
// Time coordinates (for historical analysis)
int entryTime
int exitTime
int entryBar
int exitBar
// Trade data
float entryPrice
float exitPrice
float positionSize
bool isLong
string exitReason
// Calculated metrics
float pnl = 0.0
float pnlPercent = 0.0
int duration = 0
// Visualization (optional)
line tradeLine = na
label entryLabel = na
label exitLabel = na
// Methods for trade analysis
method calculate(Trade this) =>
this.duration := this.exitBar - this.entryBar
if this.isLong
this.pnl := (this.exitPrice - this.entryPrice) * this.positionSize
this.pnlPercent := ((this.exitPrice - this.entryPrice) / this.entryPrice) * 100
else
this.pnl := (this.entryPrice - this.exitPrice) * this.positionSize
this.pnlPercent := ((this.entryPrice - this.exitPrice) / this.entryPrice) * 100
method draw(Trade this, color winColor, color loseColor) =>
tradeColor = this.pnl >= 0 ? winColor : loseColor
// Use xloc.bar_time for unlimited lookback!
this.tradeLine := line.new(this.entryTime, this.entryPrice,
this.exitTime, this.exitPrice,
xloc=xloc.bar_time, color=tradeColor, width=2)
// Storage
var array<Trade> completedTrades = array.new<Trade>()
var Trade currentTrade = na// Analyze all trades using for...in
if barstate.islastconfirmedhistory
totalPnl = 0.0
wins = 0
losses = 0
totalDuration = 0
for trade in completedTrades
totalPnl += trade.pnl
if trade.pnl >= 0
wins += 1
else
losses += 1
totalDuration += trade.duration
winRate = array.size(completedTrades) > 0 ? (wins / array.size(completedTrades)) * 100 : 0
avgDuration = array.size(completedTrades) > 0 ? totalDuration / array.size(completedTrades) : 0// Categorize trades by exit reason
var array<Trade> stopLossTrades = array.new<Trade>()
var array<Trade> takeProfitTrades = array.new<Trade>()
var array<Trade> timeoutTrades = array.new<Trade>()
// When trade closes, categorize it
if tradeJustClosed
if currentTrade.exitReason == "SL"
array.push(stopLossTrades, currentTrade)
else if currentTrade.exitReason == "TP"
array.push(takeProfitTrades, currentTrade)
else
array.push(timeoutTrades, currentTrade)
// Analyze by category
if barstate.islast
slCount = array.size(stopLossTrades)
tpCount = array.size(takeProfitTrades)
// ... diA comprehensive Pine Script development environment powered by Claude Code's Skills system. This tool helps you create professional TradingView indicators and strategies with AI assistance. Just type start to begin!
Troubleshoots Pine Script issues and adds debugging capabilities. Use when scripts have errors or unexpected behavior.
Writes production-quality Pine Script v6 code following TradingView guidelines. Use when implementing indicators, strategies, or…
Orchestrates complex Pine Script projects by coordinating multiple development phases. Use for complete trading systems.
Optimizes Pine Script for performance and user experience. Use when improving speed, UI organization, or visual appeal.
Prepares Pine Scripts for TradingView publication with documentation and compliance checks. Use when finalizing scripts for…
Analyzes trading concepts and YouTube videos to extract Pine Script specifications. Use when planning indicators or analyzing…