Comprehensive debugging suite for PineScript custom indicator development.
This debugging suite provides advanced tools for PineScript developers to identify, diagnose, and fix issues in custom indicators and strategies. Built on top of the existing PineScript integration, it addresses the #1 pain point for advanced developers: debugging complex calculations and logic.
/pine-validate --file my-indicator.pine/pine-debug helpers --output debug-helpers.pine/pine-debug inspect --var "myVariable" --bars 20/pine-debug profile --metrics complexity --iterations 1000/pine-debug inspect --var "variableName" --bars 20 --format jsonOptions:
--file, -f- PineScript file (auto-detected)--var, -v- Variable name (supports wildcards:*,rsi*)--bars, -b- Historical bars to inspect (default: 10)--format- Output format:text,json,csv--output, -o- Output file path
/pine-debug trace --var "macdLine" --plot --bars 50Options:
--plot, -p- Generate debug plot code--step, -s- Step size for tracing (default: 1)--bars, -b- Bars to trace (default: 20)
/pine-debug monitor --condition "crossover(fastMA, slowMA)" --alertOptions:
--condition, -c- Condition expression to monitor--watch, -w- Watch variables (comma-separated)--alert, -a- Generate alert code--bars, -b- Bars to monitor (default: 50)
/pine-debug profile --metrics cpu,memory,complexity --iterations 1000Options:
--iterations, -i- Number of iterations (default: 1000)--metrics, -m- Metrics:cpu,memory,complexity--output, -o- Output file for JSON report
/pine-debug helpers --output my-debug-helpers.pine --include advancedOptions:
--output, -o- Output file (default:debug-helpers.pine)--include- Helpers to include:all,basic,advanced,custom
/pine-debug server --port 3000 --file indicator.pineOptions:
--port- Server port (default: 3000)--file, -f- PineScript file to debug
/pine-debug test --file indicator.pine --test-cases tests.jsonOptions:
--test-cases- Test cases file (JSON)--output, -o- Test results output
//@include "debug-helpers.pine"
debug.plot(value, "Label", color=color.blue)
debug.plotchar(value, "Value Display")
debug.plotshape(condition, "Condition", shape.triangleup)
debug.series(value, "Historical Series", lookback=50, showHistory=true)
debug.monitorSeries(value, "Anomaly Detection", threshold=2.0)
debug.monitorCondition(condition, "State Tracking", alertOnChange=true)
debug.conditionBreakdown(mainCondition, subConditions, conditionLabels)
debug.errorCheck(value, "Validation", checks=["na", "inf", "zero"])
debug.trackCalculation("Expensive Calculation")
debug.memoryMonitor(valuesArray, labelsArray)
debug.table(values, labels, "Debug Table")
debug.compareSeries(seriesArray, labels, comparison="pct")
debugLevel = input.int(2, "Debug Level", minval=0, maxval=3)
debugOutput = input.string("plot", "Debug Output", options=["plot", "alert", "table", "all"])
The /pine-validate command now includes debugging suggestions:
- Complexity detection: Flags indicators with >100 lines or >10 variables
- Performance patterns: Identifies loops and expensive calculations
- Debugging opportunities: Suggests where to add debug visualizations
- Error handling: Checks for missing NA/infinity handling
🔧 Debugging Suggestions:
1. 💡 Complex indicator (150 lines, 25 variables).
🛠️ Consider using /pine-debug profile to analyze performance
2. 💡 Many variables (25) without debug visualization.
🛠️ Add plotchar() for key variables or use debug helpers
3. ⚠️ Loop structures detected (performance concern).
🛠️ Use /pine-debug profile to optimize performance
🚀 Quick Debugging Commands:
/pine-debug inspect --var VARIABLE_NAME
/pine-debug trace --var VARIABLE_NAME --plot
/pine-debug profile --metrics complexity
/pine-debug helpers --output debug-helpers.pine
- Value Tracking - Reference lines, ranges, background colors
- Condition Visualization - Shapes, arrows, labels for discrete events
- Historical Comparison - Bands, statistical ranges, fills
- Multi-Series Comparison - Correlation, scaling, multiple axes
- State Machine Visualization - State tracking, transitions, colors
- Anomaly Detection - Error markers, outlier detection, severity coding
- Performance Metrics - Real-time metrics, threshold bands
- Data Table Display - Tabular data in data window
- Trend Visualization - Multi-timeframe analysis, strength indicators
- Interactive Debugging - User-controlled debug levels, conditional plotting
// Pattern 1: Value Tracking with Reference Lines
plot(value, "Value", color=color.blue, linewidth=2)
plot(ta.sma(value, 20), "Mean", color=color.gray)
plot(ta.lowest(value, 20), "Min", color=color.red, linewidth=1)
plot(ta.highest(value, 20), "Max", color=color.green, linewidth=1)
bgcolor(value > ta.sma(value, 20) ? color.new(color.green, 90) : color.new(color.red, 90))
examples/pinescript-projects/debug-examples/complex-indicator-debug.pine
- Complete custom indicator with integrated debugging
- Multiple debug levels and output channels
- Performance monitoring and error checking
- Test framework for validation
examples/pinescript-projects/debug-examples/visualization-patterns.pine
- 10 standard visualization patterns
- Color schemes and styling guidelines
- Interactive debugging controls
- Best practices and usage examples
examples/pinescript-projects/debug-examples/simple-test-indicator.pine
- Intentional bugs for debugging practice
- Step-by-step debugging exercises
- Expected issues and fixes
- Learning objectives and practice tasks
examples/pinescript-projects/debug-helpers/debug-helpers.pine
- Comprehensive debugging function library
- Configurable debug levels and outputs
- Error detection and validation
- Performance monitoring utilities
# 1. Validate and get suggestions
/pine-validate --file indicator.pine
# 2. Generate debug helpers
/pine-debug helpers
# 3. Profile baseline performance
/pine-debug profile --iterations 1000 --output baseline.json# 1. List all variables
/pine-debug inspect --var "*" --format text
# 2. Trace problematic variables
/pine-debug trace --var "problematicVar" --bars 100 --plot
# 3. Monitor complex conditions
/pine-debug monitor --condition "complexLogic" --watch "input1,input2,input3"# 1. Identify bottlenecks
/pine-debug profile --metrics complexity --verbose
# 2. Test optimizations
/pine-debug profile --iterations 5000 --output optimized.json
# 3. Compare results
diff baseline.json optimized.json# 1. Interactive debugging
/pine-debug server --port 3000
# 2. Visual regression testing
/pine-debug compare --file v1.pine v2.pine --data test-data.csv
# 3. Generate documentation
/pine-debug docs --file indicator.pine --output DEBUGGING.md# Check calculations
/pine-debug inspect --var "finalValue" --bars 10
# Generate debug visualization
/pine-debug trace --var "finalValue" --plot
# Check for NA values
/pine-debug inspect --var "*" --format json | grep -i "na"# Profile with different metrics
/pine-debug profile --metrics cpu,memory --iterations 5000
# Identify expensive calculations
/pine-debug inspect --var "*" | grep -i "custom\|loop"
# Check memory patterns
/pine-debug profile --metrics memory --verbose# Trace variable history
/pine-debug trace --var "unexpectedValue" --bars 50 --step 1
# Monitor contributing conditions
/pine-debug monitor --condition "affectsValue" --watch "unexpectedValue"
# Check bounds and validation
/pine-debug inspect --var "unexpectedValue" --format json# Break down complex conditions
/pine-debug monitor --condition "mainCondition" --watch "sub1,sub2,sub3"
# Generate condition visualization code
/pine-debug trace --var "conditionState" --plot
# Track state changes
/pine-debug inspect --var "stateVariable" --bars 20// Level 0: Production (no debugging)
// Level 1: Basic plots and alerts
// Level 2: Intermediate values and conditions
// Level 3: Detailed analysis and profiling
if debugLevel >= 1
debug.plot(mainValue, "Main")
if debugLevel >= 2
debug.plot(intermediate, "Intermediate")
if debugLevel >= 3
debug.series(detailed, "Detailed", 50, true)
// Only debug on last bar for expensive operations
if barstate.islast and debugLevel > 0
debug.table(values, labels, "Final Analysis")
// Sample debug output for high-frequency indicators
debugSampling = bar_index % 5 == 0
if debugSampling
debug.plot(value, "Sampled Value")
// Group related debug outputs
debug.plot(group1Value, "Group 1 - Value", color=color.blue)
debug.plotchar(group1Condition, "Group 1 - Condition")
// Use consistent locations
debug.plotchar(value1, "Value 1", location=location.top)
debug.plotchar(value2, "Value 2", location=location.top - 1)
debug.plotchar(value3, "Value 3", location=location.top - 2)
// Validate inputs and calculations
debug.errorCheck(inputValue, "Input", ["na", "inf"])
debug.errorCheck(calculation, "Calculation", ["na", "inf", "zero"])
// Graceful degradation
if debug.errorCheck(value, "Critical Value", ["na", "inf"])
// Use fallback value
safeValue = nz(value, defaultValue)
#!/bin/bash
# pre-commit.sh
/pine-validate --strict
/pine-debug profile --metrics complexity --iterations 100
/pine-debug inspect --var "*" --format json --output variables.json# .github/workflows/pinescript-ci.yml
name: PineScript CI
on: [push, pull_request]
jobs:
debug:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Debugging Analysis
run: |
/pine-validate --file *.pine
/pine-debug profile --metrics complexity --output profile.json
/pine-debug inspect --var "*" --format json --output variables.json#!/bin/bash
# dev-debug.sh
INDICATOR=$1
echo "🔍 Analyzing: $INDICATOR"
/pine-validate --file $INDICATOR
/pine-debug helpers --output /tmp/debug-helpers.pine
/pine-debug inspect --var "*" --bars 20 --format text
/pine-debug profile --iterations 1000 --output /tmp/profile-$(date +%s).json// Check include path
//@include "debug-helpers.pine" // Same directory
//@include "../debug-helpers.pine" // Parent directory
//@include "/full/path/debug-helpers.pine" // Absolute path
- Reduce
debugLevelwhen not needed - Use
barstate.islastfor expensive operations - Disable historical tracking for long series
- Sample debug output instead of every bar
- Use different
locationvalues - Limit simultaneous plots
- Group related visuals
- Use transparency for backgrounds
# Ensure command is executable
chmod +x scripts/commands/pine-debug.js
# Test basic functionality
node scripts/commands/pine-debug.js --help// Extend PineScriptDebugger class
class CustomDebugger extends PineScriptDebugger {
async customAnalysis(args) {
// Add custom debugging logic
}
}# Export data for external analysis
/pine-debug inspect --var "*" --format csv --output data.csv
# Import profiling results
/pine-debug profile --input external-profile.json// Debugging plugins can add:
// - New analysis methods
// - Custom visualization patterns
// - Integration with other tools
// - Advanced profiling techniques- Visual Debugging Interface - Web-based GUI for interactive debugging
- Backtesting Debugger - Step-through backtest execution
- Optimization Debugger - Visualize parameter optimization process
- Machine Learning Integration - AI-powered bug detection
- Collaborative Debugging - Real-time shared debugging sessions
- Custom debugging patterns
- Performance optimization techniques
- Integration with trading platforms
- Educational debugging exercises
- Benchmark datasets for testing
- This guide (
PINESCRIPT-DEBUGGING.md) - Example projects in
examples/pinescript-projects/debug-examples/ - Command help:
/pine-debug --help
- Run
/pine-validatefor initial debugging suggestions - Check example projects for patterns
- Use
/pine-debug helpersto generate debugging utilities - Refer to visualization patterns for inspiration
- Command issues: Check executable permissions and dependencies
- Debugging problems: Provide indicator code and debug output
- Feature requests: Describe use case and expected behavior
The PineScript debugging suite provides comprehensive tools for advanced indicator development:
✅ Immediate debugging capabilities with /pine-debug commands
✅ Professional debugging patterns with visualization library
✅ Enhanced validation with automatic debugging suggestions
✅ Performance profiling for optimization guidance
✅ Example projects for learning and reference
✅ Integration ready for development workflows
Start debugging with:
/pine-validate --file your-indicator.pine
/pine-debug helpers
/pine-debug inspect --var "*"Happy debugging! 🐛🔍🚀