00Hours
00Minutes
00Seconds

ENDING SOON: SAVE 20% ON YOUR FIRST VPS INVOICE

Menu
Build trading automations with MetaTrader and n8n workflows

Build Advanced Trading Automations with MetaTrader and N8N

Wire your MetaTrader platform to n8n for alerts, trade logging, signal routing, and risk checks. Concrete automation workflows you can ship today.

Thomas Vasilyev
(Updated: May 3, 2026)
Build trading automations with MetaTrader and n8n workflows

N8N MetaTrader 5 integration lets you fire a webhook out of MT5 the moment an order opens, closes, or hits a risk threshold — and then route that event through n8n into Telegram, Google Sheets, a database, an LLM, another broker’s API, or all of them in parallel. You wire the trigger inside MetaTrader. You build the logic visually inside n8n. You don’t write a custom backend.

Here’s what you can ship in an afternoon once the link is live:

  • Telegram alert the second a trade opens or closes, with symbol, lot size, and entry price.
  • Trade log writing every fill to Google Sheets or Postgres for journaling and post-trade analysis.
  • Daily drawdown risk cap that tells your EA to stop opening new positions past a 2% loss.
  • Signal routing from TradingView alerts into n8n, then into MT5 as a market order.
  • Broker connectivity health-check pinging your VPS every minute and paging you if MT5 falls offline.

This guide walks the integration end-to-end: what n8n is, the three components you need, the four-step build, five workflow recipes you can lift, and why the whole stack belongs on an always-on VPS rather than your laptop.

n8n MetaTrader 5 integration architecture: workflow canvas fanning trade events out to Slack, Postgres, and AI agent nodes

What Is n8n?

n8n (pronounced “node-node”) is an open-source workflow automation platform — think Zapier or Make, but you can self-host it and connect to anything that speaks HTTP. For traders that includes Telegram, Discord, Google Sheets, Slack, Postgres, MySQL, OpenAI, broker REST APIs, and TradingView webhooks.

The model is simple. A trigger node kicks the workflow off — usually an inbound webhook. Logic nodes branch, filter, or transform. Action nodes push the result somewhere. For MT4 and MT5 specifically, n8n is the missing piece between MQL’s narrow native integrations (email, push, file write) and the rest of your stack — the same pattern we covered in our deeper walkthrough on MetaTrader webhooks for trading alerts and auto-execution.

Why Connect MetaTrader to n8n?

MetaTrader’s native automation surface is thin: MQL scripting plus a few one-way notifications (push, email, sound). n8n closes the gap without forcing you to write a custom Node.js or Python backend:

  • Multi-destination fan-out — one trade event lands in Telegram, Sheets, and Postgres in one workflow.
  • Cross-platform sync — copy MT5 fills into a cTrader Open API account or another broker’s REST endpoint, an approach we break down in our guide to copying trades between MetaTrader and cTrader.
  • Event-driven journaling — every trade logged with timestamps, slippage, and your own metadata.
  • AI-in-the-loop — pipe a trade event through an OpenAI node for auto-generated journal notes.
  • Risk plumbing — daily-loss caps, exposure caps, and news-window blocks enforced outside the EA.
n8n MetaTrader webhook workflow: Webhook trigger node configured with POST method and production URL ready to receive MT5 events

The Three Components You Actually Need

Every n8n + MetaTrader integration has the same three parts:

  1. MetaTrader (MT4 or MT5) running an EA or alert that fires an HTTP POST when a trade event happens. MT5’s WebRequest() takes a URL, headers, and a JSON payload directly. If you don’t already have an EA emitting events, our roundup of the best MT5 expert advisors is a good place to start.
  2. An n8n instance reachable over HTTPS — self-hosted on a VPS, n8n cloud, or a local box for development.
  3. Action nodes downstream of the webhook — Telegram, HTTP Request, Google Sheets, Postgres, OpenAI, whatever the workflow needs.

Webhook in. Logic in the middle. Actions out.

Step-by-Step: MT5 to n8n in Four Steps

The build is short. The friction is usually in MT5’s allowed-URLs setting and in matching your JSON payload to the n8n webhook’s expected schema.

