The PineScript debugging tools provide comprehensive debugging capabilities for PineScript indicator development, including:
- Interactive debugging with breakpoints and step execution
- Variable inspection with real-time monitoring
- Performance profiling and complexity analysis
- Visual debugging with charts and plots
- Web-based interface for remote debugging
The debugging tools require Node.js and npm. Dependencies are already in package.json:
npm installThis installs:
express- Web server frameworksocket.io- Real-time communicationcodemirror- Code editor for web interfacechart.js- Live chart visualization
node scripts/commands/pine-debug.js server --port 3000node scripts/pinescript/debug-server.js --port 3000--port, -p- Port number (default: 3000)--file, -f- PineScript file to debug--project, -d- Project directory (default: current)--help, -h- Show help
Open your browser to:
- Main interface: http://localhost:3000/
- Debug interface: http://localhost:3000/debug
For full debugging features (validation, optimization, backtesting), configure your project:
node scripts/commands/pine-setup.jsThis will:
- Detect PineScript tools and versions
- Set up project configuration
- Enable all debugging features
Include debugging helpers in your PineScript files:
//@version=5
indicator("My Indicator", overlay=true)
// Include debug helpers
//@include "examples/pinescript-projects/debug-helpers/debug-helpers.pine"
//@include "examples/pinescript-projects/debug-helpers/debug-breakpoints.pine"
// Your indicator code here
rsi = ta.rsi(close, 14)
// Use debugging functions
debug.plot(rsi, "RSI", color=color.blue)
debug.setBreakpoint("rsi > 70", "Overbought")
# Inspect variables and their history
node scripts/commands/pine-debug.js inspect my-indicator.pine
# Trace variable values with plot code generation
node scripts/commands/pine-debug.js trace my-indicator.pine --variable rsi
# Monitor conditions and generate alerts
node scripts/commands/pine-debug.js monitor my-indicator.pine --condition "rsi > 70"
# Profile performance and complexity
node scripts/commands/pine-debug.js profile my-indicator.pine
# Generate debug helper library
node scripts/commands/pine-debug.js helpers --output my-debug-helpers.pine
# Start interactive debugging server
node scripts/commands/pine-debug.js server --port 3000 --file my-indicator.pine
# Run debugging tests
node scripts/commands/pine-debug.js test my-indicator.pine- Syntax highlighting for PineScript
- Breakpoint management (click gutter)
- Line numbers and navigation
- File loading from project
- Real-time variable values
- Type information
- Historical tracking
- Chart visualization
- Set/clear breakpoints
- Conditional breakpoints
- Hit count tracking
- Visual indicators
- Start/pause/stop debugging
- Step execution (bar-by-bar)
- Speed control (1x to 10x)
- Call stack viewing
- Real-time variable plotting
- Multiple variable support
- Time-based visualization
- Chart controls and clearing
- Debug messages
- Error reporting
- Execution logs
- User commands
debug.plot(value, label, color) // Plot variable
debug.plotShape(condition, label, ...) // Plot shapes
debug.plotchar(value, label, char) // Plot characters
debug.plotTable(title, rows) // Display table
debug.inspect(variable, label) // Inspect variable
debug.trace(variable, label) // Trace with history
debug.monitor(condition, label) // Monitor condition
debug.setBreakpoint(condition, label) // Set breakpoint
debug.clearBreakpoints() // Clear all breakpoints
debug.checkBreakpoints() // Check breakpoints
debug.startTimer(label) // Start performance timer
debug.stopTimer(label) // Stop and log timer
debug.profileSection(label) // Profile code section
debug.validate(condition, message) // Validate condition
debug.assert(condition, message) // Assert condition
debug.logError(message) // Log error
examples/pinescript-projects/debug-examples/complex-indicator-debug.pine- RSI + MACD + Composite indicator
- Integrated debugging throughout
- Breakpoint examples
- Performance profiling
examples/pinescript-projects/debug-examples/simple-test-indicator.pine- Basic indicator with intentional bugs
- Debugging helper usage
- Error detection examples
examples/pinescript-projects/debug-examples/interactive-debugging-demo.pine- Complete debugging demonstration
- All debug features in one file
- Step-by-step examples
examples/pinescript-projects/debug-helpers/visualization-patterns.pine- 10 standard visualization patterns
- Chart styling examples
- Plot configuration templates
Solution: Run /pine-setup or use basic debugging mode
node scripts/commands/pine-setup.jsSolution: Use a different port or check for existing processes
node scripts/pinescript/debug-server.js --port 3001Solution: Ensure correct include path
//@include "examples/pinescript-projects/debug-helpers/debug-helpers.pine"
Solution: Check browser console for errors and ensure numeric variables
Solution: Verify conditions are valid PineScript expressions
Check server output for:
- Port binding confirmation
- File loading status
- Connection events
- Error messages
Use browser dev tools for:
- WebSocket connection status
- JavaScript errors
- Network requests
- Console logs
Create .debug-config.json:
{
"port": 3000,
"projectPath": "./my-pinescript-project",
"defaultFile": "main.pine",
"chartMaxPoints": 100,
"debugLevel": "verbose"
}export PINE_DEBUG_PORT=3000
export PINE_DEBUG_PROJECT=/path/to/project
export PINE_DEBUG_FILE=indicator.pine- Copy debug helpers to your TradingView script
- Use include comments for organization
- Enable/disable debugging with input boolean
- Export debug data for analysis
// In debug.html, adjust maxPoints
function updateChart(variableName, value, maxPoints = 50) {debugEnabled = input.bool(false, "Enable Debugging")
if debugEnabled
debug.plot(rsi, "RSI")
debug.setBreakpoint("rsi > 70")
Group debug calls to reduce overhead:
// Instead of individual calls
debug.plot(rsi, "RSI")
debug.plot(sma, "SMA")
debug.plot(macd, "MACD")
// Use batch plotting
debug.plotMultiple([
[rsi, "RSI", color.blue],
[sma, "SMA", color.red],
[macd, "MACD", color.green]
])
Only debug when needed:
if bar_index % 10 == 0 // Every 10 bars
debug.inspect(rsi, "RSI Sample")
The debug server is designed for local development only. Do not expose it to the internet.
The server can read files in the project directory. Ensure sensitive files are excluded.
Socket.IO connections are limited to localhost by default.
The web interface has no authentication. Use only in trusted environments.
# Load example in debug server
node scripts/pinescript/debug-server.js --file examples/pinescript-projects/debug-examples/complex-indicator-debug.pine- Copy debug helpers to your project
- Add include statements to your indicators
- Start debugging server
- Load your indicator in the web interface
- Modify debug helper functions
- Add custom visualization
- Extend the web interface
- Integrate with your workflow
- This guide (
SETUP-DEBUGGING.md) - Example projects in
examples/pinescript-projects/ - Code comments in debug helper files
Enable verbose logging:
node scripts/pinescript/debug-server.js --verboseCheck browser console for client-side issues.
Include:
- Server logs
- Browser console output
- PineScript file
- Steps to reproduce
These debugging tools are part of the everything-opencode project. See main project license for details.
Happy Debugging! 🐛🔧