Diff Viewer
The Diff Viewer shows you exactly what the AI wants to change before you apply it. This gives you full control over modifications to your code.
How It Works
Section titled “How It Works”When the AI suggests code changes:
- AI returns a diff — Changes are shown as additions/deletions
- Diff viewer displays — You see the before/after comparison
- You decide — Apply, dismiss, or ask for modifications
┌─────────────────────────────────────────────┐│ Current Code │ Suggested Code │├─────────────────────────────────────────────┤│ rsi = ta.rsi(close,14)│ rsi = ta.rsi(close,14)│- entry = rsi < 30 │+ entry = rsi < 30 and│ │+ volume > avgVol│ if entry │ if entry└─────────────────────────────────────────────┘Visual Indicators
Section titled “Visual Indicators”Line Colors
Section titled “Line Colors”| Color | Meaning |
|---|---|
| 🟢 Green | New code being added |
| 🔴 Red | Existing code being removed |
| ⚪ Gray | Unchanged context lines |
Line Prefixes
Section titled “Line Prefixes”| Prefix | Meaning |
|---|---|
+ | Addition |
- | Deletion |
| (space) | Unchanged |
Viewing Modes
Section titled “Viewing Modes”Side-by-Side
Section titled “Side-by-Side”Shows current code on the left, suggested code on the right.
Best for:
- Comparing large blocks of code
- Understanding structural changes
- Wide screens
Inline
Section titled “Inline”Shows changes inline with additions/deletions highlighted.
Best for:
- Small changes
- Quick review
- Narrow screens
Actions
Section titled “Actions”Accepts all changes and modifies your script.
Keyboard: Ctrl/Cmd + Enter (when diff is focused)
What happens:
- Deletions are removed
- Additions are inserted
- Diff viewer closes
- Editor shows updated code
Dismiss
Section titled “Dismiss”Rejects the changes without modifying your script.
Keyboard: Escape
What happens:
- Diff viewer closes
- Original code unchanged
- AI suggestion cleared
Request Changes
Section titled “Request Changes”If the suggestion isn’t quite right:
- Keep the diff open
- Type your feedback in chat
- AI responds with a revised diff
Example:
“This looks good but add a volume filter too”
Understanding Diffs
Section titled “Understanding Diffs”Simple Change
Section titled “Simple Change”rsi = ta.rsi(close, 14)rsi = ta.rsi(close, 21)Meaning: The RSI period is changing from 14 to 21.
Addition
Section titled “Addition”strategy.entry("Long", strategy.long, when=longCondition)strategy.exit("Long Exit", "Long", stop=stopPrice)Meaning: A new line is being added (exit logic).
Multiple Changes
Section titled “Multiple Changes”//@version=6indicator("My Indicator")strategy("My Strategy", overlay=true)
rsi = ta.rsi(close, 14)plot(rsi)
longCondition = rsi < 30if longCondition strategy.entry("Long", strategy.long)Meaning: Converting an indicator to a strategy with entry logic.
Working with Large Diffs
Section titled “Working with Large Diffs”Scrolling
Section titled “Scrolling”Use the scrollbar to review all changes. Context lines help you understand where changes occur.
Focusing on Changes
Section titled “Focusing on Changes”Look for colored sections:
- Skip gray unchanged sections
- Focus on green (additions) and red (deletions)
When to Be Careful
Section titled “When to Be Careful”Common Scenarios
Section titled “Common Scenarios”Fixing an Error
Section titled “Fixing an Error”You asked: “Fix the error on line 15”
Expected diff: Small, targeted change near line 15
Red flag: Large changes throughout the file
Adding a Feature
Section titled “Adding a Feature”You asked: “Add a stop loss”
Expected diff: A few new lines adding exit logic
Red flag: Changes to unrelated entry logic
Refactoring
Section titled “Refactoring”You asked: “Refactor this code for clarity”
Expected diff: Reorganization with same functionality
Red flag: Added or removed trading logic
After Applying
Section titled “After Applying”Undo Support
Section titled “Undo Support”If you apply a change and realize it’s wrong:
- Press
Ctrl/Cmd + Zto undo - The entire AI change is reverted as one step
- Your original code is restored
Validate After Apply
Section titled “Validate After Apply”Always validate after applying AI changes:
- Apply the suggestion
- Click Validate
- Fix any new errors
Tips for Better Reviews
Section titled “Tips for Better Reviews”Read the Explanation First
Section titled “Read the Explanation First”The AI usually explains what it’s changing:
“I’ve updated your RSI strategy to include a volume filter. The entry condition now requires both RSI below 30 AND volume above the 20-period average.”
Understanding the intent helps you review the code.
Check Entry/Exit Logic
Section titled “Check Entry/Exit Logic”Always verify that:
- Entry conditions match your requirements
- Exit conditions are correct
- Risk management is preserved
Test Incrementally
Section titled “Test Incrementally”For complex changes:
- Apply one feature at a time
- Validate between changes
- Test in TradingView periodically
Troubleshooting
Section titled “Troubleshooting”Diff Won’t Apply
Section titled “Diff Won’t Apply”Causes:
- Code changed since AI response
- Conflict between changes
- Malformed diff from AI
Solutions:
- Re-request the change in a new message
- Copy the suggested code manually
- Clear the diff and try again
Diff Shows Wrong Lines
Section titled “Diff Shows Wrong Lines”Causes:
- AI referenced different code version
- Context mismatch
Solutions:
- Share your current code again
- Ask AI to regenerate based on current state
Applied Wrong Changes
Section titled “Applied Wrong Changes”Solutions:
- Immediately press
Ctrl/Cmd + Z - Review the original diff
- Ask AI to try again with clearer requirements
Related Sections
Section titled “Related Sections”- AI Chat Panel — Getting better suggestions
- Editor Workspace — Undo/redo support
- Code Validation — Validating after changes