Step 1 — Stand up n8n

Three viable hosting paths: self-host on a VPS via Docker (recommended for production), n8n cloud (paid, managed, fastest to first webhook), or local install (fine for development; useless for production because MT5 needs a public HTTPS URL). For the rest of this guide we assume you have an instance at https://your-n8n.example.com.

Step 2 — Create a Webhook trigger in n8n

In the n8n editor, drop a Webhook node onto the canvas. Set the HTTP method to POST and the path to something descriptive — for example /metatrader-signal. Save the workflow and copy the production webhook URL n8n generates. That URL is your endpoint.

Step 3 — Whitelist and call it from MetaTrader

In MT5, open Tools > Options > Expert Advisors, tick “Allow WebRequest for listed URL”, and add your n8n hostname. Then, inside your EA or script, fire a POST when a trade event happens. The MQL5 outline looks like this:

string url = "https://your-n8n.example.com/webhook/metatrader-signal";
string headers = "Content-Type: application/json\r\n";
string payload = "{\"event\":\"order_open\","
              + "\"symbol\":\"" + _Symbol + "\","
              + "\"lots\":" + DoubleToString(lots, 2) + ","
              + "\"price\":" + DoubleToString(price, _Digits) + ","
              + "\"ticket\":" + IntegerToString(ticket) + "}";
char post[], result[];
StringToCharArray(payload, post, 0, StringLen(payload));
WebRequest("POST", url, headers, 5000, post, result, headers);

That’s it on the MetaTrader side. Every time the EA’s order logic fires, n8n gets the event.

Step 4 — Build the workflow downstream

Behind the webhook, chain the nodes you need: If nodes for conditional branches, Set nodes to reshape the payload, HTTP Request for any API without a first-party node, Google Sheets / Postgres for journaling, Telegram / Discord / Slack for alerts, and an OpenAI API node for auto-generated trade commentary. Save, activate, and the workflow is live.

Five MT5 Automation Workflows You Can Ship Today

These are the patterns we see most. Each one is a single n8n workflow — you can copy the shape and adapt the payload to your EA.

1. Telegram alert the moment a trade opens or closes

Webhook in. Set node formats a human-readable string (“EURUSD long 0.50 lots opened at 1.0834”). A Telegram Bot API node posts it to your private channel. Total nodes: three. Time to ship: under 10 minutes once n8n is up.

2. Trade log to Google Sheets for journaling

Webhook in. Set node maps payload fields to spreadsheet columns (timestamp, symbol, side, lots, entry, exit, P&L). Google Sheets “Append Row” node writes the row. You now have a self-updating trade journal that survives broker statement format changes.

3. Daily drawdown risk-cap webhook

The EA POSTs every closed trade to n8n. A Function node accumulates the day’s realized P&L. An If node checks whether the loss has crossed your cap (say, 2% of starting balance). If it has, n8n calls back to a second EA endpoint or flips a flag in a Postgres row that the EA reads on every tick — and the EA stops opening new entries until the next session. The risk logic lives outside the EA, which makes it auditable and easy to change without recompiling MQL.

4. TradingView signal routing into MT5

Reverse direction. TradingView alert hits n8n’s webhook with a JSON payload. n8n filters, throttles, deduplicates, and forwards to a small bridge EA on your VPS that listens on a local HTTP port. The EA places the corresponding market order in MT5. n8n becomes the rate-limiter and validator between TradingView’s noisy alert stream and your live account.

5. Broker connectivity health-check

A Schedule trigger fires every minute. n8n calls a tiny HTTP endpoint exposed by an EA on your VPS that returns the current MT5 account number, ping to the broker, and last-tick timestamp. If the response is missing or stale (say, no tick in 60 seconds during market hours), n8n pages you on Telegram. You catch a frozen terminal before it costs you a fill. https://www.youtube.com/embed/dooXxhGy5Ow

MetaTrader + n8n on a Forex VPS: Why the Stack Belongs on Always-On Infra

You can run all of this on a laptop. You shouldn’t. The whole point is reacting to live market events 24/5 — and a laptop that sleeps, drops Wi-Fi, or installs a Windows update at 3 AM breaks every workflow downstream of MT5.

