Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- //Multi-Timeframe Double Smoothed Stochastics (DSS) by William Blaw.
- indicator(title='MTF DSS (Double Smoothed Stochastic)', shorttitle='MTF DSS')
- 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)
- show1 = input(true,title="#1",inline="1")
- show2 = input(true,title="#2",inline="2")
- show3 = input(true,title="#3",inline="3")
- show4 = input(true,title="#4",inline="4")
- show5 = input(true,title="#5",inline="5")
- res1 = input.timeframe(title='', defval='',inline="1")
- res2 = input.timeframe(title='', defval='',inline="2")
- res3 = input.timeframe(title='', defval='',inline="3")
- res4 = input.timeframe(title='', defval='',inline="4")
- res5 = input.timeframe(title='', defval='',inline="5")
- mult1 = input.int(1,title='TF Mult.',minval=1,inline="1")
- mult2 = input.int(1,title='TF Mult.',minval=1,inline="2")
- mult3 = input.int(1,title='TF Mult.',minval=1,inline="3")
- mult4 = input.int(1,title='TF Mult.',minval=1,inline="4")
- mult5 = input.int(1,title='TF Mult.',minval=1,inline="5")
- Periods = input.int(10, minval=1,title="Periods",group="DSS")
- EMAlen = input.int(9, minval=1,title="EMA Length",group="DSS")
- TriggerLen = input.int(5, minval=1,title="Trigger Length",group="DSS")
- showSig = input(true,title="Show single directional signals",group="Signals")
- showCombinedSig = input(true, title="Show combined directional signals (MTF)",group="Signals")
- showOB = input(true,title="",group="Overbought / Oversold",inline="ob")
- showMID = input(true,title="",group="Overbought / Oversold",inline="mid")
- showOS = input(true,title="",group="Overbought / Oversold",inline="os")
- Overbought = input.int(80, minval=0, maxval=100,group="Overbought / Oversold",inline="ob")
- midline = input.int(50, minval=0, maxval=100,group="Overbought / Oversold",inline="mid")
- Oversold = input.int(20, minval=0, maxval=100,group="Overbought / Oversold",inline="os")
- calc_DSS(_TFmult) =>
- xPreCalc = ta.ema(ta.stoch(close, high, low, Periods*_TFmult), EMAlen*_TFmult)
- xDSS = ta.ema(ta.stoch(xPreCalc, xPreCalc, xPreCalc, Periods*_TFmult), EMAlen*_TFmult)
- xTrigger = ta.ema(xDSS, TriggerLen*_TFmult)
- //sigCol = xDSS > TriggerLen ? color.new(color.lime,90) : color.new(color.red,90)
- [xPreCalc,xDSS,xTrigger]
- [xPreCalc_1,xDSS_1,xTrigger_1] = request.security(syminfo.tickerid, res1, calc_DSS(mult1))
- [xPreCalc_2,xDSS_2,xTrigger_2] = request.security(syminfo.tickerid, res2, calc_DSS(mult2))
- [xPreCalc_3,xDSS_3,xTrigger_3] = request.security(syminfo.tickerid, res3, calc_DSS(mult3))
- [xPreCalc_4,xDSS_4,xTrigger_4] = request.security(syminfo.tickerid, res4, calc_DSS(mult4))
- [xPreCalc_5,xDSS_5,xTrigger_5] = request.security(syminfo.tickerid, res5, calc_DSS(mult5))
- sigCol1 = xDSS_1 > xTrigger_1 ? color.new(color.lime,90) : color.new(color.red,90)
- sigCol2 = xDSS_2 > xTrigger_2 ? color.new(color.lime,90) : color.new(color.red,90)
- sigCol3 = xDSS_3 > xTrigger_3 ? color.new(color.lime,90) : color.new(color.red,90)
- sigCol4 = xDSS_4 > xTrigger_4 ? color.new(color.lime,90) : color.new(color.red,90)
- sigCol5 = xDSS_5 > xTrigger_5 ? color.new(color.lime,90) : color.new(color.red,90)
- sigCombinedUp = true
- sigCombinedDown = true
- if show1
- if xDSS_1 > xTrigger_1
- sigCombinedDown := false
- else
- sigCombinedUp := false
- if show2
- if xDSS_2 > xTrigger_2
- sigCombinedDown := false
- else
- sigCombinedUp := false
- if show3
- if xDSS_3 > xTrigger_3
- sigCombinedDown := false
- else
- sigCombinedUp := false
- if show4
- if xDSS_4 > xTrigger_4
- sigCombinedDown := false
- else
- sigCombinedUp := false
- if show5
- if xDSS_5 > xTrigger_5
- sigCombinedDown := false
- else
- sigCombinedUp := false
- ob1 = hline(show1 and showOB ? Overbought : na, color=show1 and showOB ? color.green : na, linestyle=hline.style_solid)
- mid1 = hline(show1 and showMID ? midline : na, color=show1 and showMID ? color.new(color.gray,80) : na, linestyle=hline.style_solid)
- os1 = hline(show1 and showOB ? Oversold : na, color=show1 and showOB ? color.red : na, linestyle=hline.style_solid)
- fill(ob1,os1,color=showSig ? sigCol1 : color.rgb(126, 87, 194, 93))
- ob2 = hline(show2 and showOB ? Overbought-100 : na, color=show2 and showOB ? color.green : na, linestyle=hline.style_solid)
- mid2 = hline(show2 and showMID ? midline : na, color=show2 and showMID ? color.new(color.gray,80) : na, linestyle=hline.style_solid)
- os2 = hline(show2 and showOB ? Oversold-100 : na, color=show2 and showOB ? color.red : na, linestyle=hline.style_solid)
- fill(ob2,os2,color=showSig ? sigCol2 : color.rgb(126, 87, 194, 93))
- ob3 = hline(show3 and showOB ? Overbought-200 : na, color=show3 and showOB ? color.green : na, linestyle=hline.style_solid)
- mid3 = hline(show3 and showMID ? midline : na, color=show3 and showMID ? color.new(color.gray,80) : na, linestyle=hline.style_solid)
- os3 = hline(show3 and showOB ? Oversold-200 : na, color=show3 and showOB ? color.red : na, linestyle=hline.style_solid)
- fill(ob3,os3,color=showSig ? sigCol3 : color.rgb(126, 87, 194, 93))
- ob4 = hline(show4 and showOB ? Overbought-300 : na, color=show4 and showOB ? color.green : na, linestyle=hline.style_solid)
- mid4 = hline(show4 and showMID ? midline : na, color=show4 and showMID ? color.new(color.gray,80) : na, linestyle=hline.style_solid)
- os4 = hline(show4 and showOB ? Oversold-300 : na, color=show4 and showOB ? color.red : na, linestyle=hline.style_solid)
- fill(ob4,os4,color=showSig ? sigCol4 : color.rgb(126, 87, 194, 93))
- ob5 = hline(show5 and showOB ? Overbought-400 : na, color=show5 and showOB ? color.green : na, linestyle=hline.style_solid)
- mid5 = hline(show5 and showMID ? midline : na, color=show5 and showMID ? color.new(color.gray,80) : na, linestyle=hline.style_solid)
- os5 = hline(show5 and showOB ? Oversold-400 : na, color=show5 and showOB ? color.red : na, linestyle=hline.style_solid)
- fill(ob5,os5,color=showSig ? sigCol5 : color.rgb(126, 87, 194, 93))
- plot(showCombinedSig ? 120 : na,color=sigCombinedUp ? color.lime : (sigCombinedDown ? color.red : color.new(color.blue,90)),style=plot.style_circles)
- plot(show1 ? xDSS_1 : na, color=color.new(color.blue, 0), title='DSS1')
- plot(show1 ? xTrigger_1 : na, color=color.new(color.red, 0), title='Trigger1')
- plot(show2 ? xDSS_2-100 : na, color=color.new(color.blue, 0), title='DSS2')
- plot(show2 ? xTrigger_2-100 : na, color=color.new(color.red, 0), title='Trigger2')
- plot(show3 ? xDSS_3-200 : na, color=color.new(color.blue, 0), title='DSS3')
- plot(show3 ? xTrigger_3-200 : na, color=color.new(color.red, 0), title='Trigger3')
- plot(show4 ? xDSS_4-300 : na, color=color.new(color.blue, 0), title='DSS4')
- plot(show4 ? xTrigger_4-300 : na, color=color.new(color.red, 0), title='Trigger4')
- plot(show5 ? xDSS_5-400 : na, color=color.new(color.blue, 0), title='DSS5')
- plot(show5 ? xTrigger_5-400 : na, color=color.new(color.red, 0), title='Trigger5')
- showLabel = input(false,title="Show TimeFrame Labels",group="Label Settings")
- setTime = time - time[1]
- setTime := ta.change(setTime) > 0 ? setTime[1] : setTime
- var label label_res1 = na
- var label label_res2 = na
- var label label_res3 = na
- var label label_res4 = na
- var label label_res5 = na
- label.delete(label_res1)
- label.delete(label_res2)
- label.delete(label_res3)
- label.delete(label_res4)
- label.delete(label_res5)
- res1Display1 = res1
- if res1 == ""
- res1Display1 := "Chart"
- res1Display2 = res2
- if res2 == ""
- res1Display2 := "Chart"
- res1Display3 = res3
- if res3 == ""
- res1Display3 := "Chart"
- res1Display4 = res4
- if res4 == ""
- res1Display4 := "Chart"
- res1Display5 = res5
- if res5 == ""
- res1Display5 := "Chart"
- 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")
- 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")
- 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")
- 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")
- 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")
- 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."
- alertsigUp = input.bool(true, title="Combined Signal Up (confirmed - candle closed)", group="⏰Alerts⏰", tooltip=tt_alert)
- alertsigUpText = input.string("🟩 Up Signal\nMTF DSS",title="Customize Alert Message (Signal Up)")
- alertsigDown = input.bool(true, title="Combined Signal Down (confirmed - candle closed)", group="⏰Alerts⏰")
- alertsigDownText = input.string("🟥 Down Signal\nMTF DSS",title="Customize Alert Message (Signal Down)")
- if alertsigUp and sigCombinedUp and sigCombinedUp[1] == false
- alert(alertsigUpText, alert.freq_once_per_bar_close)
- if alertsigDown and sigCombinedUp and sigCombinedUp[1] == false
- alert(alertsigDownText, alert.freq_once_per_bar_close)
Advertisement
Add Comment
Please, Sign In to add comment