0

Can anyone tell me how precisely to set up alerts on tradingview (i do know how to set up alerts..) specific to the "Strict Buy" criteria in the CM_Stochastic Highlight Bars indicator??? I have done a lot of searching but with little luck. Thank you :)strong text

1 Answer 1

0

Unfortunately, that script was not written very friendly to set up alerts. Luckily, the source code is available.

I have edited the code a little bit (it has the same functionality) so that it plots some shapes along with some text, and you can set up your alerts based on those shapes.

enter image description here

Wherever the original indicator has "S" or "B", my indicator has "Strict Sell" or "Strict Buy" triangles. So, the functionality is the same. Of course, when you add my indicator, it won't have those "S" or "B"s. Above chart has both indicators on.

Now you can simply do "Add Alerts" and select the new indicator (Stoch HL).

enter image description here

Then select "Shapes" and look at the drop-down menu and select the shape which you want to set up your alert based on.

enter image description here

Create a new indicator and copy&paste below code. Save it and then add it to your chart.

//@version=3
study("Stoch HL", overlay=true)

//Created by ChrisMoody on October 23, 2014 by user request - belgusinc
//Changes Barcolor when Stochastic is Overbought Oversold.

//Necessary for Highlight Bars
//Only Necessary if you want you want Stochastic Croses
len = input(14, minval=1, title="Length for Stochastic") 
smoothK = input(3, minval=1, title="SmoothK for Stochastic")
smoothD = input(3, minval=1, title="SmoothD for Stochastic")
upLine = input(80, minval=50, maxval=90, title="Upper Line Value?")
lowLine = input(20, minval=10, maxval=50, title="Lower Line Value?")

//Not Necessary, In Inputs Tab, capability to turn On/Off Highlight Bars, and Both Crosses
//These are all checkboxes in inputs tab....Show Barcolor Highlights, Show Background Hghlight, Plot B and S for Buy Sell 
sbc = input(true, title="Show Price Bar highlight When Stoch is Above/Below High/Low Lines?")
sbh = input(false, title="Show Background highlight When Stoch is Above/Below High/Low Lines?")
sch = input(false, title="Show Back Ground Highlights When Stoch Cross - Strict Criteria - K Greater/LesThan High/Low Line - Crosses D ?")
sl = input(true, title="Show 'B' and 'S' Letters When Stoch Crosses High/Low Line & D?")
sac = input(false, title="Show Back Ground Highlights When Stoch Cross - Any Cross?")
sacl = input(false, title="Show 'B' and 'S' Letters When Stoch Crosses - Any Cross?")

//Necessary for Highlight Bars
//Stoch formula
k = sma(stoch(close, high, low, len), smoothK)
d = sma(k, smoothD)

//Necessary for Highlight Bars
//aboveline = OverBought, belowline = Oversold Definitions
aboveLine = k > upLine ? 1 : 0
belowLine = k < lowLine ? 1 : 0

//Only Necessary if you want you want Stochastic Croses
//Definition for Cross when Above High-Low lines
crossUp = (k[1] < d[1] and k[1] < lowLine[1]) and (k > d)  ? 1 : 0
crossDn = (k[1] > d[1] and k[1] > upLine[1]) and (k < d) ? 1 : 0

//Only Necessary if you want you want Stochastic Croses
//Definition for Cross that doesn't have to be above or below High and Low line.
crossUpAll = (k[1] < d[1] and k > d) ? 1 : 0
crossDownAll = (k[1] > d[1] and k < d) ? 1 : 0

//Only Necessary if you want background Highlighting also - Take out the sbh/sbc and part
//BackGround Highlights based on Above/Below Lines, Strict Cross Up/Down
//BackGroound Color Plots
bgcolor(sbh and aboveLine ? red : na, transp=70)
bgcolor(sbh and belowLine ? lime : na, transp=70)
bgcolor(sch and crossUp ? lime : na, transp=40)
bgcolor(sch and crossDn ? red : na, transp=40)

//Only Necessary if you want background Highlighting also
//plots bgcolor Cross with no filter
bgcolor(sac and crossUpAll ? lime : na, transp=40)
bgcolor(sac and crossDownAll ? red : na, transp=40)

//Necessary for Highlight Bars
//Highlight Bar Definitions
overBought() => sbc and aboveLine 
overSold() => sbc and belowLine 

//Necessary for Highlight Bars
//Highlight Bar Plot Statement based on Above Definitions
barcolor(overBought() ? orange : overSold() ? fuchsia : na)

// Buy and Sell Conditions
bssc = sl and crossUp ? crossUp : na
sssc = sl and crossDn ? crossDn : na
bscu = sacl and crossUpAll ? crossUpAll : na
sscd = sacl and crossDownAll ? crossDownAll : na

//Not Necessary if you just want Highlight Bars  - Extra Feature
//These are just the Letters B and Sell Based on Crosses
alertcondition(condition=bssc, title="Strict Buy", message="Buy Signal Strict Criteria.")
alertcondition(condition=sssc, title="Strict Sell", message="Sell Signal Strict Criteria.")
alertcondition(condition=bscu, title="Buy Cross Up", message="Buy Signal Any Cross Up.")
alertcondition(condition=sscd, title="Sell Cross Down", message="Sell Signal Any Cross Down.")

plotshape(bssc, style=shape.triangleup, color=lime, transp=40, text="Strict Buy", editable=false, location=location.belowbar, size=size.small)
plotshape(sssc, style=shape.triangledown, color=red, transp=40, text="Strict Sell", editable=false, location=location.abovebar, size=size.small)
plotshape(bscu, style=shape.triangleup, color=lime, transp=40, text="Buy Cross Up", editable=false, location=location.belowbar, size=size.small)
plotshape(sscd, style=shape.triangledown, color=red, transp=40, text="Sell Cross Down", editable=false, location=location.abovebar, size=size.small)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.