Skip to content

Automated trading

Run a Pine Script Strategy on MT5: Rewrite It in MQL5, or Route the Alerts?

You have a Pine Script strategy that backtests well on TradingView and a broker account on MetaTrader 5. The question is how the two meet. There are two genuinely different answers, and they are often confused: you can rewrite the strategy in MQL5 so it runs inside MT5 as an Expert Advisor, or you can keep the strategy on TradingView and route its alerts to an MT5 terminal as trade instructions. The first moves your logic. The second moves only your signals.

Short answer: if your edge depends on tick-level logic, on other MQL5 tools, or you do not want to depend on TradingView at all, rewriting in MQL5 is the right call. If your strategy already lives in Pine Script and you want to keep it there, alert routing is the shorter path, and the piece you then have to keep online is the MT5 terminal, not TradingView. This article walks through what each route actually involves, using one simple rule as the example.

Illustrative comparison of rewriting a strategy in MQL5 with routing TradingView alerts through PineConnector to MT5.
A native EA needs independent code, data and demo checks. Alert routing needs delivery and receiving-account reconciliation.

Why these are two different projects, not two settings

MQL5 is MetaQuotes' own language. Its reference describes it as "a high-level language designed for developing technical indicators, trading robots and utility applications, which automate financial trading."[1] An Expert Advisor written in it runs inside the MT5 terminal, reads the broker's price feed, and places orders directly. Nothing from TradingView is involved.

Pine Script, by contrast, runs on TradingView's servers against TradingView's data. Pine cannot place an order at your broker. What it can do is raise an alert, and TradingView can deliver that alert as a webhook, an HTTP POST to a URL you choose.[2] Something at that URL has to turn the message into an order in MT5. That "something" is a connector, and it needs an MT5 terminal that is open and running, because MetaQuotes documents that an Expert Advisor stops when the platform is turned off.[3]

So route 1 is a software port. Route 2 is an integration. They share a broker and nothing else.

The worked example: a two-EMA crossover

Illustrative example, not a recommendation: an EURUSD H1 rule requests a long when EMA(20) crosses above EMA(50), using a fixed 0.5 lot size, then requests a close on the opposite cross. This example specifies no protective stop. It illustrates the implementation routes, not a tested strategy or suitable trade size.

Route 1: rewrite it in MQL5

  1. Re-implement the indicators. You use MT5's built-in EMA handle or write the calculation yourself, then code the cross detection in an EA's tick or bar handler. Even for a rule this simple, EMA values can differ from TradingView's because the price history and bar boundaries come from your broker's server, not from TradingView's data.
  2. Backtest again in MT5. Test the rewritten implementation on its chosen data and modelling settings. MT5 Strategy Tester runs EAs on historical prices, but a tester run does not verify a broker demo outcome.[4]
  3. Handle order state in code. Position sizing, checking whether a position is already open, and what to do if an order is rejected are now your code's responsibility.
  4. Host it. The EA runs only while an MT5 terminal is running, so you need a machine that stays on: a PC, a Windows VPS, or MetaQuotes' own MetaTrader VPS, which accepts EAs but not DLL-dependent ones.[5] If you go the Windows VPS route, ForexVPS (affiliate link) offers Windows VPS plans for MetaTrader.
  5. Maintain it. Every future change to the rule is a change to MQL5 code, recompiled and retested. If you also keep the Pine version for charting, you now maintain two codebases that can drift.

Route 2: keep it in Pine and route the alerts

  1. Leave the strategy where it is. The Pine strategy() script keeps running on TradingView, and your existing backtest still describes the logic that will fire.
  2. Attach an instruction to each order. Pine's strategy.*() order functions accept an alert_message parameter. TradingView's documentation says that when it is used, "script users must include the {{strategy.order.alert_message}} placeholder in the 'Create Alert' dialog box's 'Message' field when creating script alerts on order fill events."[6] For the EMA example, the entry order's message would be a connector instruction and the exit order's message a close instruction.
  3. Write the intended action explicitly. The illustrative entry message is LicenseID,buy,EURUSD,vol_lots=0.5; the exit is LicenseID,closelong,EURUSD.[7] For a method using the TradingView Message field, complete the message there; per-order alert_message setups build it in the script. Replace LicenseID and EURUSD with the intended ID and exact broker symbol. Add your configured secret= privately if authentication is enabled. This entry message specifies no SL/TP; inspect any receiving-EA defaults and verify the broker’s accepted protection. Without a comment filter, the close is not limited to one strategy label: check EA scope and every account receiving that License ID. Verify entries and closes on demo before using the pattern.
  4. Create the alert in the TradingView UI. This step is manual by design. The Pine documentation is explicit that "no alert-related Pine Script code can create a running alert in the charts UI; it merely creates alert events which can then be used by script users to create running alerts from the charts UI."[6] You set the webhook URL in the alert dialog.[2]
  5. Keep one MT5 terminal running with the connector EA attached. This is the always-on component. It can be your own Windows machine or VPS, or a hosted terminal. TradingView delivers the webhook and cancels the request if the receiver takes more than three seconds,[2] so the receiver's job is to accept quickly and hand the instruction to the terminal.

Two behaviours of route 2 catch people out and are worth knowing before you start. First, TradingView keeps a snapshot: creating an alert "saves a 'snapshot' of the script, its inputs, and the current chart's context on TradingView's servers", and to update it you must "delete the existing alert and create a new one."[8] Editing your Pine code does not change a live alert. Second, TradingView warns not to include "sensitive information such as login credentials or passwords in the webhook body."[2] A connector should identify you by a licence or key, never by your broker password.

Side by side

