pine-debugger
Troubleshoots Pine Script issues and adds debugging capabilities. Use when scripts have errors or unexpected behavior.
By traderspost · 387 installs
npx skills add traderspost/pinescript-agents --skill pine-debugger
Source repository · Upstream listing
Pine Script Debugger
Specialized in adding debugging tools and troubleshooting Pine Script code in TradingView's often opaque environment.
⚠️ Pine Script v6 2025 Common Pitfalls
CRITICAL: March 2025 Breaking Change For Loop Boundaries
for loops now re evaluate boundaries every iteration .
PREFERRED FIX: Use for...in loops:
FALLBACK: Cache boundary if traditional for is required:
Debug check: If a loop seems to hang, either switch to for...in or verify boundaries are cached.
Line Continuation Errors
The most common syntax error. Updated rules as of December 2025:
Bid/Ask Variables Return NA
Plot in Local Scope
Core Debugging Toolkit
1. Label Based Value Inspector
2. Table Based Variable Monitor
3. Loop Iteration Debugger
4. Repainting Detector
5. NA Value Tracker
6. Security Function Debugger
7. Input Active State Debugger (July 2025)
UDT Debugging Techniques
1. UDT State Inspector
2. UDT Array Inspector Table
3. Time vs Bar Index Comparison Debugger
4. Drawing Object Status Debugger
5. UDT Creation Flow Debugger
6. xloc.bar time vs xloc.bar index Validator
Common Issues and Solutions
1. Infinite Loop (March 2025)
Symptom: Script hangs or times out
2. Unexpected NA Values
Symptom: Calculations return na unexpectedly
3. Security Function Issues
Symptom: Wrong values from higher timeframe
4. Historical vs Real time Mismatch
Symptom: Strategy works in backtest, fails live
5. String Too Long (Pre August 2025)
Symptom: String truncation errors
Debug Mode Implementation
Debugging Workflow
1. Identify Symptom
Compilation error?
Runtime error?
Wrong values?
Performance issue?
2. Check 2025 Breaking Changes
For loop boundaries (March 2025)
Line continuation rules
Bid/ask availability
3. Add Debug Points
Labels at key calculations
Table for variable monitoring
Plot intermediate values
4. Trace Execution
Follow calculation flow
Check condition evaluations
Monitor state changes
5. Test Edge Cases
First bars (bar index == 0)
NA values
Real time vs historical
Different timeframes
6. Clean Up
Wrap debug code in if debugMode
Or remove before publishing
Quick Reference: Error Messages
Error Likely Cause Fix
"end of line without line continuation" Split ternary or wrong indentation Keep ternary on one line, use 5 space indent
"Cannot use 'plot' in local scope" plot() inside if/for/function Use plot(condition ? value : na)
"Loop too long" Dynamic boundary in for loop Cache boundary or use for...in
"String is too long" String 40,960 chars Chunk string or reduce content
"na" everywhere NA propagation Add NA checks at each step
Drawing doesn't appear bar index 5000 bars back Use xloc.bar time instead
UDT line is na Forgot to assign after line.new() Use := to assign drawing to UDT field
UDT Specific Debugging Checklist
[ ] Are time values being captured when events occur (not later)?
[ ] Are both time AND bar index stored (for drawing + calculation)?
[ ] Are drawing objects using xloc.bar time ?
[ ] Is delete() being called before draw() ?
[ ] Are UDT methods using this.field := for assignments?
[ ] Is the UDT array being iterated with for...in ?
TradingView's environment is opaque. Always test thoroughly and provide multiple debugging approaches.