BKHXLTON
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: November 5th, 2020
Contact: TradingView Profile

A script for a divergence alert?

Has anyone coded a script to alert when price diverges from an oscillator (like a stoch)?

User avatar
ocaptain
Pine Script Scholar
Pine Script Scholar
Posts: 33
Joined: September 28th, 2020
Location: Cornelius, NC
Contact: Website TradingView Profile

Re: A script for a divergence alert?

I haven't set an alert but I do have an indicator that shows me when RSI is divergent from the Trend...

You can look at my code here:

https://www.tradingview.com/script/i3AP ... h-Low-RSI/

and it would be easy enough to basically track the last 4 pivots with 4 variables to see if you are in an uptrend or downtrend (i.e. pivot 3 is > pivot 1 AND pivot 4 > pivot 2), and then use 2 variables for the RSI to see if you have divergence, (lastRSI and currentRSI) and if we are in an uptrend and currentRSI < prevRSI then you have divergence, and vice-versa.

Don't know if this is the type of divergence you are looking for (RSI v. Trend) but I hope it inspires you to move forward with whatever Oscillator you are looking for to give you the results you need.

Trade well!

-Anthony
Trade Hard, and Trade Well!

-Anthony
--------------------------------
:long: Find Me on TradingView
:student: Trade with me at Sabre Trading Systems

User avatar
Matthew
Site Admin
Site Admin
Posts: 92
Joined: July 1st, 2020
Location: Australia
Contact: Website Facebook Twitter TradingView Profile

Re: A script for a divergence alert?

This is a great question and something high on my list of ideas to explore when I get time. I'll let you know if I ever come up with anything useful, I'll definitely share it on this forum.

In the meantime Anthony's work is definitely worth looking into and I'm sure you'll find some inspiring ideas there! Good luck with your search :)

Return to “Request Scripts”