How to Create a Trading Bot for MT5 (No Coding Required)
By HorizonAI Team
Want to automate your trading strategy on MetaTrader 5 but don't know MQL5? You don't need to. With AI-powered tools like HorizonAI, you can describe your strategy in plain English and get a working Expert Advisor (EA).
This guide walks you through the entire process—from idea to live automation.
What is an MT5 Trading Bot?
An MT5 trading bot (called an Expert Advisor or EA) is a program that automatically executes trades on your behalf based on predefined rules.
What EAs can do:
- Monitor markets 24/7
- Execute trades automatically
- Manage positions (stop loss, take profit, trailing stops)
- Apply complex entry/exit logic
- Trade while you sleep
What you need:
- MetaTrader 5 platform (free)
- A broker account supporting MT5
- Your trading strategy defined
- An EA file (.ex5)
You don't need to code the EA yourself. HorizonAI generates the MQL5 code for you—just describe what you want.
Step 1: Define Your Strategy
Before generating any code, clearly define your trading rules. The more specific, the better the bot.
Questions to Answer
Entry Rules:
- What triggers a buy signal?
- What triggers a sell signal?
- Any filters? (time, trend, volatility)
Exit Rules:
- Where is your stop loss?
- Where is your take profit?
- Do you use trailing stops?
- Any time-based exits?
Position Sizing:
- Fixed lot size or risk-based?
- What percentage of account per trade?
Example Strategy Definition
Strategy: EMA Crossover with RSI Filter
Entry Rules:
- Long: 9 EMA crosses above 21 EMA AND RSI(14) > 50
- Short: 9 EMA crosses below 21 EMA AND RSI(14) < 50
Exit Rules:
- Stop Loss: 2x ATR(14) from entry
- Take Profit: 4x ATR(14) from entry (2:1 R:R)
- Trailing Stop: Activate at 1R, trail at 1.5x ATR
Position Sizing:
- Risk 1% of account per trade
Settings:
- Pairs: EURUSD, GBPUSD, USDJPY
- Timeframe: H1
- Max trades: 1 per symbol
Step 2: Generate Your EA with HorizonAI
Now turn your strategy into code without writing a single line.
2.1 Create a New Script
- Go to HorizonAI and sign in
- Click New Script
- Select MT5 (MQL5) as your target language
2.2 Describe Your Strategy
In the chat, describe your strategy in detail. Be specific:
Good prompt:
Create an MT5 Expert Advisor with these rules:
Entry:
- Go long when 9 EMA crosses above 21 EMA and RSI(14) is above 50
- Go short when 9 EMA crosses below 21 EMA and RSI(14) is below 50
Exit:
- Stop loss at 2x ATR(14) from entry price
- Take profit at 4x ATR(14) from entry price
Position sizing:
- Use fixed lot size of 0.1 lots
Additional:
- Only trade on H1 timeframe
- Add input parameters for EMA periods, RSI period, lot size
- Include proper error handling
Bad prompt:
Make me a trading bot
Pro tip: More detail = better results. Include exact indicator settings, stop/take profit logic, and any special conditions.
2.3 Review and Iterate
HorizonAI generates the MQL5 code. Review it and ask for changes:
- "Add a trailing stop that activates after 1R profit"
- "Only allow one trade per symbol at a time"
- "Add a time filter—only trade between 8:00 and 17:00 server time"
Keep iterating until the strategy matches your requirements.
Step 3: Export Your EA
Once satisfied with the code:
- Click Download or Copy in HorizonAI
- Save the file as
YourStrategyName.mq5 - Keep this file—you'll import it into MT5
Step 4: Set Up MetaTrader 5
If you haven't already, install and configure MT5.
4.1 Download MT5
- Download from MetaTrader 5 website or your broker
- Install and open the platform
- Log in with your broker account (demo first!)
4.2 Open MetaEditor
MetaEditor is where you'll compile your EA:
- In MT5, press F4 or go to Tools → MetaQuotes Language Editor
- MetaEditor opens in a new window
4.3 Import Your EA Code
- In MetaEditor, go to File → New → Expert Advisor
- Give it a name and click Finish
- Delete the template code
- Paste your HorizonAI-generated code
- Save the file (Ctrl+S)
4.4 Compile
- Press F7 or click Compile
- Check the Errors tab at the bottom
- If errors exist, copy them back to HorizonAI: "Fix these compile errors: [paste errors]"
- Repeat until compilation succeeds (0 errors)
Note: Warnings are okay—they won't stop your EA. Errors must be fixed.
Step 5: Backtest Your EA
Never trade live without thorough backtesting.
5.1 Open Strategy Tester
- In MT5, press Ctrl+R or go to View → Strategy Tester
- The tester panel appears (usually at bottom)
5.2 Configure the Test
- Expert: Select your EA from the dropdown
- Symbol: Choose a pair (e.g., EURUSD)
- Timeframe: Match your strategy (e.g., H1)
- Date range: At least 1-2 years of data
- Model: "Every tick" for accuracy
- Deposit: Set realistic starting balance
5.3 Run the Backtest
- Click Start
- Wait for completion
- Review results in the tabs:
- Results: Every trade
- Graph: Equity curves
- Report: Key metrics
Key Metrics to Evaluate
- Profit Factor: Good > 1.5, Warning < 1.0 (losing)
- Max Drawdown: Good < 20%, Warning > 40%
- Win Rate: Depends on R:R, context matters
- Total Trades: Good > 100, Warning < 30 (not enough data)
Important: A profitable backtest doesn't guarantee live results. Always test on demo before real money.
Step 6: Demo Trading
Before risking real money, prove your EA works in real-time.
6.1 Open a Demo Account
Most brokers offer free demo accounts with virtual money.
6.2 Attach EA to Chart
- In MT5, open a chart for your symbol (e.g., EURUSD H1)
- In Navigator panel (Ctrl+N), find your EA under Expert Advisors
- Drag the EA onto the chart
- Configure settings and enable Allow Algo Trading
- Click OK
6.3 Enable Auto Trading
- Click Algo Trading button in toolbar (must be green/enabled)
- Your EA is now running
6.4 Monitor Performance
- Watch for at least 20-50 trades
- Compare to backtest expectations
- Note any differences
Step 7: Go Live (Carefully)
When demo results match expectations:
Pre-Live Checklist
- [ ] Backtested on 2+ years of data
- [ ] Demo traded for 20+ trades
- [ ] Demo results match backtest within 20%
- [ ] Understand maximum expected drawdown
- [ ] Prepared to lose your risk capital
- [ ] Have monitoring system in place
Start Small
- Begin with minimum lot size
- Risk only what you can afford to lose
- Scale up gradually
Consider a VPS
For 24/7 trading, run MT5 on a Virtual Private Server:
- Low latency to broker
- Always-on
- Costs $10-50/month
Common Issues and Fixes
EA Not Trading
Check:
- Algo Trading enabled (green button)
- EA enabled on chart
- Correct symbol and timeframe
- Account has sufficient margin
- Check Experts tab for errors
Compile Errors
Solution:
- Copy error messages
- Paste into HorizonAI: "Fix these errors: [paste]"
- Replace code and recompile
Different Live vs Backtest Results
Common causes: Slippage, spread differences, requotes
Mitigation: Add slippage buffer to backtest, use wider stops
Example Prompts for HorizonAI
Basic Strategies
Create an MT5 EA that:
- Buys when RSI(14) goes below 30 then crosses above 30
- Sells when RSI(14) goes above 70 then crosses below 70
- Stop loss: 50 pips
- Take profit: 100 pips
- Lot size: 0.1
Advanced Features
Add these features to my EA:
- Trailing stop that activates after 1R profit
- Move stop to breakeven after 0.5R
- Only trade Monday through Thursday
- Max 2 trades per day
- Close all trades before Friday 5pm
Risk Management
Add these safety features:
- Maximum daily loss: 3% of account (stop trading if hit)
- Maximum drawdown: 10% (stop trading if hit)
- Cool-off period: 4 hours after 3 consecutive losses
Try it free →
FAQs
How much does it cost to create a trading bot?
With HorizonAI, you can create basic EAs for free. The MT5 platform is free. Your broker may have minimum deposit requirements.
Can I run multiple EAs at once?
Yes. Attach different EAs to different charts, or use one EA on multiple symbols.
Will my EA work with any broker?
Most MT5 EAs work across brokers, but test with your specific broker first.
Can the EA trade while my computer is off?
No—unless you use a VPS. The EA runs within MT5, which must be running.
Is automated trading legal?
In most jurisdictions, yes. Check your broker's terms and local regulations.
Summary
Creating an MT5 trading bot without coding:
- Define your strategy clearly (entries, exits, sizing)
- Generate MQL5 code with HorizonAI
- Compile in MetaEditor (fix any errors)
- Backtest thoroughly (2+ years of data)
- Demo trade (20+ trades minimum)
- Go live with small size, scale gradually
- Monitor regularly, adjust as needed
The barrier to automated trading has never been lower. Start with demo, prove your edge, and scale responsibly.
Have questions about MT5 bots? Join our Discord to discuss with other traders!
