Documentation

User Guide

Get started with Tradingview MT5 Gateway in minutes

Introduction

Tradingview MT5 Gateway bridges the gap between your TradingView alerts and MetaTrader 5 terminal. It allows you to automate your trading strategies by converting TradingView alerts into automated executions on MT5.

1. Prerequisites

  • A TradingView account (Pro, Pro+, or Premium for webhooks).
  • MetaTrader 5 terminal installed on your computer or VPS.
  • An account on our platform.

2. Enable Two-Factor Authentication (2FA)

For enhanced security, we strongly recommend enabling Two-Factor Authentication on your account. This adds an extra layer of protection by requiring a time-based code from your mobile device when logging in.

Steps to Enable 2FA:

  1. Navigate to Profile Settings: Click on your profile photo in the top-right corner and select "Profile".
  2. Locate 2FA Section: Scroll down to the "Two Factor Authentication" card.
  3. Start Setup: Click the "Enable" button. You will be asked to confirm your password.
  4. Scan QR Code: Once confirmed, a QR code will appear. Open your authenticator app (e.g., Google Authenticator, Authy) on your phone and scan the code. If you cannot scan it, you can enter the "Setup Key" manually.
  5. Verify Code: Enter the 6-digit code generated by your authenticator app into the "Verification Code" field and click "Confirm".
  6. Save Recovery Codes: Upon success, you will be shown a list of Recovery Codes. Store these in a secure password manager. They allow you to access your account if you lose your phone.
Once enabled, you will need your authenticator app to log in.

3. Set Your Timezone

To ensure all signals and logs are displayed in your local time:

  1. Go to Profile: Click your avatar and select "Profile".
  2. Update Timezone: In the "Profile Information" section, select your location from the "Timezone" dropdown.
  3. Save: Click "Save Changes". The dashboard will immediately reflect your local time.

* The system attempts to auto-detect your browser timezone upon your first login.

4. Setup Connections

Our platform uses "Connections" to pair your TradingView strategies with specific MetaTrader 5 accounts.

  • Go to the Dashboard and navigate to the "TV Gateway" section.
  • Click "Create Connection" to generate a new pair of keys.
  • Connection Name: Give it a recognizable name (e.g., "Gold Strategy").
  • MT5 Account Number (Mandatory): Enter your MT5 login ID here. Signals from this connection will ONLY be executed by the EA running on this specific account.
Your plan determines the maximum number of active connections you can have (e.g., Free: 1, Starter: 5).

5. Install the Expert Advisor (EA)

Download the TvGatewayEA.ex5 file from the Downloads page. Place it in your MT5 Data Folder under MQL5/Experts/. Refresh the Experts list in MT5 and drag the EA onto any chart.

In the EA settings input:

  • Gateway URL: https://www.uat.tvmt5gateway.com/api/next-signal
  • EA Token: Copy the "EA Token" from the Connection you created in the dashboard.

* The EA automatically appends your MT5 account number to the request (e.g., `?token=...&account=123456`) to authorize the signal retrieval.

Make sure to enable "Allow WebRequest" in MT5 settings and add our API URL to the allowed list.

6. Configure TradingView Alert

In TradingView, create a new alert on your strategy or indicator. In the "Webhook URL" field, paste the webhook URL provided in your dashboard (e.g., https://www.uat.tvmt5gateway.com/api/tv-webhook).

In the "Message" field, use the JSON format provided. Make sure to use the specific "TV Secret" for your Connection.

{
    "secret": "YOUR_TV_SECRET_FROM_DASHBOARD",
    "action": "buy",
    "symbol": "XAUUSD",
    "volume": 0.1,
    "price": "{{close}}",
    "sl": "{{plot("Stop Loss")}}",
    "tp": "{{plot("Take Profit")}}"
}
                

Example Strategies (Pine Script)

Example 1: Simple MA Crossover

This script sends a BUY signal when EMA 20 crosses over EMA 50, and a CLOSE signal when it crosses under.

//@version=5
strategy("TV-MT5 MA Cross", overlay=true)

// Inputs
secret = input.string("CHANGE_ME", "Webhook Secret")

// Indicators
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
plot(ema20, color=color.green)
plot(ema50, color=color.red)

// Logic
longCondition = ta.crossover(ema20, ema50)
closeCondition = ta.crossunder(ema20, ema50)

// JSON Payloads
buy_json = '{"secret": "' + secret + '", "action": "buy", "symbol": "' + syminfo.ticker + '", "volume": 0.1}'
close_json = '{"secret": "' + secret + '", "action": "close_symbol", "symbol": "' + syminfo.ticker + '"}'

// Execution
if (longCondition)
    strategy.entry("Long", strategy.long, alert_message=buy_json)

if (closeCondition)
    strategy.close("Long", alert_message=close_json)

                

Example 2: RSI Overbought/Oversold

This script BUYS when RSI < 30 and SELLS when RSI > 70.

//@version=5
strategy("TV-MT5 RSI Strategy", overlay=true)

secret = input.string("CHANGE_ME", "Webhook Secret")
rsi = ta.rsi(close, 14)

// Triggers
buySignal = ta.crossover(rsi, 30)
sellSignal = ta.crossunder(rsi, 70)

// JSON
buy_msg = '{"secret": "' + secret + '", "action": "buy", "symbol": "' + syminfo.ticker + '", "volume": 0.1, "comment": "RSI Buy"}'
sell_msg = '{"secret": "' + secret + '", "action": "sell", "symbol": "' + syminfo.ticker + '", "volume": 0.1, "comment": "RSI Sell"}'

if (buySignal)
    strategy.entry("Long", strategy.long, alert_message=buy_msg)

if (sellSignal)
    strategy.entry("Short", strategy.short, alert_message=sell_msg)

                

7. Monitor & Trade

Once set up, every time your alert triggers, the signal is sent to our gateway. The EA on your MT5 terminal polls for pending signals matching its token and account, executing them automatically (batch processing is supported). You can monitor all signals in real-time from your dashboard.

Troubleshooting

Signal received but not executed?

Check if "Algo Trading" is enabled in MT5 and if the EA is running (smiley face icon). Also verify the symbol name matches exactly. If you set an "MT5 Account Number" in your connection, ensure the EA is running on that exact account.

Webhook error in TradingView?

Verify your TV Secret is correct. Check the webhook log in TradingView for response codes.