xmd79

Multi-Timeframe Double Smoothed Stochastics (DSS) by William Blaw

Jun 17th, 2022
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.83 KB | None | 0 0
  1. //@version=5
  2. //Multi-Timeframe Double Smoothed Stochastics (DSS) by William Blaw.
  3.  
  4. indicator(title='MTF DSS (Double Smoothed Stochastic)', shorttitle='MTF DSS')
  5.  
  6. checkFirst = input.bool(false, title="*READ FIRST* To prevent repainting, leave timeframes as 'Chart' and set 'TF Mult.' fields'.\nExample: If current timeframe is 15 minutes and you want a 2nd timeframe of 1 hour, set #2 'TF Mult.' to '4' (4 x 15 minutes = 1 hour)\n Only timeframes that are greater or equal to a chart's current timeframe can be used. (incorrect data will be displayed otherwise)",confirm=true)
  7.  
  8. show1 = input(true,title="#1",inline="1")
  9. show2 = input(true,title="#2",inline="2")
  10. show3 = input(true,title="#3",inline="3")
  11. show4 = input(true,title="#4",inline="4")
  12. show5 = input(true,title="#5",inline="5")
  13.  
  14. res1 = input.timeframe(title='', defval='',inline="1")
  15. res2 = input.timeframe(title='', defval='',inline="2")
  16. res3 = input.timeframe(title='', defval='',inline="3")
  17. res4 = input.timeframe(title='', defval='',inline="4")
  18. res5 = input.timeframe(title='', defval='',inline="5")
  19.  
  20. mult1 = input.int(1,title='TF Mult.',minval=1,inline="1")
  21. mult2 = input.int(1,title='TF Mult.',minval=1,inline="2")
  22. mult3 = input.int(1,title='TF Mult.',minval=1,inline="3")
  23. mult4 = input.int(1,title='TF Mult.',minval=1,inline="4")
  24. mult5 = input.int(1,title='TF Mult.',minval=1,inline="5")
  25.  
  26. Periods = input.int(10, minval=1,title="Periods",group="DSS")
  27. EMAlen = input.int(9, minval=1,title="EMA Length",group="DSS")
  28. TriggerLen = input.int(5, minval=1,title="Trigger Length",group="DSS")
  29.  
  30. showSig = input(true,title="Show single directional signals",group="Signals")
  31. showCombinedSig = input(true, title="Show combined directional signals (MTF)",group="Signals")
  32.  
  33. showOB = input(true,title="",group="Overbought / Oversold",inline="ob")
  34. showMID = input(true,title="",group="Overbought / Oversold",inline="mid")
  35. showOS = input(true,title="",group="Overbought / Oversold",inline="os")
  36. Overbought = input.int(80, minval=0, maxval=100,group="Overbought / Oversold",inline="ob")
  37. midline = input.int(50, minval=0, maxval=100,group="Overbought / Oversold",inline="mid")
  38. Oversold = input.int(20, minval=0, maxval=100,group="Overbought / Oversold",inline="os")
  39.  
  40. calc_DSS(_TFmult) =>
  41. xPreCalc = ta.ema(ta.stoch(close, high, low, Periods*_TFmult), EMAlen*_TFmult)
  42. xDSS = ta.ema(ta.stoch(xPreCalc, xPreCalc, xPreCalc, Periods*_TFmult), EMAlen*_TFmult)
  43. xTrigger = ta.ema(xDSS, TriggerLen*_TFmult)
  44. //sigCol = xDSS > TriggerLen ? color.new(color.lime,90) : color.new(color.red,90)
  45.  
  46. [xPreCalc,xDSS,xTrigger]
  47.  
  48. [xPreCalc_1,xDSS_1,xTrigger_1] = request.security(syminfo.tickerid, res1, calc_DSS(mult1))
  49. [xPreCalc_2,xDSS_2,xTrigger_2] = request.security(syminfo.tickerid, res2, calc_DSS(mult2))
  50. [xPreCalc_3,xDSS_3,xTrigger_3] = request.security(syminfo.tickerid, res3, calc_DSS(mult3))
  51. [xPreCalc_4,xDSS_4,xTrigger_4] = request.security(syminfo.tickerid, res4, calc_DSS(mult4))
  52. [xPreCalc_5,xDSS_5,xTrigger_5] = request.security(syminfo.tickerid, res5, calc_DSS(mult5))
  53.  
  54. sigCol1 = xDSS_1 > xTrigger_1 ? color.new(color.lime,90) : color.new(color.red,90)
  55. sigCol2 = xDSS_2 > xTrigger_2 ? color.new(color.lime,90) : color.new(color.red,90)
  56. sigCol3 = xDSS_3 > xTrigger_3 ? color.new(color.lime,90) : color.new(color.red,90)
  57. sigCol4 = xDSS_4 > xTrigger_4 ? color.new(color.lime,90) : color.new(color.red,90)
  58. sigCol5 = xDSS_5 > xTrigger_5 ? color.new(color.lime,90) : color.new(color.red,90)
  59.  
  60. sigCombinedUp = true
  61. sigCombinedDown = true
  62.  
  63. if show1
  64. if xDSS_1 > xTrigger_1
  65. sigCombinedDown := false
  66. else
  67. sigCombinedUp := false
  68. if show2
  69. if xDSS_2 > xTrigger_2
  70. sigCombinedDown := false
  71. else
  72. sigCombinedUp := false
  73. if show3
  74. if xDSS_3 > xTrigger_3
  75. sigCombinedDown := false
  76. else
  77. sigCombinedUp := false
  78. if show4
  79. if xDSS_4 > xTrigger_4
  80. sigCombinedDown := false
  81. else
  82. sigCombinedUp := false
  83. if show5
  84. if xDSS_5 > xTrigger_5
  85. sigCombinedDown := false
  86. else
  87. sigCombinedUp := false
  88.  
  89. ob1 = hline(show1 and showOB ? Overbought : na, color=show1 and showOB ? color.green : na, linestyle=hline.style_solid)
  90. mid1 = hline(show1 and showMID ? midline : na, color=show1 and showMID ? color.new(color.gray,80) : na, linestyle=hline.style_solid)
  91. os1 = hline(show1 and showOB ? Oversold : na, color=show1 and showOB ? color.red : na, linestyle=hline.style_solid)
  92. fill(ob1,os1,color=showSig ? sigCol1 : color.rgb(126, 87, 194, 93))
  93. ob2 = hline(show2 and showOB ? Overbought-100 : na, color=show2 and showOB ? color.green : na, linestyle=hline.style_solid)
  94. mid2 = hline(show2 and showMID ? midline : na, color=show2 and showMID ? color.new(color.gray,80) : na, linestyle=hline.style_solid)
  95. os2 = hline(show2 and showOB ? Oversold-100 : na, color=show2 and showOB ? color.red : na, linestyle=hline.style_solid)
  96. fill(ob2,os2,color=showSig ? sigCol2 : color.rgb(126, 87, 194, 93))
  97. ob3 = hline(show3 and showOB ? Overbought-200 : na, color=show3 and showOB ? color.green : na, linestyle=hline.style_solid)
  98. mid3 = hline(show3 and showMID ? midline : na, color=show3 and showMID ? color.new(color.gray,80) : na, linestyle=hline.style_solid)
  99. os3 = hline(show3 and showOB ? Oversold-200 : na, color=show3 and showOB ? color.red : na, linestyle=hline.style_solid)
  100. fill(ob3,os3,color=showSig ? sigCol3 : color.rgb(126, 87, 194, 93))
  101. ob4 = hline(show4 and showOB ? Overbought-300 : na, color=show4 and showOB ? color.green : na, linestyle=hline.style_solid)
  102. mid4 = hline(show4 and showMID ? midline : na, color=show4 and showMID ? color.new(color.gray,80) : na, linestyle=hline.style_solid)
  103. os4 = hline(show4 and showOB ? Oversold-300 : na, color=show4 and showOB ? color.red : na, linestyle=hline.style_solid)
  104. fill(ob4,os4,color=showSig ? sigCol4 : color.rgb(126, 87, 194, 93))
  105. ob5 = hline(show5 and showOB ? Overbought-400 : na, color=show5 and showOB ? color.green : na, linestyle=hline.style_solid)
  106. mid5 = hline(show5 and showMID ? midline : na, color=show5 and showMID ? color.new(color.gray,80) : na, linestyle=hline.style_solid)
  107. os5 = hline(show5 and showOB ? Oversold-400 : na, color=show5 and showOB ? color.red : na, linestyle=hline.style_solid)
  108. fill(ob5,os5,color=showSig ? sigCol5 : color.rgb(126, 87, 194, 93))
  109.  
  110. plot(showCombinedSig ? 120 : na,color=sigCombinedUp ? color.lime : (sigCombinedDown ? color.red : color.new(color.blue,90)),style=plot.style_circles)
  111.  
  112. plot(show1 ? xDSS_1 : na, color=color.new(color.blue, 0), title='DSS1')
  113. plot(show1 ? xTrigger_1 : na, color=color.new(color.red, 0), title='Trigger1')
  114. plot(show2 ? xDSS_2-100 : na, color=color.new(color.blue, 0), title='DSS2')
  115. plot(show2 ? xTrigger_2-100 : na, color=color.new(color.red, 0), title='Trigger2')
  116. plot(show3 ? xDSS_3-200 : na, color=color.new(color.blue, 0), title='DSS3')
  117. plot(show3 ? xTrigger_3-200 : na, color=color.new(color.red, 0), title='Trigger3')
  118. plot(show4 ? xDSS_4-300 : na, color=color.new(color.blue, 0), title='DSS4')
  119. plot(show4 ? xTrigger_4-300 : na, color=color.new(color.red, 0), title='Trigger4')
  120. plot(show5 ? xDSS_5-400 : na, color=color.new(color.blue, 0), title='DSS5')
  121. plot(show5 ? xTrigger_5-400 : na, color=color.new(color.red, 0), title='Trigger5')
  122.  
  123. showLabel = input(false,title="Show TimeFrame Labels",group="Label Settings")
  124.  
  125. setTime = time - time[1]
  126. setTime := ta.change(setTime) > 0 ? setTime[1] : setTime
  127.  
  128. var label label_res1 = na
  129. var label label_res2 = na
  130. var label label_res3 = na
  131. var label label_res4 = na
  132. var label label_res5 = na
  133.  
  134. label.delete(label_res1)
  135. label.delete(label_res2)
  136. label.delete(label_res3)
  137. label.delete(label_res4)
  138. label.delete(label_res5)
  139.  
  140. res1Display1 = res1
  141. if res1 == ""
  142. res1Display1 := "Chart"
  143. res1Display2 = res2
  144. if res2 == ""
  145. res1Display2 := "Chart"
  146. res1Display3 = res3
  147. if res3 == ""
  148. res1Display3 := "Chart"
  149. res1Display4 = res4
  150. if res4 == ""
  151. res1Display4 := "Chart"
  152. res1Display5 = res5
  153. if res5 == ""
  154. res1Display5 := "Chart"
  155. label_res1 := label.new(x=time + setTime * 48, y=show1 and showLabel ? 20 : na, text=res1Display1, textcolor=show1 and showLabel ? #FFFFFF : na, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price, tooltip="#1")
  156. label_res2 := label.new(x=time + setTime * 48, y=show2 and showLabel ? -80 : na, text=res1Display2, textcolor=show2 and showLabel ? #FFFFFF : na, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price, tooltip="#2")
  157. label_res3 := label.new(x=time + setTime * 48, y=show3 and showLabel ? -180 : na, text=res1Display3, textcolor=show3 and showLabel ? #FFFFFF : na, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price, tooltip="#3")
  158. label_res4 := label.new(x=time + setTime * 48, y=show4 and showLabel ? -280 : na, text=res1Display4, textcolor=show4 and showLabel ? #FFFFFF : na, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price, tooltip="#4")
  159. label_res5 := label.new(x=time + setTime * 48, y=show5 and showLabel ? -380 : na, text=res1Display5, textcolor=show5 and showLabel ? #FFFFFF : na, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.price, tooltip="#5")
  160.  
  161.  
  162.  
  163. tt_alert = "Check off each piece of criteria you want for the alerts, then select Okay. Then go to 'Create Alert' and set the condition to 'MTF DSS', select create."
  164.  
  165. alertsigUp = input.bool(true, title="Combined Signal Up (confirmed - candle closed)", group="⏰Alerts⏰", tooltip=tt_alert)
  166. alertsigUpText = input.string("🟩 Up Signal\nMTF DSS",title="Customize Alert Message (Signal Up)")
  167. alertsigDown = input.bool(true, title="Combined Signal Down (confirmed - candle closed)", group="⏰Alerts⏰")
  168. alertsigDownText = input.string("🟥 Down Signal\nMTF DSS",title="Customize Alert Message (Signal Down)")
  169.  
  170. if alertsigUp and sigCombinedUp and sigCombinedUp[1] == false
  171. alert(alertsigUpText, alert.freq_once_per_bar_close)
  172. if alertsigDown and sigCombinedUp and sigCombinedUp[1] == false
  173. alert(alertsigDownText, alert.freq_once_per_bar_close)
Advertisement
Add Comment
Please, Sign In to add comment