To auto-execute trades in MetaTrader, alerts need to be triggered on TradingView or in Telegram channel. Once an alert fires, it is forwarded by TradingConnector for execution.

Alerts syntax vs ExpertAdvisor config

Configuring your signals can be done in 2 ways:

  1. send simple LONG / SHORT (or BUY / SELL) alert from TradingView and apply other order parameters from TradingConnectorEA configuration (named EAconfig hereinafter).

  2. advanced way: include some or all parameters in alert message. If a parameter is found in the alert message it will OVERRIDE the one which is set in EAconfig. If particular parameter is not found in alert message, the value from EAconfig will be used.

Currently 9 basic commands are supported: long (or buy), short (or sell), closelong, closeshort, cancel long, cancel short, closepart, slmod, tpmod, closeall, closeall_on_ticker. On all markets available with your broker.

Alert message needs to say exactly “long” (or “buy”) or “short” (or “sell”) or “closelong” or “closeshort” or “cancel long” or “cancel short” or “closeall” or “closeall_on_ticker” to work correctly. Otherwise an alert will fail.

“buy” and “sell” are aliases to “long” and “short”. “Long” and “short” were in TradingConnector first, but at some point TradingView has added placeholders in alerts and this one {{strategy.order.action}} produces exactly “buy” or “sell” so we have decided to add them to our system as aliases. So wherever in the specification below you see alert example like “long sl=XX tp=YY” it can be replaced with “buy sl=XX tp=YY”".

FULL ALGO TRADING FROM TRADINGVIEW IS POSSIBLE!

All examples on “Alerts Syntax” page refer to alert messages as they should be displayed in “Message” field of “Create Alert” popup (see image above).

However, it is totally possible to configure these alert messages and logic triggering them also automatically from PineScript code. This is more advanced and leads to full algo-trading, but requires at least basic coding skills (actually basic or learning basics should suffice). Check here how to run alerts from PineScript.

ADVANCED PARAMETERS

Which market to trade (execute trade on) is being determined by alert header. However, because sometimes a broker runs a market under a different symbol, it is possible to specify that symbol precisely with ’tradesymbol=’ parameter. So no matter what symbol is in alert header, trade will be executed in the market mentioned under ‘tradesymbol’ parameter. So this alert will open trade with XAUUSD market, even if alert is attached to EURUSD or some other chart on TradingView:

long tradesymbol=XAUUSD

Other parameters, which can be included in alert message after ‘long’ or ‘short’ are:

lot - sets amount invested in each trade,

risk - defines the size of investment per trade, as a fraction of trading account balance. Values above 0.02 are HUUUUUGE RISK.

sl - sets fixed stop loss distance in pips. So with this setting at 12.0, if the trade goes against you by 12 pips (120 ticks), it will be closed with 12 pips loss. If this is set to 0, “risk=” parameter will be ignored.

slprice - sets fixed stop loss price level exactly at a value specified in this parameter.

slperc - sets fixed stop loss distance at % change from the entry price.

tp - sets fixed take profit distance. So with this setting at 12.0, if the trade goes in favourable direction by 12 pips (120 ticks), it will be closed with a profit of 12 pips.

tpprice - sets fixed take profit price level exactly at a value specified in this parameter.

tpperc - sets fixed take profit distance at % change from the entry price.

tp1 (tp2, tp3) - same as “tp=”, but for partial profit taking. Must be used with “part=” parameter. Scroll down to “Multiple Take Profit Distances” section for details and example.

tpprice1 (tpprice2, tpprice3) - same as “tpprice=”, but for partial profit taking. Must be used with “part=” parameter. Scroll down to “Multiple Take Profit Levels” section for details and example.

tpperc1 (tpperc2, tpperc3) - same as “tpperc=”, but for partial profit taking. Must be used with “part=” parameter. Scroll down to “Multiple Take Profit Levels” section for details and example.

part1 (part2, part3) - defines how big part of the position should be closed. Scroll down to “Multiple Take Profit Distances” section for details and example.

