xmd79

CM_Stochastic_MTF

Jan 14th, 2022
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. //@version=5
  2.  
  3. //Created by ChrisMoody on October 23, 2014 by user request - platinumFX
  4. //Defaults to current timeframe Ability to change to different timeframe, or plot two RSI's on different timeframes.
  5. indicator(title='CM_Stochastic_MTF', shorttitle='CM_Stoch_MTF')
  6. len = input.int(14, minval=1, title='Length for Main Stochastic')
  7. smoothK = input.int(3, minval=1, title='SmoothK for Main Stochastic')
  8. smoothD = input.int(3, minval=1, title='SmoothD for Main Stochastic')
  9. upLine = input.int(80, minval=50, maxval=90, title='Upper Line Value?')
  10. lowLine = input.int(20, minval=10, maxval=50, title='Lower Line Value?')
  11. sml = input(true, title='Show Mid Line?')
  12. sbh = input(false, title='Show Back Ground Highlights When Stoch is Above/Below High/Low Lines?')
  13. sch = input(true, title='Show Back Ground Highlights When Stoch Cross - Strict Criteria - K Greater/LesThan High/Low Line - Crosses D ?')
  14. sl = input(true, title='Show \'B\' and \'S\' Letters When Stoch Crosses High/Low Line & D?')
  15. sac = input(false, title='Show Back Ground Highlights When Stoch Cross - Any Cross?')
  16. sacl = input(false, title='Show \'B\' and \'S\' Letters When Stoch Crosses - Any Cross?')
  17. useCurrentRes = input(true, title='Use Current Chart Resolution?')
  18. resCustom = input.timeframe(title='Use Different Timeframe? Uncheck Box Above', defval='60')
  19. ssStoch = input(false, title='Show 2nd Stoch?')
  20. resCustom2 = input.timeframe(title='Use 2nd Stoch? Check Box Above', defval='D')
  21. useCurrentRes2 = input(false, title='Use 2nd Stoch Plot On Samet Timeframe?')
  22. len2 = input.int(14, minval=1, title='2nd Stoch Length')
  23. smoothK2 = input.int(3, minval=1, title='SmoothK for 2nd Stoch')
  24. smoothD2 = input.int(3, minval=1, title='SmoothD for 2nd Stoch')
  25. //Resolutioon for MTF
  26. res = useCurrentRes ? timeframe.period : resCustom
  27. res2 = useCurrentRes2 ? timeframe.period : resCustom2
  28. //Stoch formula
  29.  
  30. inp = input(close)
  31.  
  32. k = ta.sma(ta.stoch(inp, high, low, len), smoothK)
  33. d = ta.sma(k, smoothD)
  34. outK = request.security(syminfo.tickerid, res, k)
  35. outD = request.security(syminfo.tickerid, res, d)
  36. //Optional 2nd Stoch for additional plot
  37. k2 = ta.sma(ta.stoch(inp, high, low, len2), smoothK2)
  38. d2 = ta.sma(k2, smoothD2)
  39. outK2 = request.security(syminfo.tickerid, res2, k2)
  40. outD2 = request.security(syminfo.tickerid, res2, d2)
  41. //definitions for Cross
  42. aboveLine = outK > upLine ? 1 : 0
  43. belowLine = outK < lowLine ? 1 : 0
  44. crossUp = outK[1] < outD[1] and outK[1] < lowLine[1] and outK > outD ? 1 : 0
  45. crossDn = outK[1] > outD[1] and outK[1] > upLine[1] and outK < outD ? 1 : 0
  46. //Definition for Cross that doesn't have to be above or below High and Low line.
  47. crossUpAll = outK[1] < outD[1] and outK > outD ? 1 : 0
  48. crossDownAll = outK[1] > outD[1] and outK < outD ? 1 : 0
  49. //BackGroound Color Plots
  50. bgcolor(sbh and aboveLine ? color.red : na, transp=70)
  51. bgcolor(sbh and belowLine ? color.lime : na, transp=70)
  52. bgcolor(sch and crossUp ? color.lime : na, transp=40)
  53. bgcolor(sch and crossDn ? color.red : na, transp=40)
  54. //plots for Cross with no filter
  55. bgcolor(sac and crossUpAll ? color.lime : na, transp=40)
  56. bgcolor(sac and crossDownAll ? color.red : na, transp=40)
  57. //Plot main Stochastic
  58. plot(outK, title='Stoch K', style=plot.style_line, linewidth=3, color=color.new(color.lime, 0))
  59. plot(outD, title='Stoch D', style=plot.style_line, linewidth=3, color=color.new(color.red, 0))
  60. //Ability to plot 2nd Stoch
  61. plot(ssStoch and outK2 ? outK2 : na, title='2nd Stoch K - Different TimeFrame', style=plot.style_line, linewidth=3, color=color.new(color.orange, 0))
  62. plot(ssStoch and outD2 ? outD2 : na, title='2nd Stoch D - Different TimeFrame', style=plot.style_line, linewidth=3, color=color.new(color.yellow, 0))
  63.  
  64. p1 = plot(upLine, title='Upper Line', style=plot.style_line, linewidth=3, color=color.new(color.red, 0))
  65. p2 = plot(lowLine, title='Lower Line', style=plot.style_line, linewidth=3, color=color.new(color.lime, 0))
  66. plot(sml and 50 ? 50 : na, title='Mid Line', style=plot.style_linebr, linewidth=2, color=color.new(color.gray, 0))
  67. plotchar(sl and crossUp ? crossUp : na, title='Buy Signal Strict Criteria', char='B', location=location.bottom, color=color.new(color.lime, 0), offset=0)
  68. plotchar(sl and crossDn ? crossDn : na, title='Sell Signal Strict Criteria', char='S', location=location.top, color=color.new(color.red, 0), offset=0)
  69. 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)
  70. 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)
  71. fill(p1, p2, color=color.new(color.silver, 70))
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment