Code Validation
The Code Validation feature checks your Pine Script against TradingView’s actual compiler, catching errors before you copy your code to the platform.
How It Works
Section titled “How It Works”Your Code → Algo Trade Analytics → TradingView Compiler → Results ↓ Errors, Warnings, InfoThe system sends your code to TradingView’s validation endpoint and returns:
- Errors — Must be fixed before the script will compile
- Warnings — Code works but has potential issues
- Info — Suggestions and best practices
Manual Validation
Section titled “Manual Validation”Running Validation
Section titled “Running Validation”Click the ✓ Validate button in the editor toolbar.
Process:
- Your code is sent for validation
- A loading indicator appears
- Results display in the validation panel
Validation Panel
Section titled “Validation Panel”✓ Script is valid──────────────────────────────────────────No errors or warnings detected.Or with issues:
❌ 2 Errors | ⚠️ 1 Warning──────────────────────────────────────────Line 15: Undeclared identifier 'rsi_val' [Fix with AI]Line 23: Cannot call 'security' with argument... [Fix with AI]──────────────────────────────────────────Line 45: Consider using 'request.security' instead [Info]Auto-Validation
Section titled “Auto-Validation”When enabled, your code validates automatically after changes.
Enabling Auto-Validation
Section titled “Enabling Auto-Validation”- Click the ⚙️ settings icon in the toolbar
- Toggle Auto-Validation on
How It Works
Section titled “How It Works”- You stop typing for 600ms
- Validation runs automatically
- Results update in the panel
Error Types
Section titled “Error Types”Syntax Errors
Section titled “Syntax Errors”Missing brackets, incorrect keywords, malformed expressions.
Example:
Line 10: Mismatched input '(' expecting ')'Common causes:
- Unclosed parentheses or brackets
- Missing commas in function calls
- Typos in keywords
Undeclared Identifiers
Section titled “Undeclared Identifiers”Using variables or functions that don’t exist.
Example:
Line 15: Undeclared identifier 'rsi_val'Common causes:
- Typo in variable name
- Using variable before declaration
- Missing function import
Type Errors
Section titled “Type Errors”Using incompatible data types.
Example:
Line 23: Cannot call 'strategy.entry' with argument 'qty'=stringCommon causes:
- Passing string where number expected
- Using series where simple required
- Incorrect function signatures
Deprecated Function Warnings
Section titled “Deprecated Function Warnings”Using outdated Pine Script functions.
Example:
Line 45: 'security' is deprecated. Use 'request.security' instead.Common in:
- Code migrated from older Pine Script versions
- Copy-pasted examples from old tutorials
- Legacy strategies being updated
Fix with AI
Section titled “Fix with AI”Each error and warning includes a Fix with AI button.
How It Works
Section titled “How It Works”-
Click Fix with AI
Section titled “Click Fix with AI”The error details are sent to the AI chat.
-
AI Analyzes
Section titled “AI Analyzes”The AI examines:
- The error message
- The surrounding code
- Your script context
-
Receive Fix
Section titled “Receive Fix”The AI returns a diff showing the proposed fix.
-
Apply or Dismiss
Section titled “Apply or Dismiss”Review the change and apply if correct.
Example Fix
Section titled “Example Fix”Error:
Line 15: Undeclared identifier 'rsi_val'AI Response:
entry_condition = rsi_val < 30entry_condition = rsi_value < 30Explanation: “The variable rsi_val doesn’t exist. Based on line 8 where you declared rsi_value, this appears to be a typo.”
TradingView Username
Section titled “TradingView Username”Why Configure It?
Section titled “Why Configure It?”Providing your TradingView username enables:
- More accurate validation results
- Access to your saved libraries
- Better script compatibility checking
How to Configure
Section titled “How to Configure”- Go to Account Settings
- Navigate to Integrations or TradingView
- Enter your TradingView username
- Save settings
Common Validation Scenarios
Section titled “Common Validation Scenarios”Script Won’t Compile
Section titled “Script Won’t Compile”❌ 5 ErrorsAction: Fix errors one at a time, starting from the first. Often, later errors are caused by earlier ones.
Warnings but No Errors
Section titled “Warnings but No Errors”✓ Valid | ⚠️ 3 WarningsAction: Warnings won’t prevent compilation, but review them:
- Deprecated functions should be updated
- Potential bugs should be investigated
- Style suggestions can be ignored if intentional
No Issues Found
Section titled “No Issues Found”✓ Script is validAction: Safe to copy to TradingView. Note that validation doesn’t guarantee the strategy works correctly—only that it compiles.
Validation vs. TradingView
Section titled “Validation vs. TradingView”What’s Checked
Section titled “What’s Checked”| Validation Catches | TradingView Also Checks |
|---|---|
| ✅ Syntax errors | ✅ Syntax errors |
| ✅ Type mismatches | ✅ Type mismatches |
| ✅ Undefined variables | ✅ Undefined variables |
| ✅ Deprecated functions | ✅ Deprecated functions |
| ❌ Runtime errors | ✅ Runtime errors |
| ❌ Series length issues | ✅ Series length issues |
What May Differ
Section titled “What May Differ”Some errors only appear in TradingView:
- Data-dependent errors — Errors that depend on actual chart data
- Runtime limits — Memory or execution time limits
- Indicator-specific issues — Problems with overlay settings
Best Practices
Section titled “Best Practices”Validate Often
Section titled “Validate Often”- After each significant change
- Before copying to TradingView
- After applying AI suggestions
Fix Systematically
Section titled “Fix Systematically”- Address errors first (required)
- Review warnings (recommended)
- Consider info suggestions (optional)
Use Fix with AI
Section titled “Use Fix with AI”Don’t waste time debugging manually:
- Click “Fix with AI”
- Review the suggestion
- Apply if correct
The AI often provides context and explanations that help you learn.
Troubleshooting
Section titled “Troubleshooting”Validation Takes Too Long
Section titled “Validation Takes Too Long”Causes:
- Large script
- Network issues
- TradingView API delays
Solutions:
- Wait a moment and retry
- Check your internet connection
- Reduce script size if possible
Validation Returns Empty
Section titled “Validation Returns Empty”Causes:
- Empty script
- Network failure
- API timeout
Solutions:
- Ensure script has content
- Refresh the page
- Check console for errors
Related Sections
Section titled “Related Sections”- Editor Workspace — Editor features
- AI Chat Panel — AI assistance
- Troubleshooting — Common issues