trail - (true/false) enables Trailing Stop-Loss on all trades

trailtrig - Trailing Stop-Loss will be activated after a trade gains this number of pips.

traildist - distance of the Trailing Stop-Loss.

trailstep - distance of the Trailing Stop-Loss, increased after a step.

trailtrigperc - Trailing Stop-Loss will be activated after a trade gains % value from the entry price.

traildistperc - distance of the Trailing Stop-Loss as % gain from the entry price.

trailstep - distance of the Trailing Stop-Loss as % gain from the entry price, increased after a step.

be - activation of “Breakeven” feature. It moves stop-loss to a entry price + small margin (for example to cover commission costs)

betrig - Breakeven will be activated after a trade gains this number of pips.

beoff - offset from entry price level, 0 means price level exactly, 1 - 1 pip higher than entry price level for buy trades / 1 pip lower for sell trades. In other words "beoff" means how many pips you want to protect.

betrigperc - Breakeven will be activated after a trade gains this % of value from the entry price.

beoffperc - offset from entry price level, calculated as % distance from the value of entry price.

tradeid - add unique identifier of the trade to be able to close only a part of it.

offset - parameter used for stop and limit orders, explained in section below

price - parameter used for stop and limit orders, explained in section below

accounts - for distributing alerts to various accounts/brokers, explained in section below

comment - for adding any comments you might need for history analysis

slippage - don’t make an entry If slippage is greater than X

onlytc - if “Require ‘onlytc’ parameter in alerts” setting in EAconfig is enabled, all alerts without this string will be ignored by TradingConnector.

Here is example entry alert which combines several parameters:

long tradesymbol=XAUUSD tp=30 trail=true trailtrig=4 traildist=3 be=true betrig=2 beoff=1

It would trigger long entry on XAUUSD, with TakeProfit 30 pips away from the entry price, and 3-pip Trailing-Stop enabled after price favourably moves by 4 pips. Stop-Loss and lotsize values would be taken from the ExpertAdvisor configuration. Also, thanks to “Breakeven” feature, after price favourably moves by 2 pips, Stop-Loss will be moved to 1 pip higher than entry price.

Pending ORders

Placing pending orders (stop-orders and limit-orders) is also supported, using “offset” or "price" parameters.

long offset=3 - will place buy-stop order with entry price set 3 pips above current market price.

long offset=-3 - will place buy-limit order with entry price set 3 pips below current market price.

short offset=3 - will place sell-limit order with entry price set 3 pips above current market price.

short offset=-3 - will place sell-stop order with entry price set 3 pips below current market price.

short price=1.19111 - will place sell pending order with entry price set exactly at 1.19111.

cancel short - will cancel all pending and not entered short orders on a given market.

REVERSING ORDER CLOSES PREVIOUS TRADES AKA NO HEDGING… OR HEDGING

By default - hedging is disabled. So when a position is about to be entered, but there already is a position open in the opposite direction, that already existing one will be closed first. But you can modify this behaviour by enabling “Allow hedging” in EA configuration. This will have effect only if broker doesn’t block hedging.

MULTIPLE TAKE PROFIT DISTANCES

It is also possible to set profit taking at multiple pre-defined levels. Up to 3 levels. Example entry alert defining these take profit levels looks like this:

long tp1=30 part1=0.3 tp2=45 part2=0.4 tp3=55 part3=0.3

partN value is initial lot size part for closing. For example if “part=0.3” and initial lot size was 0.1 lot, only 0.03 lot will be closed when reaching defined level.

1) part=0.3 -> 0.03 will be closed, 0.07 lot continues

2) part=0.4 -> 0.04 will be closed, 0.03 lot continues

3) part=0.3 -> 0.03 will be closed, nothing is left in the trade

MULTIPLE TAKE PROFIT LEVELS

Multiple TakeProfits can be also set with particular price levels, not distances. Entire logic is the same as in “Multiple Take Profit distances” example, just with TPPRICEX= instead of TPX=:

long tpprice1=30 part1=0.3 tpprice2=45 part2=0.4 tpprice3=55 part3=0.3

PARTIAL CLOSING

closepart command works with part parameter.

part value is initial lot size part for closing. It works exactly as partN in “Multiple take profit levels” section described above.

TRADES MODIFICATION (FOR MOVING STOP-LOSS)

TradingConnector enables modifying ongoing trades, for example to develop Moving Stop-Loss feature. Commands are SLMOD and TPMOD. Here is example alert:

slmod slprice=1.11111

Where 1.11111 is the new level of a stop-loss.

NO INTERFERENCE WITH OTHER ALERTS

By default TradingConnector listens to all alerts which are triggered by TradingView. So there is a chance you have also set other alerts, which you wouldn’t like to be auto-executed in MetaTrader. But those alerts contain keywords like “long” or “short”, so TradingConnector will try to execute them in MetaTrader.

How to avoid it? Enable “Require ‘onlytc’ parameter in alerts” setting in EAconfig and add “onlytc” string to your alert. All alerts without this string will be ignored by TradingConnector. So your alert should look like this:

long onlytc sl=1.20000 tp=1.33000

Multiple Accounts

In case you want to distribute your TradingView alerts to various accounts you have with several brokers, you need to add “accounts” parameter to your alerts - it will ensure the move is delivered only to those particular listed accounts. Like this:

long accounts=123456,098765

This will execute trades only with specified accounts/brokers. Their MT4's/MT5's must be installed and running on the same computer as TradingConnector desktop app and Google Chrome with TradingView.

Expert Advisor configuration

You can define a number of parameters for your trades in Expert Advisor.

Auto size - with this set to TRUE lot size of every trade will be calculated dynamically according to the size of your account deposit and available funds. This calculation uses value defined in “Risk” parameter. If “Auto size” is set to FALSE, investment amount will be fixed per trade and will be taken from “Lot size”.

Lot size - this will be amount invested in each trade, provided that “Auto size” is set to FALSE.

Risk (%) - this parameter defines the size of investment per trade, if “Auto size” is set to TRUE. Values above 0.02 are HUUUUUGE RISK.

Stop loss - fixed stop loss value in pips. So with this setting at 12.0, if the trade goes against you by 12 pips (120 ticks), it will be closed with 12 pips loss. If this is set to 0, “risk=” parameter (autosizing) will be ignored.

Take profit - fixed take profit value. So with this setting at 12.0, if the trade goes in favourable direction by 12 pips (120 ticks), it will be closed with a profit of 12 pips.

Pyramiding - if this set to FALSE, and a trade is already opened, all new signals ordering trades in the same direction will not be executed.

Allow hedging - if this is set to TRUE opening trade in opposite direction that the current one, will not automatically close that current one. Note: there are brokers, which block hedging.

Show error messages in popups - by default all reasons for not opening a trade will be show in the popup. It can be disabled, all such these error messages can be found in ‘Experts’ tab of MetaTrader anyway.

Require ‘onlytc’ parameter in alert - by default TradingConnector listens to all alerts which are triggered by TradingView. So there is a chance you have also set other alerts, which you wouldn’t like to be auto-executed in MetaTrader. But those alerts contain keywords like “long” or “short”, so TradingConnector will try to execute them in MetaTrader. How to avoid it? Enable this setting in EAconfig and add “onlytc” string to your alert. All alerts without this string will be ignored by TradingConnector.

Time settings - restrict trading times to these sessions. If you want to have TradingConnector take trades all the time, have 0:00 in all 4 lines.

Use trailing - enabling Trailing Stop-Loss on all trades

Trailing trigger - Trailing Stop-Loss will be activated after a trade gains this number of pips.

Trailing distance - distance of the Trailing Stop-Loss.

Trailing step - distance for stepped moving of Trailing Stop-Loss.

New features are coming up soon. Subscribe to our NEWSLETTER to get info about new releases first hand!