A forex VPS handles the obvious problems and a few less obvious ones:

  • Always-on terminal. MT5 stays connected through weekends, OS updates, and home internet hiccups.
  • Low broker latency. A VPS in Equinix NY4, LD4, or TY3 reaches major brokers in 1ms or less — webhooks fire before the price moves.
  • Stable n8n endpoint. Self-host n8n on the same VPS and your webhook URL is reachable 24/7 with a real HTTPS cert.
  • Audit and debug. n8n’s execution log lives on the same box as MT5’s journal — when something breaks at 2 AM, the evidence is all in one place.

If you’re already running MT4 or MT5 on a trading VPS, adding n8n is essentially free — Docker, a reverse proxy, and a subdomain. If you’re not yet, our MT4 VPS and MT5 VPS plans are sized for this stack. Traders building heavier API-driven workflows usually start on a trading VPS with API access from day one.

Frequently Asked Questions

Is n8n MetaTrader 5 integration officially supported by MetaQuotes?

No. There is no first-party n8n node from MetaQuotes and no official MT5 plugin from n8n. The integration works because MT5’s MQL5 language exposes WebRequest(), which can POST JSON to any HTTPS endpoint — and n8n’s Webhook trigger accepts any HTTPS POST. Both sides speak HTTP, which is enough.

Can I use the same setup for MT4?

Yes, with one caveat. MT4’s MQL4 also has WebRequest(), the URL allow-list works the same way, and the n8n side is identical. The caveat is MT4’s HTTPS support is older and stricter about cert chains — if you self-host n8n, use a real Let’s Encrypt cert, not a self-signed one.

Is n8n free?

n8n is open-source and free to self-host (fair-code license). n8n cloud is a paid managed service. For most traders running a single workflow, self-hosting on the same VPS as MT5 is the cheapest and most reliable option.

Self-host vs n8n cloud — which one for trading?

Self-host if you already run a VPS for MT4/MT5; the marginal cost is near zero and your webhook stays inside the same network as your terminal. n8n cloud if you don’t want to manage infrastructure and you’re fine with the webhook traversing the public internet between MT5 and the cloud instance.

Do I need a VPS to run n8n with MetaTrader?

For a real trading workflow, yes. A laptop or desktop can’t be your webhook receiver because it sleeps, reboots, and loses connectivity. A VPS gives you a stable public URL, 24/7 uptime, and low broker latency in the same box. If you’re already running MT5 on a VPS, n8n shares the same machine.

What MT5 events can I send to n8n?

Anything the MQL5 runtime can detect: order open, order close, partial fill, stop-loss hit, take-profit hit, margin call, equity threshold, custom indicator signal, news-time block, broker reconnect — all of it. The webhook is just an HTTP call inside an EA, so the trigger is whatever event you put it next to in your code.

Where to Go from Here

The minimum viable build is one webhook, one Telegram node, and an MT5 EA that fires on order open. Ship that first. Once you trust the pipe, add the trade-log workflow, then the risk-cap workflow, then the health-check. Each one stacks on the same webhook plumbing.

The harder part is keeping the whole thing online. MT5, n8n, and your broker connection all need to be up at the same time, every minute the market is open. That’s an infrastructure problem, not an automation problem — and it’s the one a trading-focused VPS solves.

If you want the stack on infrastructure that’s already tuned for MT4, MT5, and 24/7 EA execution, our forex VPS plans drop you into Equinix NY4, LD4, or TY3 with MetaTrader pre-installed. Add n8n in a Docker container and your webhook layer is live the same day.

Thomas Vasilyev headshot

About the Author

Thomas Vasilyev

Writer & Full Time EA Developer

Tom is our associate writer, and has advanced knowledge with the technical side of things, like VPS management. Additionally Tom is a coder, and develops EAs and algorithms.

Areas of Expertise

VPS ManagementAlgorithm DevelopmentExpert AdvisorsTechnical Infrastructure

Finally, A Forex VPS
That Pays For Itself.

Join 10,000+ traders who already upgraded to smarter, faster trading with our Forex VPS service.