Route 1: rewrite in MQL5 Route 2: route the alerts
Up-front effort Port the strategy, re-implement indicators, handle order state Add alert messages to existing orders, create the alerts, install or activate a connector
Where backtests live MT5 Strategy Tester, on broker data TradingView, on TradingView data
Who maintains the logic You, in MQL5 You, in Pine Script
Depends on TradingView No Yes, for signals
Needs an always-on MT5 terminal Yes Yes
Tick-level or sub-bar logic Available Limited to what Pine alerts can express
Cost shape Your time, plus hosting Connector subscription, plus hosting unless included

Who should rewrite in MQL5

  • Your logic needs the tick stream or broker-side data that Pine alerts cannot carry, such as reacting to spread, order book depth, or partial fills.
  • You rely on the MQL5 ecosystem: other Expert Advisors, custom libraries, or the Strategy Tester's optimiser as your primary research tool.
  • You do not want a TradingView dependency. A native EA need not use TradingView, but it still depends on its own terminal, broker connection and implementation.
  • You are comfortable in a C-like language and want to own every line between signal and order.

For these traders, a connector is the wrong tool, and no hosting product changes that.

Who should route the alerts

  • Your strategy already exists in Pine and you trust the backtest you have, as evidence about the logic rather than about future results.
  • You want one Pine codebase. Keep the script version, chart settings and running-alert snapshot aligned. Recreate the alert after changes, and reconcile its simulated state with actual broker exposure.
  • You need the same signal on several accounts, since one alert can be routed to more than one terminal.
  • You would rather not learn MQL5 to trade a rule you have already written.

Where PineConnector fits on route 2

PineConnector is a connector for route 2. Your Pine strategy stays on TradingView; its alerts describe the intended actions. PineConnector and its EA process the supported instruction, and the EA sends an order request to the broker. Verify acceptance, fills and resulting positions separately. The demo procedure checks that path.

PineConnector Edge hosts MT5 with the PineConnector EA. It is included with Core, Plus and Pro; older subscriptions may have different Edge access. Your strategy, broker account and trading decisions remain yours. Check current plans and connection allowances instead of relying on a historical price or region list.[9]

Edge does not host third-party EAs; its hosted EA settings are changed in Portal → Edge → EA Settings, where applying a change restarts the terminal. A local EA input change does not alter Edge. The documented service hosts MT5; use a suitable separate environment for an MQL5 EA you write yourself.[10] The 17 September 2026 update removed the access-list invitation requirement; check the current Edge guide and Portal for available controls and supported servers.

Frequently asked questions

Can I convert Pine Script to MQL5 automatically?

PineConnector's Pine Script converter creates a Pine copy with alert integration, not MQL5 source. Moving a strategy to MQL5 requires a separately verified implementation because data, timing and order models can differ. Test it in MT5 Strategy Tester and on demo.[4]

If I route alerts, does my TradingView backtest prove the live result?

No. It describes the logic, and route 2 keeps that logic unchanged. Live fills, spreads and slippage at your broker are different from the backtest engine, and past performance does not indicate future results on either route.

Why did my alert keep using the old settings after I edited the script?

Because alerts are snapshots. TradingView's own FAQ says the alert saves the script, its inputs and chart context at creation time, and that you must delete and recreate the alert to pick up changes.[8] No connector or hosting product can change an upstream alert.

Can I run my own MQL5 Expert Advisor on PineConnector Edge?

No. Edge's documentation says it does not host third-party EAs. A native MQL5 strategy needs an environment that supports that EA; a direct implementation that calculates its signals and submits its own orders does not need PineConnector.[10]

Next step: if you are taking route 2, read the TradingView to MT5 setup guide and decide whether you will host the terminal yourself or use PineConnector Edge. If you are taking route 1, start with the MQL5 reference and the Strategy Tester documentation linked below.

Reviewed 23 September 2026 against primary documentation accessed on that date; Edge EA Settings updated 6 October 2026. No trading account was tested and no Pine Script or MQL5 code was compiled for this update.

Sources

  1. MetaQuotes – MQL5 Reference, accessed 9 September 2026.
  2. TradingView Help Center – How to configure webhook alerts, accessed 9 September 2026.
  3. MetaQuotes – MetaTrader 5 Help: Algorithmic Trading, accessed 9 September 2026.
  4. MetaQuotes – MetaTrader 5 Help: Strategy Testing, accessed 9 September 2026.
  5. MetaQuotes – Rules of Using the Virtual Hosting Service, accessed 9 September 2026.
  6. TradingView – Pine Script documentation: Alerts, accessed 9 September 2026.
  7. PineConnector Docs – Syntax, accessed 9 September 2026.
  8. TradingView – Pine Script FAQ: Alerts, accessed 9 September 2026.
  9. PineConnector – Getting started: Edge eligibility, accessed 23 September 2026.
  10. PineConnector Docs – PineConnector Edge, accessed 23 September 2026.
  11. PineConnector – Updates, 17 September 2026, accessed 23 September 2026.
  12. PineConnector – Pine Script converter, accessed 23 September 2026.
  13. PineConnector – Test your setup, accessed 23 September 2026.

PineConnector executes the instructions you send it. It does not select trades, manage money, or hold funds. Trading carries risk, and past performance of any strategy does not indicate future results.

Back to PiCo Blog

Run your strategies on our managed infrastructure

Bridge routes TradingView alerts to MetaTrader. Edge hosts and runs MT5 for you.

Core Trial

Then $59/month unless you cancel.

$7for 7 days

  • 3 account connections
  • 1 hosted MT5
  • Unlimited alerts, routed by Bridge
Try Core for $7

Trusted by 66,000+ traders in 156 countries and territories · <1s typical latency

Your Edge MT5 runs in our cloud · nothing to install · built on Microsoft Azure