Perplexity × MT5: AI Trading Bot, No Pixie Dust

Simple AI Trading Bot (Perplexity + MT5)

:world_map: One-Line Flow: Ask Perplexity “what’s the vibe?” → Check MT5 charts → Decide BUY/SELL/WAIT → Execute (safely)


:test_tube: 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.


:high_voltage: Why It’s Awesome

:white_check_mark: You don’t need to guess → news + charts fuse together
:white_check_mark: Risk rules stop you from blowing the account
:white_check_mark: Starts simple → you can add more fancy tricks later
:white_check_mark: Paper trading first → practice with fake money


:rocket: 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

:laptop: 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}")

:bullseye: How Decisions Work

Perplexity Says MT5 Charts Say Bot Decision
Bullish Bullish BUY :green_circle:
Bearish Bearish SELL :red_circle:
Mixed signals Mixed signals WAIT :yellow_circle:

Simple rule: Only trade when both brains agree.


:gear: 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

:shield: 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

:cross_mark: This is not magic → You will have losing trades
:cross_mark: Start small → Even experts lose money learning
:cross_mark: Test everything → Paper trade for at least 1 month
:white_check_mark: Stay patient → Good trades are rare, bad trades are common


:books: Learn More

Essential Links:

Upgrade Path:

  1. Week 1-2: Run this simple version, understand the basics
  2. Week 3-4: Add more indicators (RSI, MACD)
  3. Month 2: Add proper risk management
  4. Month 3: Consider live trading (if profitable on paper)

:chequered_flag: Next Steps

  1. Copy the code → Save as simple_bot.py
  2. Get your API keys → Perplexity + MT5 demo account
  3. Run in paper mode → Let it trade fake money for 2 weeks
  4. Track results → Are you making fake profits consistently?
  5. 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. :robot:

5 Likes

Any idea on how to setup the stop loss?