Exporting Strategies
Learn how to export your trading strategies to MetaTrader 5 (MT5) and TradingView for live trading or further analysis.
Overview
Once you’ve developed and backtested a strategy in Lona, you can export it to popular trading platforms:
- MetaTrader 5 (MT5): Professional trading platform for forex, stocks, and futures
- TradingView: Popular charting platform with Pine Script support
The export system converts your strategy from Lona’s internal format to platform-specific code, ready for deployment.
Starting an Export
Where to Find Export
- Open your strategy from the Strategies section
- Look for the Export button in the strategy details panel
- Click to open the export dialog
Export Dialog
The export dialog has two main sections:
- Platform Selection: Choose between MT5 or TradingView
- Export Options: Configure how the export is processed
Choosing Your Platform
MetaTrader 5 (MT5)
Best For:
- Professional traders using MT5 terminals
- Forex and CFD trading
- Automated trading (Expert Advisors)
- Brokers that support MT5
Output: MQL5 source code (.mq5) and optionally compiled binary (.ex5)
TradingView
Best For:
- Chart-based trading
- Visual strategy analysis
- Alert-based trading
- Sharing strategies with community
Output: Pine Script v5 code (.pine)
Export Options
Common Options (Both Platforms)
Include Strategy Parameters
- What it does: Exports adjustable input parameters
- When enabled: Traders can modify settings without editing code
- Recommendation: Keep enabled for flexibility
Include Documentation
- What it does: Generates README with installation instructions
- When enabled: Includes step-by-step setup guide
- Recommendation: Keep enabled
MT5-Specific Options
Compile to Executable
- What it does: Compiles MQL5 source to binary .ex5 file
- When enabled: Ready-to-use file, no compilation needed by end user
- Trade-off: Takes extra processing time (30-60 seconds)
- When to use: Final production version, sharing with others
TradingView-Specific Options
Include Alert Conditions
- What it does: Adds alert() function calls for trading signals
- When enabled: Enables TradingView alert notifications
- Recommendation: Keep enabled if using alerts
The Export Process
After clicking Export, you’ll see real-time progress:
| Progress | Stage | Description |
|---|---|---|
| 10-20% | Analysis | AI analyzes your strategy structure |
| 30-40% | Event Mapping | Converts Lona events to platform equivalents |
| 50-60% | Code Generation | Creates platform-specific code |
| 70-75% | Validation | Checks code for errors |
| 85-90% | Compilation | Compiles to binary (MT5 only, if enabled) |
| 95-100% | Packaging | Creates downloadable archive |
Processing Time:
- Simple strategies: 30-60 seconds
- Complex strategies: 1-3 minutes
- MT5 compilation adds 30-60 seconds
Automatic Error Recovery
If the system detects validation errors:
- Automatically retries up to 3 times
- Each retry improves the generated code
- You can cancel if taking too long
Download and Files
What You Receive
When export completes, you’ll receive a ZIP archive containing:
For MT5 Exports:
strategy_name_mt5.zip
├── strategy_name.mq5 # MQL5 source code
├── strategy_name.ex5 # Compiled binary (if enabled)
├── metadata.json # Strategy analysis data
├── validation_report.json # Quality check results
└── README.txt # Installation instructionsFor TradingView Exports:
strategy_name_tradingview.zip
├── strategy_name.pine # Pine Script v5 code
├── metadata.json # Strategy analysis data
├── validation_report.json # Quality check results
└── README.txt # Installation instructionsDownload Link
- Success dialog appears with download button
- Download link valid for 24 hours
- Save the file before the link expires
Installing Exported Strategies
MT5 Installation
Step 1: Locate MT5 Data Folder
Windows:
C:\Users\[Username]\AppData\Roaming\MetaQuotes\Terminal\[Instance]\MQL5\ExpertsMac (with Wine):
~/Library/Application Support/MetaTrader 5/drive_c/Program Files/MetaTrader 5/MQL5/ExpertsStep 2: Copy Files
- Extract the ZIP archive
- Copy
.mq5file (and.ex5if available) to the Experts folder
Step 3: Enable in MT5
- Open MetaTrader 5
- View → Navigator (Ctrl+N)
- Expand “Expert Advisors”
- Find your strategy
- Double-click to attach to a chart
- Enable AutoTrading in toolbar
Note: If you only have .mq5, MT5 will compile it automatically on first use.
TradingView Installation
Step 1: Open Pine Editor
- Go to TradingView.com
- Open any chart
- Click “Pine Editor” at bottom of screen
Step 2: Add Your Strategy
- Extract the ZIP archive
- Open the .pine file in a text editor
- Copy all the code
- Paste into Pine Editor
- Click “Add to Chart”
Step 3: Configure Alerts (Optional)
- Click the three dots on your strategy
- Select “Add Alert”
- Choose alert conditions
- Set notification preferences
Understanding Export Files
metadata.json
Contains information about your strategy:
- Export ID and timestamp
- Detected indicators and parameters
- Strategy complexity assessment
- Event mappings used
validation_report.json
Quality assurance results:
- Pass/fail status
- Any errors or warnings found
- Suggestions for improvement
- Compilation results (MT5)
README.txt
Installation guide including:
- Platform-specific setup steps
- Parameter configuration help
- Troubleshooting tips
Supported Features
Technical Indicators
The export system supports common indicators:
- Moving Averages (SMA, EMA)
- RSI (Relative Strength Index)
- MACD
- Bollinger Bands
- Stochastic Oscillator
- ATR (Average True Range)
- And many more
Trading Events
Lona events are converted to platform equivalents:
| Lona Event | MT5 Handler | TradingView |
|---|---|---|
| on_bar_close | OnTick() | On each bar |
| on_position_opened | OnTradeTransaction() | strategy.entry() |
| on_position_closed | OnTradeTransaction() | strategy.close() |
Troubleshooting
”Export Failed” Error
Possible Causes:
- Strategy code has unresolved issues
- Network connection interrupted
- Server temporarily unavailable
Solutions:
- Verify your strategy runs successfully in backtest
- Check your internet connection
- Try again in a few minutes
”Validation Failed After Retries”
Possible Causes:
- Complex strategy logic difficult to convert
- Unsupported indicator or feature
Solutions:
- Simplify strategy if possible
- Download the partial export and modify manually
- Contact support for assistance
”Compilation Errors” (MT5)
Possible Causes:
- MQL5 syntax issues in generated code
- Missing dependencies
Solutions:
- Open .mq5 file in MetaEditor
- Review error messages
- Make manual corrections if needed
Download Link Expired
- Export links are valid for 24 hours
- Re-run the export to get a new download link
- Save exports locally as backup
Best Practices
Before Exporting
- Ensure backtest results are satisfactory
- Verify all parameters have reasonable defaults
- Test with different market conditions
- Document any special requirements
After Exporting
- Test in demo/paper trading first
- Verify indicator calculations match
- Check entry/exit signals fire correctly
- Monitor for any behavioral differences
Platform-Specific Tips
For MT5:
- Use compiled .ex5 for production
- Test on demo account before live
- Check spread and slippage settings
For TradingView:
- Test alert conditions manually first
- Verify bar timing matches expectations
- Check strategy tester results
Limitations
What Cannot Be Exported
- Strategies using unsupported data types
- Complex portfolio-level operations
- Real-time external data feeds
- Custom visualization components
Platform Differences
Exported strategies may behave slightly differently due to:
- Bar timing differences
- Order execution models
- Available indicator implementations
- Platform-specific limitations
Important: Always validate exported strategies with thorough testing before live trading.
Quick Reference
| Task | Where to Find It |
|---|---|
| Start Export | Strategy details → Export button |
| Choose Platform | Export dialog → Platform tab |
| Configure Options | Export dialog → Options section |
| Monitor Progress | Progress dialog during export |
| Download Result | Success dialog → Download button |
| View Installation Guide | README.txt in ZIP archive |
What’s Next?
After exporting your strategy:
- Test thoroughly in demo/paper trading mode
- Monitor performance and compare with backtests
- Iterate on parameters in the target platform
- Consider creating variations for different markets
Related Pages:
- Results & Analysis - Understand your backtest results before exporting
- Best Practices - Strategy optimization tips
- AI Model Selection - Choose the best AI model for code generation