🚀 Build a 24/7 AI Forex Trading Bot with TradingAgents and VPS (Full Deployment Tutorial)
📌 Introduction
Ever thought about letting AI analyze the market, generate signals, and place trades while you sleep?
TradingAgents.jl is a powerful reinforcement learning framework built with Julia, helping you develop smart trading strategies. Meanwhile, a Forex VPS provides a stable, 24/7 runtime environment.
This tutorial will walk you through:
- Deploying TradingAgents.jl on a VPS
- Passing trading signals to MT5
- Executing real trades automatically
With just a one-time setup, you can build a fully autonomous trading bot that never goes offline!
🧠 Step 1: What You’ll Need
- A Forex VPS (Linux preferred; Windows optional, e.g., LightNode, Vultr)
- Julia installed (v1.6 or higher)
- Python installed (v3.8 or higher recommended)
- MetaTrader 5 (MT5) installed + a real or demo account
- Basic knowledge of Linux terminal
🔧 Step 2: Overall Architecture
We will split the system into two parts:
TradingAgents (Julia) — Generates trading signals
↓
Writes to a shared file
signal.txt
↓
Python script reads signals → Executes MT5 trade via API
This bridges AI strategy output to real-world trade execution.
🟩 Step 3: Deploy TradingAgents.jl on VPS
1. Install Julia and required packages
Run the following commands on your Ubuntu VPS:
# Install Julia
sudo apt update
sudo apt install julia -y
# Launch Julia and install packages
julia
] add TradingAgents ReinforcementLearning Dates
Exit Julia and create the project directory:
mkdir ~/trading_bot && cd ~/trading_bot
2. Create strategy script agent.jl
# agent.jl
using Dates
function run_strategy()
signal = rand(["BUY", "SELL", "HOLD"]) # Simulated signal
price = round(rand(1.080:0.0001:1.090), digits=5)
open("signal.txt", "w") do f
write(f, "$(Dates.now()),$signal,$price")
end
end
while true
run_strategy()
sleep(300) # Run every 5 minutes
end
🟨 Step 4: Create MT5 Auto-Trading Script (Python)
1. Install MT5 Python Module
pip install MetaTrader5
⚠️ Note: MetaTrader 5 must run on Windows. If your VPS runs Linux, you can use Wine + GUI, or choose a dual-OS VPS (e.g., LightNode).
2. Create Python script mt5_bridge.py
import MetaTrader5 as mt5
import time
import os
MT5_SYMBOL = "EURUSD"
LOT = 0.1
# Initialize MT5
mt5.initialize()
mt5.login(account_number, password="your_password", server="your_server")
def send_order(signal, price):
if signal == "BUY":
order_type = mt5.ORDER_TYPE_BUY
elif signal == "SELL":
order_type = mt5.ORDER_TYPE_SELL
else:
return
request = {
"action": mt5.TRADE_ACTION_DEAL,
"symbol": MT5_SYMBOL,
"volume": LOT,
"type": order_type,
"price": price,
"deviation": 10,
"magic": 100234,
"comment": "TradingAgentsBot",
"type_time": mt5.ORDER_TIME_GTC,
"type_filling": mt5.ORDER_FILLING_IOC,
}
result = mt5.order_send(request)
print("Order result:", result)
# Monitor signal.txt and place order
last_signal = ""
while True:
if os.path.exists("signal.txt"):
with open("signal.txt", "r") as f:
content = f.read().strip()
if content and content != last_signal:
timestamp, signal, price = content.split(",")
send_order(signal, float(price))
last_signal = content
time.sleep(10)
🛠️ Step 5: Automate Running (Recommended: tmux)
# Start the strategy script
tmux new -s agent
julia agent.jl
# Open new tmux window to run MT5 bridge
tmux new -s mt5
python3 mt5_bridge.py
Alternatively, use supervisor
or systemd
for startup automation.
🌍 Step 6: Recommended VPS Providers (for this setup)
- Hourly billing supported
- 40+ global locations (low latency from São Paulo / Tokyo)
- Linux + Windows available
- Fast deployment, perfect for EA hosting
📦 Step 7: Advanced Suggestions
- Replace
signal.txt
with SQLite or Redis for better stability - Log every signal and trade for tracking and debugging
- Use Docker to containerize and migrate the setup easily
- Add a basic dashboard UI to monitor trading status (optional)
✅ Conclusion: AI-Powered Trading Is No Longer a Dream
With this guide, you can deploy TradingAgents-based strategies on a VPS and execute real trades via MT5.
24/7 uptime, low latency, full automation, and intelligent decision-making—this is how you gain the edge over traditional traders!