Alerts Syntax
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 - for example ‘long tradesymbol=EURUSD sl=100 tp=150 lotsize=0.15’ must be constructed in a specific way:
KEYWORD - each alert must contain 1 and only 1 of the basic mandatory commands: long (or buy), short (or sell), closelong, closeshort, cancel long, cancel short, closepart, slmod, tpmod, closeall, closeall_on_ticker.
* TRADESYMBOL - a way to specify which ticker/symbol/asset the alert is designated for - is mandatory, but sometimes optional parameter. Why sometimes optional? Alert set on TradingView is always attached to particular symbol (so it is not possible to set something like 1 alert for all forex pairs) and this symbol is forwarded in alert’s header. TradingConnector retrieves symbol from the header, so there is no need to duplicate this information also inside alert message. HOWEVER sometimes symbol name on TradingView and on MetaTrader do not match - in such case tradesymbol=EURUSD parameter (where ‘EURUSD’ is symbol name on MetaTrader) must be added to alert message, to OVERRIDE whatever is found in the header.
Messages incoming from Telegram do not include headers. Whatever stands at the beginning of alert message (until first space) will be considered as a header, so this will be valid alert message: ‘EURUSD long’. If not at the beginning, add parameter name, like this: ‘long tradesymbol=EURUSD’
** PARAMETERS - adding parameters to alert message is optional because of 2 reasons:
you may not want to attach stop-loss or take-profit or any other parameters to the position, or
you may want to attach trade parameters specified in EAconfig (how to open EAconfig is explained at the bottom of this page). There is an extensive set of parameters which can be set in EAconfig like stop-loss, lot size, trailing and more and they will be applied to each and every incoming alert under one condition - they are not found in alert message. Each time a certain parameter is found in alert message, its value will OVERRIDE whatever is set in EAconfig. For example, if StopLoss and TakeProfit are both set to 50 pips in EAconfig and alert saying “long sl=25” is received, a long position will be entered with StopLoss=25 and TakeProfit=50.
As per above requirements even most simple alert messages saying only ‘long’ or ‘short’ triggered by the TradingView would be VALID for TradingConnector.
It doesn’t matter in which order parameters are specified in the alert. Parameters must be divided by spaces, not commas or semicolons.
Reversing Orders Automatically
Most common question asked is how to send 2 alerts - one to close long and second to open short entry (or vice versa) - making sure second alert is slightly delayed to make sure it is not executed first.
The answer: no need to worry about it. If ‘short’ entry alert comes in when long position is opened (or vice versa), that long position is automatically closed before entering short.
That is default behaviour and TradingConnector works like this when “Allow Hedging” is set to FALSE in EAconfig. But it can be changed to TRUE - in such case opened positions will not get automatically closed on reversing entry order.
Parameters
risk - defines the size of investment per trade, as a fraction of trading account balance. Values above 0.02 are HUUUUUGE RISK.
auto - 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=” is set to FALSE, investment amount will be fixed per trade and will be taken from “lot=”.
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.
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
delay - alert execution will be delayed by specified number of seconds
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
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.
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, Take-Profit)
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.
The same works for moving take-profit:
tpmod tpprice=1.22222
‘ONLYTC’ TO AVOID 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.
ADVANCED: CLOSE OR MODIFY SPECIFIC POSITION ONLY WITH TRADEID=
Let’s say there are multiple positions on the same symbol opened, and you only want to close one of them. To do this, you need to add tradeid= parameter to the alert.
closelong tradeid=1
However, this can be done only for positions, which were marked with that specific tradeid by the entry alert, like this:
long tradeid=1
An example of tradeid= implementation in a complete strategy can be found in this example script: https://www.tradingview.com/script/BTSkg8IP-TradingView-Alerts-to-MT4-MT5-Forex-indices-commodities/
Expert Advisor configuration
To access EAconfig in your MetaTrader, right-click on the chart TradingConnectorEA is attached to, then “Expert List” and “Properties”.
Apart from settings mirroring parameters described above, EAconfig includes also some settings, which cannot be controlled via alert messages.
TradingConnector application IP-Address - IP-Address of TradingConnector.EXE application. By default this is local address (127.0.0.1) and can be changed to remote address only under Remote Multiple Accounts lincese.
Pyramiding - pyramiding limit per symbol.
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.
Magic Number - if this is set to 0, TradingConnector can be used to close manually opened trades.
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.
Visual settings (HUD) - Settings of the HUD which is displayed on the chart.
New features are coming up soon. Subscribe to our NEWSLETTER to get info about new releases first hand!