TradingView Alerts to MT4 MT5 - Forex, indices, commoditiesHowdy Algo-Traders! This example script has been created for educational purposes - to present how to use and automatically execute TradingView Alerts on real markets.
I'm posting this script today for a reason. TradingView has just released a new feature of the PineScript language - ALERT() function. Why is it important? It is finally possible to set alerts inside PineScript strategy-type script, without the need to convert the script into study-type. You may say triggering alerts straight from strategies was possible in PineScript before (since June 2020), but it had its limitations. Starting today you can attach alert to any custom event you might want to include in your PineScript code.
With the new feature, it is easier not only to execute strategies, but to maintain codebase - having to update 2 versions of the code with each single modification was... ahem... inconvenient. Moreover, the need to convert strategy into study also meant it was required to rip the code from all strategy...() calls, which carried a lot of useful information, like entry price, position size, and more, definitely influencing results calculated by strategy backtest. So the strategy without these features very likely produced different results than with them. While it was possible to convert these features into study with some advanced "coding gymnastics", it was also quite difficult to test whether those gymnastics didn't introduce serious, bankrupting bugs.
//////
How does this new feature work? It is really simple. On your custom events in the code like "GoLong" or "GoShort", create a string variable containing all the values you need inside your alert and this string variable will be your alert's message. Then, invoke brand new alert() function and that's it (see lines 67 onwards in the script). Set it up in CreateAlert popup and enjoy. Alerts will trigger on candle close as freq= parameter specifies. Detailed specification of the new alert() function can be found in TradingView's PineScript Reference (www.tradingview.com), but there's nothing more than message= and freq= parameters. Nothing else is needed, it is very simple. Yet powerful :)
//////
Alert syntax in this script is prepared to work with TradingConnector. Strategy here is not too complex, but also not the most basic one: it includes full exits, partial exits, stop-losses and it also utilizes dynamic variables calculated by the code (such as stop-loss price). This is only an example use case, because you could handle variety of other functionalities as well: conditional entries, pending entries, pyramiding, hedging, moving stop-loss to break-even, delivering alerts to multiple brokers and more.
//////
This script is a spin-off from my previous work, posted over a year ago here: Some comments on strategy parameters have been discussed there, but let me copy-paste most important points:
* Commission is taken into consideration.
* Slippage is intentionally left at 0. Due to shorter than 1 second delivery time of TradingConnector, slippage is practically non-existing.
* This strategy is NON-REPAINTING and uses NO TRAILING-STOP or any other feature known to be causing problems.
* The strategy was backtested on EURUSD 6h timeframe, will perform differently on other markets and timeframes.
Despite the fact this strategy seems to be still profitable, it is not guaranteed it will continue to perform well in the future. Remember the no.1 rule of backtesting - no matter how profitable and good looking a script is, it only tells about the past. There is zero guarantee the same strategy will get similar results in the future.
Full specs of TradingView alerts and how to set them up can be found here: www.tradingview.com
Alerts
EMA CrossoversUseful for identifying and receiving alerts about uptrends and downtrends.
This script uses two Exponential Moving Averages (EMAs) to find price uptrends and downtrends. An Exponential Moving Average (EMA) is a type of moving average that places a greater weight and significance on the most recent data points. The script produces uptrend and downtrend signals based on crossovers and divergences between the two EMAs, the user will be able to spot a trend change (when the EMAs crossover) and to determine the strength of the current trend (when the EMAs diverge). It is also posible to get alerts for uptrends and downtrends on the web and mobile app with sound and pop-ups as well as via email. The optimal time to enter and exit the market can be concluded from this trend changes.
The user can set their own EMAs, by default they are set to 21 and 55 periods for medium and long term respectively. When the medium term EMA crosses below the long term EMA the asset is in a downtrend and the price will decline, and when the medium term EMA crosses above the long term EMA the asset is in an uptrend and price will increase.
This scripts plots the following indicators and signals on the chart to help the user to identify trends:
1.- Medium and long term EMAs as lines overlaid on the price chart.
2.- Up green triangles above bars when the price is on an uptrend and down red triangles below bars when the price is on a downtrend.
3.- Arrows with text to indicate the start of an uptrend or downtrend.
The user can enable and disable the indicators and signals as well as set colors and shapes to their liking.
This script also lets the user create alerts for uptrends and downtrends. To create a new alert using this script follow this instructions:
1.- Once you added this script to your chart, go to the alerts panel (right on web or bottom tool bar on the mobile app) and add a new alert (alarm clock icon with a plus sign).
2.- A modal window will open. On the “Condition” dropdown menu select “EMA Crossovers”.
3.- On the next dropdown menu (right below the “Condition” one) you can select from two types of alerts “Uptrend started” and “Downtrend started”.
4.- Lastly you can set all the normal alert options and create the alert.
Modified Smoothed Heiken AshiThis code is based on Smoothed HA candle which will work on all chart types
condition for BUY:
1. When close crosses Smoothed HA
2.Close should be in side upper band
3.BBW must be greater than the average
vice versa for sell
this code takes data from HA chart so that it can be applied on all chart type.
Bollinger band and Bollinger band width conditions added for removal of unwanted signals
Alert added so that you can apply alert and check it in real time performance
thanks to The Secret Mindset You tube channel from where I got the idea to convert this into a pine script indicator
smooth HA taken from "Smoothed Heiken Ashi Candles v1" at //@jackvmk
Correlation Oscillator - Anomaly AlertsThis script plots the correlation for two symbols as an oscillator:
A correlation of 1 means that both values move in the same direction together.
A correlation of -1 means that both values are perfectly negative correlated.
Parameter:
Length of the Correlation
The two symbols you want to calculate the correlation for
Barcolor: Defines whether Bar-coloring is set on.
The Number of bars lookback for anomaly: Say both are normally positively correlated it is an anomaly when the correlation turns negative and vica-versa.
Alerts: You can also set an Alert when an anomaly is detected.(blue dots on oscillator)
This has many use-cases:
For example VVIX and VIX are normally positive correlated.
When this turns negative, this can mean that we are on a turning point:
--> VVIX is rising while VIX is falling, risk of future Volatility is increasing (Top)
--> VIX is rising while VVIX is falling, risk of future Volatility is decreasing (Bottom)
Another use-case is just checking the correlation of stocks in your portfolio to diversify.
Open Close Cross Strategy R6.1 revised by yourmattieOriginal version: Open Close Cross Strategy R5 revised by JustUncle.
Change: script changed to a study script with custom alerts.
This revision is an open Public release, with just some minor changes. It is a revision of the Strategy "Open Close Cross Strategy R2" originally published by @JayRogers.
Revised by JustUncleL
Description :
Strategy based around Open-Close Moving Average Crossovers optionally from a higher time frame.
Read more about the indicator original script
Klik here
##USE AT YOUR OWN RISK##
Use this as overlayer on the original strategy to set custom alerts.
Info: with this study script no buy/sell arrows show up op the chart.
Does some know a solution for this issue:
Issue: sometimes it gives a false signal because even when you set "one per bar close" the custom set alert might come halfway the bar....and it might be a false signal when the bar is closed
Does somone know a fix for this? I tried with barstate.iscomfirmed but it didn't work for me.
Ps. I'm not a developer...just changed the scipt by watching a youtube tutorial.
MACD With Trend Filter: Visual Backtest Module TemplateSample Strategy: MACD Crossover with trend filter options
MA Filter : Price Close Above MA, Search for Buy, Price Close Below MA, Search for Sell
ADX Filter : Take trade only when ADX is above certain treshold
MACD Signal : MACD Cross above signal line while under 0 line indicate Buy Signal
MACD Cross below signal line while above 0 line indicate Sell Signal
-----------------------------
Using Alert Module:
Enable Alert --> Enable TV's alert and plot signal to chart
Alert Type --> Set to take Buy only, Sell only or Both alert
----------------------------
Using Backtest Module:
Enable Backtest --> Enable Backtest simulation
Backtest Type --> Set to take Buy only, Sell only or Both
SL Type -->
ATR : Set SL in ATR times Multiplier below/above entry price
Fixed : Set SL in fixed point below entry point (in 'Dollar'). e.g. for Stocks -> 0.5 equals to 50cent while for EURUSD currency -> 0.005 equal to 50 pips
HiLo Bar : Set SL at highest/lowest wick of previous bar plus/minus Fixed point. e.g. EURUSD HiLo=3 and Fixed Point = 0.0005, buy trade will place SL 5 Pips below lowest of previous 3 bar
SL ATR Period --> Set Lookback Period used for SL's ATR calculation
SL ATR Multi --> Set ATR Multiplier for SL
SL Fixed --> Set Fixed Level for SL (Use when SL Type is either Fixed or HiLo Bar)
SL Bar --> Set Number of previous bar to check for SL placement
TP RR Ratio --> Set TP based on RR multiplier. e.g. 2 means TP level will be twice further from entry point compared to Entry-SL distance.
Notes: The point is for preliminary testing, so it only supports 1 trade at a time and no Trailing Stop
----------------------------
Disclaimer:
This script main objective is to create my personal indicator template so that i just have to modify the indicator module for preliminary testing in future.
Testing Alert Module so i can re-use it as template in future study/indicator
Testing Visual Backtest Module so i can re-use it as template in future study/indicator
i believe using Strategy function is a better approach for this but the entry/exit level seems to be hit n miss (at least for me, still trying to figure what i did wrong)
also, i rather code the strategy in other platform where i can use the more accurate tick data if i want to validate backtest statistics.
My study scripts was built only to test/visualize an idea to see its viability and if it can be used to optimize existing strategy.
credit: ADX code are originally from "ADX and DI" by @BeikabuOyaji although i re-wrote so i can have cleaner read and use RMA instead of SMA
Trend Trader Buy/Sell SignalsTrend Trader
The code is open source, what it uses to print signals is MACD cross and ADX. Bar colors change in relation to where price is according to the 50 day MA. The MA ribbon is used for visualizing trend and using it for dynamic support/resistance. The ribbon is comprised of the 50 day and 100 day MAs.
Main reason to publish this script is because some like to jumble up scripts together slap some moving averages on it to "follow trend" and then label it an algorithm, market it and sell it to people online. No single system will work 100% of the time, do you due diligence in anything you are interested in buying. Plenty of free scripts in the TV library that can do you justice when trading.
One Percent Move Study (For your Alerts)This is a simple script that can be used to alerts. The signal1 variable goes to 100 if there is a 1% up move in a tick, and goes to -100 if there is a 1% down move in a tick for an asset. This is best on a 1 minute or 5 minute chart.
This example shows this on the DeFi exchange Uniswap for the UNI/ETH pair
BTC & ETH Alert SystemWith Tradingview's free plan, only one alert is allowed. The purpose of this indicator is to allow for two alerts--one for BTC and one for ETH.
How to use the alert system:
1. Set the desired value for BTC and ETH that you want to be alerted for
2. Set an alert on the indicator by clicking the three ellipses and then "Add Alert"
3. Set the alert to go off if the value of the indicator is greater than 0.
The example is of BTC using an alert of $10,000 and an alert of ETH at $2,000 (untriggered)
The script can be easily modified to be used for different assets
RSI, STOCHASTIC, KELTNER AND EMA CROSSES COMBINEDI have combined RSI and Stochastic but also added an keltner channel and then also two EMA's.
How the indicator works is the background turns green when the rsi and stochastic are below 20 and the keltner channel is below X and also your fast ema is below your slow ema and then vice versa for sell signals.
Feel free to leave a comment on what you think and what could be improved on it because i know their is some fine tuning to do and some improvement that can be made and I'm sure i'll be updating this myself.
All the variables are interchangable and the indicator has alert functionality.
TST Signals & AlertsThis is an unofficial script for strategies tested on Trading Strategy Testing Youtube channel. Over time, most successful strategies will be added with an option to set strategy-specific alerts . TST Signals & Alerts will draw signals on the chart when the entry conditions are met. You can also opt for displaying indicators .
My script is meant for beginners but can be used by veterans too. Just pick one or two strategies, you don't want to flood your chart with conflicting signals. You may want to support your trades with a proper analysis. Is the market trending? Is there a fundament around the corner?
If a new signal occurs when there is still an open position, you are not supposed to take another.
The current version includes MACD and ADX + BB and BB strategies.
MACD strategy:
►Buy, when MACD crosses below the signal line when it is negative. The price must also be above 200 EMA.
►Sell, when MACD crosses above the signal line when it is positive. The price must also be below 200 EMA.
►This strategy was tested on 15-minute charts of EURUSD with reward-to-risk ratio 1,5 and win rate of 61% over 100 trades.
►►►MACD has to be added to your chart separately because it needs a new window. Ticking display indicators will not add MACD to your chart.
►►►MACD was also tested by a different channel I made a script for. You can view the results and the script here:
ADX + BB strategy:
►Buy, when the price is above 200 EMA and ADX becomes higher than 25.
►Sell, when the price is below 200 EMA and ADX becomes higher than 25.
►Stop-loss is either 200 EMA or Bollinger Bands level. Check the channel for more information.
►This strategy was tested on 5-minute charts of EURUSD, USDJPY, AUDUSD with reward-to-risk ratio 1,2 and win rate of 56% over 100 trades in total.
BB strategy:
►Buy, when the price is above 200 EMA and candle's low is below the lower Bollinger Band.
►Sell, when the price is below 200 EMA and candle's high is above the upper Bollinger Band.
►This strategy was tested on 15-minute charts of EURUSD with reward-to-risk ratio 1,5 and win rate of 52% over 100 trades in total.
►►►Due to the relatively low win rate of this strategy, you need to filter out potentially harmful signals with a proper analysis.
Bear in mind that backtesting performance doesn't guarantee future profitability. • Most systematic strategies are not suitable for each timeframe - if you use the different timeframe than the one it was tested on, the result can differ significantly. • You should perform your own backtest to base your trades on more data & to establish confidence in the selected strategy. • This script is not a replacement for proper analysis.
New strategies will be added when I have time. If I see multiple people asking for the same feature, I might agree to release it with a new version. I am not going to add input options in this script, it could come as a separate script though. I am in no way affiliated with the Youtube channel, so if you find the script helpful, shot me a message or send me some TradingView coins >)
If you encounter any bug, you can report it in a message or in comments. Support it with screenshot and relevant information such as a time when it occurred and what options were on etc.
Trading Rush Signals & AlertsThis is an unofficial script for strategies tested on TRADING RUSH Youtube channel. Over time, most successful strategies will be added with an option to set strategy-specific alerts . Trading Rush Signals & Alerts will draw signals on the chart when the entry conditions are met. You can also opt for displaying indicators .
My script is meant for beginners but can be used by veterans too. Just pick only one or two strategies, you don't want to flood your chart with conflicting signals. You may want to support your trades with a proper analysis. If a new signal occurs when there is still an open position, you are not supposed to take another.
The current version includes MACD and Donchian Channels.
MACD strategy:
►Buy, when MACD crosses below the signal line when it is negative. The price must also be above 200 EMA.
►Sell, when MACD crosses above the signal line when it is positive. The price must also be below 200 EMA.
►This strategy was tested on 30-minute charts of EURUSD and EURJPY with reward-to-risk ratio 1,5 and win rate of 62% over 100 trades .
►►►MACD has to be added to your chart separately because it needs a new window. Indicators displaying will not add this indicator to the chart.
Donchian Channels strategy:
►Buy, when the price breaches Donchian to the upside after making a new low. The price must also be above 200 EMA.
►Sell, when the price breaches Donchian to the downside after making a new high. The price must also be below 200 EMA.
►Stop-loss is Donchian bottom for long and Donchian top for shorts. Check the channel for more information.
►This strategy was tested on 30-minute charts of EURUSD with reward-to-risk ratio 1,5 and win rate of 58% over 100 trades .
►►►I programmed alerts for Donchians to come ahead of an actual breach. If you often leave the screen when trading, this will help you. The necessary downside for that is the alerts might come when the signal doesn't trigger in the end. You will see a mark on the chart if the conditions are truly met.
Bear in mind that backtesting performance doesn't guarantee future profitability. • Most systematic strategies are not suitable for any timeframe. • You should perform your own backtest to base your trades on more data & to establish confidence in the selected strategy.
New strategies will be added when I have time. If I see multiple people asking for the same new feature, I might agree to release it with a new version. I am not going to add input options in this script, it could come as a separate script though. I am in no way affiliated with the Youtubechannel , so if you find the script helpful, shot me a message or send me some TradingView coins >)
If you encounter any bug, you can report it in a message or in comments. Support it with screenshot and relevant information such as a time when it occurred and what options were on etc.
[KK]EMA Breakout,1st retest,Peak BreakoutThis script gives Signal based on 3 parameters
(1) Exponential Moving average breakout
(2)Retest after Breakout
(3) Peak Breakout after retest for conformation
Recommended Settings:
(1) EMA Length = 20 period
(2)Left Bars= Right Bars = 4
(3)15min chart resolution
Note: Default setting is what recommended.
Interpretation:
(1)Green Background = Higher Peak Breakout candle after conformed retest
(2)Red Background = Lower Peak Breakout candle after conformed retest
(3) Green circle = 1st Upward Breakout candle after conformed retest ( if previous breakout is Downward)
(4)Red circle = 1st Downward Breakout candle after conformed retest ( if previous breakout is Upward)
Note: you can additionally add backgrounds for EMA breakout and conformed Retest from code.
Signals:
(1)Long = When Green circle
(2)Short = When Red circle
This script works with any ticker id. Best Use for Equity and Forex Markets. Also, added alert condition for green and red circle.
P.S.: Thanks to @RagingRocketBull for source code for breakout candles
Fancy strategy alerts example [QuantNomad]Alerts on strategies were introduced just recently in TradingView.
These alerts have an alert_message placeholder which allows you to compose in PineScript very complex alerts and insert quite a lot of information in them.
This is just very simple example of how they can look like.
Vertical Horizontal Moving Average [AneoPsy & alexgrover] Moving average adapting to the strength of the trend, this is made possible by using the square of the vertical-horizontal filter as a smoothing factor. Alerts are included with two different types of conditions available to the user.
Settings
Length : Period of the moving average
Src : Input data for the indicator
Alerts : Types of conditions to be used in the alerts, when set to "VHMA Direction Change" alerts are triggered once the VHMA is either rising or declining, else the alerts are based on the crosses between Src and the VHMA
Usage
The VHMA can be used as a fast or slow-moving average in a moving average crossover system, or as input for other indicators.
VHMA of with length = 25 and sma with length = 200.
VHMA with length = 25 used as input for the RSI with length = 14.
Details
The vertical-horizontal filter is a measure of the strength of the trend and lay in a (0,1) range, to calculate it you just need to divide the rolling range over with the rolling sum of the absolute price changes, squaring the result allow to get lower results with higher values of length .
Squared vertical horizontal filter with length = 50, the value is low when the market is ranging and high when trending.
To set the alerts go in the alert panel, click on create alert, and select VHMA in "condition", choose between the buy or sell alert. If Src = closing price or another indicator dependant on the closing price select in options "once per bar close", if the indicator using the opening or lagged closing prices values as input select "One per bar" instead.
Thanks
Thanks to AneoPsy for adding the color change, the idea to use two kinds of conditions for the alert, and for its feedback, you can follow him
www.tradingview.com
and finally thanks to you for reading and for your support, only one last script left for the month, then we'll start July with some pretty interesting indicators, I hope you'll like them ^^/
ck - EMA Cross with AlertsDisplays 5 popular EMAs (you can hide any you don’t want to see from the “Styles” screen when editing the config).
Set the values for your EMAs by clicking the cog after adding this indicator to your chart.
A Long or Short signal is fired when EMA1 crosses EMA2 - a cross up is a Long signal, a cross down is a Short signal.
Connect to your Bots (3commas / 3C.exchange recommended) to automate buys and sells!
Trend Follow with kijun-sen/tenkan sen for 1 Hour SPX
This script determines, plots and alerts on probable trend initiation and continuation points, using tenkan-sen(conversion line of ichimoku), kijun-sen(baseline of ichimoku) and stochastic RSI, for 1 H SPX.
New long/short trend initiates when prices cross above/below kijun sen. The trend continues when prices cross above/below tenkan-sen or stochastic RSI crosses up/down its signal line, while prices are above/below kijun-sen.
It is good to take partial profit between 10-15 points gain and trail the left with stops below kijun-sen line.
While placing the order, using 2-3 points buffer above/below of signal bars is recommended. Additionally, please be careful about clouds and do not place long/short orders below/above clouds.
RSI LookbackChecks RSI High/Low X candles in the past
Displays Green/Red circles at bottom of chart
Sends alerts
Alert Intervals and Delays Framework [BigBitsIO]Simply explained, this script, when modified to each specific use case, can allow you to specify that alert conditions are only checked every X seconds (AKA Intervals - as fast as every single second) and that alerts can not occur quicker than the user-specified delay (in seconds)
Explained:
- This will work on any resolution, but for the best results/fastest alerts a premium plan with 1s resolution will work best.
- Be mindful of which alert option you choose when setting up corresponding alerts. On 1s resolution with alerts once per bar you can get alerts up to every second.
- The scan for alerts every X seconds will be when the script can scan, by default every 5th second. If you want it to scan on any and all updates, set it to 1 for 1 second
- The delay between alerts will just require than that many seconds have passed since the last alert was fired (whether it was an actual alert in TradingView or just as recognized by this script)
- To have a custom alert condition met, do your normal indicator logic and check your conditions during the scanning period after the delay has been met, as marked by comments in the code
FAQ
- Why is this script useful?
- Many people do not want to constantly monitor for alerts, and may only want alerts to trigger at certain times, or after certain periods of time
- What is an example?
- You want a 1min resolution RSI alert, but you don't want to see it every minute, or only once.
- By setting your alert to once per bar, or once per minute on a 1min or less resolution chart you can get alerts only every 2min 30sec for example when setting your delay to 150 (seconds)
Warning: Since the scan time and alert times on larger resolutions can not be accessed from previous candles when first added to the chart it should be pretty important that you operate on a chart with a smaller resolution than your delay.
Fixed Percent Stop Loss & Take Profit % - For Study Scripts===========
Fixed Percent Stop Loss & Take Profit % - { FOR STUDY SCRIPTS! }
===========
A neat example of how to set up Fixed Stops and Take Profit as a percent of the entry price - This is for setting Alerts within your own Study Script for when either your SL or TP get hit.
Yup, that's about it!
You can ignore the actual entry/exit orders - they're based on a simple MA cross and are therefore NOT relevant, NOT profitable and NOT recommended!
You should be using this code as a way of adding Stops and Takes to your own scripts - hope it helps!
Set your "Open Long/Short" Alerts to be triggered "Once per Bar Close" - Set your "SL/TP" Alerts to trigger "Once per Bar".
--
We wrote this with a bit of a rush on! ~ If you spot any mistakes/bugs just let us know and we'll get round to them asap!
-----------
Good Luck and Happy Trading!
Auto Fib Retracement AlertsFor the fibonacci traders.
The Auto Fib Retracement Is a good indicator for tradingview to show you the current alerts and points to watch in the market
IMPORTANT SETTING => Retracement
This controls your alert levels
I have modified it to deliver the following
+Custom Fib retracement level alerts
+Drawing of old levels and retracement levels
+Backtesting Old Alerts
There are two shapes drawn on the chart;
Shown When the fib end is attained and market retraces back to your level
1. Buy retracement -
2. Sell retracement
How are they detected?
When we have new levels in the market; this is when the red or gree line changes, we calculate the new fib level that we will be watching for retracement
This is the purple level drawn on the chart
When the market first crosses below or above this level, The alert will be fired.
Consequent crosses are not updated
Enjoy! 😍
Originally requested by trade atechproduction
MTF Trailing SL Alerts [QuantNomad]These are alerts for my MTF Trailing SL Strategy.
Entry Long position if all 4 time-frames agree on the long signal.
Exit Long positions when at least 2 time-frames disagree on the long signals.
Entry to Short position if all 4 time-frames agree on Short signal.
Exit from Short positions when at least 2 time-frames disagree on Short signal.
Use "Once Per Bar Close" when creating alerts.
Link to the strategy:
Parabolic SAR [with Algorithm and Alerts]Hello All,
In one of my projects I needed Parabolic SAR algorithm. I decided to write it in Pine and publish it. Then I added Alerts and Labels. here it is ;)
ENJOY!