How to manually set up an alert on TradingView
(fastest way to trigger test alert)
Click “Create Alert” on top of TradingView’s chart page.
Set up conditions which are surely and immediately met with ‘Greater Than’ or ‘Less Than’ condition + proper price level.
Type ‘long’ or ‘short’ in alert’s Message field. “Alert name” field is irrelevant.
Click “Create”.
Alert should trigger immediately and execution result should be visible in TradingConnector.EXE and MetaTrader (provided the connection between TradingConnector components has been set up properly according to guidelines specified on installation page).
From PineScript to Alerts - 101
(scroll down for advanced)
PineScript is TradingView’s proprietary scripting language used for coding trading indicators and strategies. Its simplified nature makes it accessible for tech-savvy people, yet coding noobs - after 2-3 weeks of digging into it, they can produce strategies of moderate complexity. The most simple trading strategy we can think of can be written in 7 lines of PineScript, while equivalent in MQL (C++-based native MetaTrader4/5 language) might exceed 100 lines.
Starting coding in PineScript is smooth and easy, no need to install anything:
Open any Chart on TradingView.com
Click “Pine Editor” tab at the bottom of the page
Select any of the scripts from “New” dropdown to paste it in the editor
Click “Add to Chart” to compile and run it. That’s it - you have just became a QUANT (trading algorithm developer).
To be able to create Alerts based on the logic coded inside PineScript (for example on crossover of two Moving Averages), the logic needs to be wrapped into alertcondition() function. For example, to produce “long” alert message, there needs to be a function call like this:
alertcondition(EnterLong, title="Long", message='long')
Variety of open source scripts - both indicators (studies) and strategies - can be found on TradingView. We recommend exploring TradingView’s library and community on your own, then experimenting yourself.
Because it all happens on the same computer, no data is being passed over the Internet so our system is the fastest available to the average trader. It takes less than 1 second TradingView alert until the trade is executed in MT4 or MT5.
PineScript - Advanced, dynamic variables
Apart from all detailed parameters described in “Alerts Syntax” section, which can - and should - be passed via alertcondition() from PineScript, there are some even more advanced ways of transferring logic for trades execution. It is possible to intercept a value of a variable calculated in runtime and forward it in the alert to MT4/MT5. Passing dynamic variables to alerts was introduced by TradingView in November 2019 and is well described in this blog post: https://www.tradingview.com/blog/en/introducing-variables-in-alerts-14880/
Here is a very brief example of code. It passes “low” value of last candle as Stop-Loss:
alertcondition(EnterLong, title="Long", message='long sl={{low}}')
More complex and complete use-case of dynamic variables in alerts is showcased in this educational script, which presents how to set stop-losses below and above most recent pivot points with surgical precision or take partial profits: https://www.tradingview.com/script/9MJO3AgE-TradingView-Alerts-to-MT4-MT5-dynamic-variables-NON-REPAINTING/
PineScript - other resources
These are also worth checking when digging into PineScript:
Ultimate set of resources collected by masters of Pine: http://www.pinecoders.com/resources/
PineScripters community channel on Telegram: https://t.me/pinescripters
Gallery of useful open source scripts by Pine Wizards https://www.tradingview.com/blog/en/meet-the-tradingview-pine-wizards-15929/