Context & Attachments
Context attachments allow you to share additional information with the AI beyond just your chat message. This includes code selections, full scripts, images, and most powerfully—your execution analysis reports.
Why Attachments Matter
Section titled “Why Attachments Matter”The AI can only see what you share. Attachments provide:
- Precision — Point the AI at exactly what you’re asking about
- Data-Driven Insights — Let the AI analyze your actual trading performance
- Visual Context — Share screenshots of charts or error messages
- Multi-File Awareness — Reference code from multiple script tabs
Attachment Types
Section titled “Attachment Types”Full Script
Section titled “Full Script”Shares the complete contents of a script tab.
When to use:
- Starting a new conversation about a strategy
- Asking for a comprehensive review
- Requesting refactoring of the entire script
How to attach:
- Click the 📎 button in the chat input
- Select “Share Active Tab” or choose a specific tab
- The script appears in your context area
Code Selection
Section titled “Code Selection”Shares only the highlighted portion of your code.
When to use:
- Asking about a specific function
- Debugging a particular section
- Requesting changes to targeted code
How to attach:
- Select code in the editor
- Click “Share Selection” in the chat toolbar
- The selection appears with line numbers
Images
Section titled “Images”Upload screenshots or diagrams.
When to use:
- Sharing TradingView chart screenshots
- Showing error dialogs
- Providing visual reference for desired output
How to attach:
- Click the 📎 button
- Select “Add Image”
- Choose a file from your computer
Supported formats: PNG, JPG, GIF, WebP
Analysis Reports
Section titled “Analysis Reports”Attach saved execution reports from Backtest vs Alerts or Alerts vs Fills.
When to use:
- Optimizing strategy based on real performance data
- Debugging discrepancies between backtest and live
- Getting AI recommendations for execution improvements
How to attach:
- Click the 📊 button
- Search or browse your saved reports
- Select a report to attach
Report Integration Deep Dive
Section titled “Report Integration Deep Dive”This is the most powerful feature of the AI Editor—feeding your actual trading data to the AI.
What the AI Sees
Section titled “What the AI Sees”When you attach a report, the AI has access to:
| Data Point | Example |
|---|---|
| Symbol & Timeframe | BTCUSD, 15min |
| Date Range | 2024-01-01 to 2024-01-31 |
| Match Statistics | 85% match rate, 15 missed alerts |
| Discrepancy Patterns | ”Most misses occurred at market open” |
| Time Drift Analysis | Average drift of 45 seconds |
| Price Drift Analysis | Average drift of 0.3% |
Example Workflow
Section titled “Example Workflow”-
Run Analysis
Section titled “Run Analysis”Complete a Backtest vs Alerts analysis showing 82% match rate with missed alerts.
-
Save the Report
Section titled “Save the Report”Click “Save Snapshot” to preserve the analysis.
-
Open in AI Editor
Section titled “Open in AI Editor”Click “Open in AI Editor” or navigate manually.
-
Attach the Report
Section titled “Attach the Report”The report is automatically attached (or use the 📊 button).
-
Ask for Optimization
Section titled “Ask for Optimization”Based on the attached report, my strategy is missing 18%of alerts. The pattern shows most misses happen when RSIchanges rapidly. How can I fix this? -
Apply AI Suggestions
Section titled “Apply AI Suggestions”The AI analyzes your execution data and suggests specific code changes.
Sample AI Interaction
Section titled “Sample AI Interaction”You: Here’s my backtest report showing 15 missed alerts. Most occur during high volatility. What’s wrong with my strategy?
AI: Looking at your report, I see several patterns:
- Repainting Issue: Your RSI calculation may be reading future data
- Bar Timing: Alerts fire at bar close but your backtest assumes bar open
- Recommendation: Change
barstate.isconfirmedcheck…
[AI provides specific code diff]
Managing Attachments
Section titled “Managing Attachments”Viewing Active Context
Section titled “Viewing Active Context”Above the chat input, you’ll see all active attachments:
Context:├── 📄 RSI Strategy.pine (full) [×]├── 📄 Lines 45-67 (selection) [×]└── 📊 Backtest Report - Jan 2024 [×]Removing Attachments
Section titled “Removing Attachments”Click the × next to any attachment to remove it from context.
Stale Attachments
Section titled “Stale Attachments”If you modify your code after attaching it, the attachment becomes “stale”:
- Fresh — Code matches current editor state
- Stale — Code has changed since attachment
Token Budget
Section titled “Token Budget”AI models have limited context windows. The system automatically:
- Estimates tokens for each attachment
- Prioritizes based on recency and relevance
- Excludes older attachments if the budget is exceeded
Token indicators:
- Green: Within budget
- Yellow: Near limit
- Red: Some context excluded
Optimizing Token Usage
Section titled “Optimizing Token Usage”| Do | Don’t |
|---|---|
| Share relevant selections | Attach entire scripts unnecessarily |
| Remove old attachments | Keep stale context |
| Ask focused questions | Include unrelated reports |
Best Practices
Section titled “Best Practices”For Code Attachments
Section titled “For Code Attachments”- Be selective — Share only what’s relevant to your question
- Include context — If asking about a function, include its dependencies
- Keep it fresh — Re-share after making changes
For Report Attachments
Section titled “For Report Attachments”- Save important analyses — Reports must be saved to attach them
- Choose relevant reports — Attach reports that relate to your current work
- Reference the data — Tell the AI what specific aspects to focus on
For Images
Section titled “For Images”- Crop to relevant area — Don’t include unnecessary screen elements
- Use clear screenshots — Ensure text and charts are readable
- Describe the image — Tell the AI what you want it to focus on
Automatic Context
Section titled “Automatic Context”Some context is automatically shared without explicit attachment:
| Auto-Included | Description |
|---|---|
| Active Tab | Your currently selected script |
| Tab Names | List of all open script tabs |
| Chat History | Last 10 messages in conversation |
Related Sections
Section titled “Related Sections”- AI Chat Panel — Using the chat effectively
- Credits & Models — How context affects credits
- Backtest vs Alerts — Creating reports to attach