Trading Router
Contact Us Log in Sign up

Tradingview Alert With Code

Tradingview setup

1. Custom alert in pinescript

Add alert in your pinescript indicator/strategy to send message. The message in the alert should follow TradingRouter Syntax

You can add the alert whenever you want to send message

Example: Add alert to MACD indicator

We add alert at line 17, so that whenever MACD crossover aMACD, tradingview will send message to close all short positions and buy 0.01 lot of symbol, which is the same symbol the pinescript is running on. If your pinescript is running on EURUSD, then all short EURUSD positions will be closed and a 0.01 lot long EURUSD position will be created.

We add another alert at line 21, so that whenever MACD crossunder aMACD, tradingview will send message to close all long positions and sell 0.01 lot of symbol, which is the same symbol the pinescript is running on. If your pinescript is running on EURUSD, then all long EURUSD positions will be closed and a 0.01 lot short EURUSD position will be created.

2. Set up alert on tradingview

On your tradingview page, click the alert icon, then click the "Create alert" button or click the plus sign to creat a new alert


On the Settings tab of the pop up window, set Condition to your script, and choose "Any alert() function call".


On the Notifications tab, check Webhook URl, put https://webhook.tradingrouter.com


Now whenver your script calls alert() function, the message will be sent to your MT4/5. For example if you put "Trading Router MACD Indicator" script to chart and set Condition to "Trading Router MACD Indicator", when the alert on line 17 is called, the message in this alert will be sent to MT4/5 and MT4/5 will close all short positions and buy 0.01 lot of symbol.