Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- //Created by ChrisMoody on October 23, 2014 by user request - platinumFX
- //Defaults to current timeframe Ability to change to different timeframe, or plot two RSI's on different timeframes.
- indicator(title='CM_Stochastic_MTF', shorttitle='CM_Stoch_MTF')
- len = input.int(14, minval=1, title='Length for Main Stochastic')
- smoothK = input.int(3, minval=1, title='SmoothK for Main Stochastic')
- smoothD = input.int(3, minval=1, title='SmoothD for Main Stochastic')
- upLine = input.int(80, minval=50, maxval=90, title='Upper Line Value?')
- lowLine = input.int(20, minval=10, maxval=50, title='Lower Line Value?')
- sml = input(true, title='Show Mid Line?')
- sbh = input(false, title='Show Back Ground Highlights When Stoch is Above/Below High/Low Lines?')
- sch = input(true, 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?')
- useCurrentRes = input(true, title='Use Current Chart Resolution?')
- resCustom = input.timeframe(title='Use Different Timeframe? Uncheck Box Above', defval='60')
- ssStoch = input(false, title='Show 2nd Stoch?')
- resCustom2 = input.timeframe(title='Use 2nd Stoch? Check Box Above', defval='D')
- useCurrentRes2 = input(false, title='Use 2nd Stoch Plot On Samet Timeframe?')
- len2 = input.int(14, minval=1, title='2nd Stoch Length')
- smoothK2 = input.int(3, minval=1, title='SmoothK for 2nd Stoch')
- smoothD2 = input.int(3, minval=1, title='SmoothD for 2nd Stoch')
- //Resolutioon for MTF
- res = useCurrentRes ? timeframe.period : resCustom
- res2 = useCurrentRes2 ? timeframe.period : resCustom2
- //Stoch formula
- inp = input(close)
- k = ta.sma(ta.stoch(inp, high, low, len), smoothK)
- d = ta.sma(k, smoothD)
- outK = request.security(syminfo.tickerid, res, k)
- outD = request.security(syminfo.tickerid, res, d)
- //Optional 2nd Stoch for additional plot
- k2 = ta.sma(ta.stoch(inp, high, low, len2), smoothK2)
- d2 = ta.sma(k2, smoothD2)
- outK2 = request.security(syminfo.tickerid, res2, k2)
- outD2 = request.security(syminfo.tickerid, res2, d2)
- //definitions for Cross
- aboveLine = outK > upLine ? 1 : 0
- belowLine = outK < lowLine ? 1 : 0
- crossUp = outK[1] < outD[1] and outK[1] < lowLine[1] and outK > outD ? 1 : 0
- crossDn = outK[1] > outD[1] and outK[1] > upLine[1] and outK < outD ? 1 : 0
- //Definition for Cross that doesn't have to be above or below High and Low line.
- crossUpAll = outK[1] < outD[1] and outK > outD ? 1 : 0
- crossDownAll = outK[1] > outD[1] and outK < outD ? 1 : 0
- //BackGroound Color Plots
- bgcolor(sbh and aboveLine ? color.red : na, transp=70)
- bgcolor(sbh and belowLine ? color.lime : na, transp=70)
- bgcolor(sch and crossUp ? color.lime : na, transp=40)
- bgcolor(sch and crossDn ? color.red : na, transp=40)
- //plots for Cross with no filter
- bgcolor(sac and crossUpAll ? color.lime : na, transp=40)
- bgcolor(sac and crossDownAll ? color.red : na, transp=40)
- //Plot main Stochastic
- plot(outK, title='Stoch K', style=plot.style_line, linewidth=3, color=color.new(color.lime, 0))
- plot(outD, title='Stoch D', style=plot.style_line, linewidth=3, color=color.new(color.red, 0))
- //Ability to plot 2nd Stoch
- plot(ssStoch and outK2 ? outK2 : na, title='2nd Stoch K - Different TimeFrame', style=plot.style_line, linewidth=3, color=color.new(color.orange, 0))
- plot(ssStoch and outD2 ? outD2 : na, title='2nd Stoch D - Different TimeFrame', style=plot.style_line, linewidth=3, color=color.new(color.yellow, 0))
- p1 = plot(upLine, title='Upper Line', style=plot.style_line, linewidth=3, color=color.new(color.red, 0))
- p2 = plot(lowLine, title='Lower Line', style=plot.style_line, linewidth=3, color=color.new(color.lime, 0))
- plot(sml and 50 ? 50 : na, title='Mid Line', style=plot.style_linebr, linewidth=2, color=color.new(color.gray, 0))
- plotchar(sl and crossUp ? crossUp : na, title='Buy Signal Strict Criteria', char='B', location=location.bottom, color=color.new(color.lime, 0), offset=0)
- plotchar(sl and crossDn ? crossDn : na, title='Sell Signal Strict Criteria', char='S', location=location.top, color=color.new(color.red, 0), offset=0)
- plotchar(sacl and crossUpAll ? crossUpAll : na, title='Buy Signal Any Cross Up', char='B', location=location.bottom, color=color.new(color.lime, 0), offset=0)
- plotchar(sacl and crossDownAll ? crossDownAll : na, title='Sell Signal Any Cross Down', char='S', location=location.top, color=color.new(color.red, 0), offset=0)
- fill(p1, p2, color=color.new(color.silver, 70))
Advertisement
Add Comment
Please, Sign In to add comment