Simple AI Trading Bot (Perplexity + MT5)
One-Line Flow: Ask Perplexity “what’s the vibe?” → Check MT5 charts → Decide BUY/SELL/WAIT → Execute (safely)
What This Bot Really Does
Step 1: Ask Perplexity → “What’s the vibe on EURUSD?” (fundamentals & news)
Step 2: Ask MT5 → “Show me the candles + indicators” (technicals)
Step 3: Mix both answers → decide BUY / SELL / WAIT
Step 4: Run in paper mode (demo money) → later flip to real mode
Think of it like a GPS for trading: Perplexity = traffic news, MT5 = street map, Bot = driver that won’t speed into a wall.
Why It’s Awesome
You don’t need to guess → news + charts fuse together
Risk rules stop you from blowing the account
Starts simple → you can add more fancy tricks later
Paper trading first → practice with fake money
Quick Setup (15 Minutes)
1. Install Python Libraries
pip install requests pandas numpy MetaTrader5 ta
2. Get Your Keys
- Perplexity API: Sign up at perplexity.ai → get API key
- MT5 Broker: Open demo account → get login details
3. Set Environment Variables
export PPLX_API_KEY="your_perplexity_key"
export MT5_ACCOUNT=12345678
export MT5_PASSWORD="your_password"
export MT5_SERVER="broker_server_name"
4. Run The Bot
python simple_bot.py --symbol EURUSD --mode paper
The Simple Code
Basic Bot Structure
import requests
import MetaTrader5 as mt5
import os
# Connect to Perplexity
def ask_perplexity(symbol):
url = "https://api.perplexity.ai/chat/completions"
headers = {"Authorization": f"Bearer {os.getenv('PPLX_API_KEY')}"}
prompt = f"Is {symbol} bullish or bearish? Answer: bullish/bearish/neutral"
data = {
"model": "sonar",
"messages": [{"role": "user", "content": prompt}]
}
response = requests.post(url, headers=headers, json=data)
answer = response.json()["choices"]["message"]["content"]
return "bullish" if "bullish" in answer.lower() else "bearish" if "bearish" in answer.lower() else "neutral"
# Connect to MT5
def get_mt5_signal(symbol):
mt5.initialize()
rates = mt5.copy_rates_from_pos(symbol, mt5.TIMEFRAME_H1, 0, 50)
# Simple moving average crossover
prices = [r['close'] for r in rates]
short_ma = sum(prices[-10:]) / 10 # 10-period average
long_ma = sum(prices[-30:]) / 30 # 30-period average
if short_ma > long_ma:
return "bullish"
else:
return "bearish"
# Make Decision
def decide_trade(symbol):
perplexity_view = ask_perplexity(symbol)
mt5_view = get_mt5_signal(symbol)
# Both agree = strong signal
if perplexity_view == "bullish" and mt5_view == "bullish":
return "BUY"
elif perplexity_view == "bearish" and mt5_view == "bearish":
return "SELL"
else:
return "WAIT"
# Main
symbol = "EURUSD"
decision = decide_trade(symbol)
print(f"{symbol}: {decision}")
How Decisions Work
Perplexity Says | MT5 Charts Say | Bot Decision |
---|---|---|
Bullish | Bullish | BUY ![]() |
Bearish | Bearish | SELL ![]() |
Mixed signals | Mixed signals | WAIT ![]() |
Simple rule: Only trade when both brains agree.
Essential Settings
# config.yaml
symbols: ["EURUSD", "GBPUSD", "USDJPY"]
risk_per_trade: 1% # Never risk more than 1% per trade
max_trades_per_day: 3 # Don't overtrade
mode: "paper" # Start with fake money
check_every: 60 # Minutes between checks
Safety First
Built-in Protections
- Paper trading mode → Practice with demo money first
- Risk limits → Never bet more than 1% per trade
- Daily limits → Max 3 trades per day (avoid overtrading)
- Stop losses → Auto-exit if trade goes wrong
Reality Checks
This is not magic → You will have losing trades
Start small → Even experts lose money learning
Test everything → Paper trade for at least 1 month
Stay patient → Good trades are rare, bad trades are common
Learn More
Essential Links:
- Perplexity API Docs
- MetaTrader5 Python
- Trading Basics (Free course)
Upgrade Path:
- Week 1-2: Run this simple version, understand the basics
- Week 3-4: Add more indicators (RSI, MACD)
- Month 2: Add proper risk management
- Month 3: Consider live trading (if profitable on paper)
Next Steps
- Copy the code → Save as
simple_bot.py
- Get your API keys → Perplexity + MT5 demo account
- Run in paper mode → Let it trade fake money for 2 weeks
- Track results → Are you making fake profits consistently?
- Only then → Consider real money (start with $100)
Remember: The goal isn’t to get rich quick. The goal is to build a system that makes more good trades than bad trades over time.
EDITED BY @SRZ Everything is complete. 