//@version=4
study("TDST", overlay=true)
Disp1 = input(false, title="Show 1 Min")
Disp2 = input(false, title="Show 5 Min")
Disp3 = input(false, title="Show 15 Min")
Disp4 = input(true, title="Show 1 Hour")
Disp5 = input(false, title="Show 4 Hour")
Disp6 = input(true, title="Show 1 Day")
Disp7 = input(true, title="Show 1 Week")
Disp8 = input(false, title="Show 1 Month")
TDST() =>
// Create impulse series of price action. Compare where price is greater/less/equal than prior price.
setupPriceUp = close > close[4]
setupPriceDown = close < close[4]
setupCountUp = int(na)
setupCountUp := setupPriceUp ? nz(setupCountUp[1]) + 1 : 0
setupCountDown = int(na)
setupCountDown := setupPriceDown ? nz(setupCountDown[1]) + 1 : 0
// A Setup event is when up/down count == SetupBars
// Sell Setups are defined by up counts, Buy Setups by down counts.
setupSell = float(na)
valuewhen_1 = valuewhen(setupCountUp == 9, close, 0)
setupSell := setupCountUp == 9 ? valuewhen_1 : na
setupBuy = float(na)
valuewhen_2 = valuewhen(setupCountDown == 9, close, 0)
setupBuy := setupCountDown == 9 ? valuewhen_2 : na
//---- TD Setup Trend (TDST) ---------------------------
setupTrendSupport = float(na)
lowest_1 = lowest(9) < close[9] ? lowest(9) : close[9]
setupTrendSupport := setupSell ? lowest_1 : nz(setupTrendSupport[1])
setupTrendResist = float(na)
highest_1 = highest(9) > close[9] ? highest(9) : close[9]
setupTrendResist := setupBuy ? highest_1 : nz(setupTrendResist[1])
[setupTrendSupport,setupTrendResist]
[stsp1,strp1] = security(syminfo.tickerid, "1", TDST())
[stsp2,strp2] = security(syminfo.tickerid, "5", TDST())
[stsp3,strp3] = security(syminfo.tickerid, "15", TDST())
[stsp4,strp4] = security(syminfo.tickerid, "60", TDST())
[stsp5,strp5] = security(syminfo.tickerid, "240", TDST())
[stsp6,strp6] = security(syminfo.tickerid, "D", TDST())
[stsp7,strp7] = security(syminfo.tickerid, "W", TDST())
[stsp8,strp8] = security(syminfo.tickerid, "M", TDST())
// TDST (Support/Resistance)
// Use plot offset to move line back to beginning of Setup count...
plot(Disp1? stsp1 : na, title="TDST1 Support", style=plot.style_circles, color=color.lime, linewidth=2, offset=0)
plot(Disp1? strp1 : na, title="TDST1 Resistance", style=plot.style_circles, color=color.red, linewidth=2, offset=0)
plot(Disp2? stsp2 : na, title="TDST5 Support", style=plot.style_circles, color=color.lime, linewidth=2, offset=0)
plot(Disp2? strp2 : na, title="TDST5 Resistance", style=plot.style_circles, color=color.red, linewidth=2, offset=0)
plot(Disp3? stsp3 : na, title="TDST15 Support", style=plot.style_circles, color=color.lime, linewidth=2, offset=0)
plot(Disp3? strp3 : na, title="TDST15 Resistance", style=plot.style_circles, color=color.red, linewidth=2, offset=0)
plot(Disp4? stsp4 : na, title="TDST1H Support", style=plot.style_circles, color=color.lime, linewidth=2, offset=0)
plot(Disp4? strp4 : na, title="TDST1H Resistance", style=plot.style_circles, color=color.red, linewidth=2, offset=0)
plot(Disp5? stsp5 : na, title="TDST4H Support", style=plot.style_circles, color=color.lime, linewidth=2, offset=0)
plot(Disp5? strp5 : na, title="TDST4H Resistance", style=plot.style_circles, color=color.red, linewidth=2, offset=0)
plot(Disp6? stsp6 : na, title="TDSTD Support", style=plot.style_circles, color=color.lime, linewidth=2, offset=0)
plot(Disp6? strp6 : na, title="TDSTD Resistance", style=plot.style_circles, color=color.red, linewidth=2, offset=0)
plot(Disp7? stsp7 : na, title="TDSTW Support", style=plot.style_circles, color=color.lime, linewidth=2, offset=0)
plot(Disp7? strp7 : na, title="TDSTW Resistance", style=plot.style_circles, color=color.red, linewidth=2, offset=0)
plot(Disp8? stsp8 : na, title="TDSTM Support", style=plot.style_circles, color=color.lime, linewidth=2, offset=0)
plot(Disp8? strp8 : na, title="TDSTM Resistance", style=plot.style_circles, color=color.red, linewidth=2, offset=0)