Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TD Sequential Setup and Countdown //
- //
- // Features:
- // ==========
- // Setup counts long/short | Encircled number above bar | Close exceeds the close 4 bars earlier in the direction of the setup. |
- // | Setup must be contiguous. It resets if a close fails the test. |
- //
- // 'Perfect' setups | Filled encircled 8 or 9 setup above bar | The high exceeds the high 2 bars earlier in the direction of the setup |
- //
- // Countdown long/short | Encircled number below bar | On and after a complete (9) setup, increment count for each close: |
- // | -- above the high of two bars earlier (rising short countdown). |
- // | -- below the low of two bars earlier (falling long countdown). |
- // | Is not contiguous, but resets if a new reversing setup completes, or |
- // | if the high or low exceeds the extreme high or low of the triggering setup. |
- // | The setup extreme high/low recycles based on the fib rules desccribed. |
- //
- // 'Perfect' countdown | Filled encircled 13 countdown below bar | When the 13th high or low exceeds the close of countdown bar 8 |
- //
- // Colour | Green for rising setups/countdowns | Reversible in configuration. |
- // | Red for falling setups/countdowns | |
- // How to trade:
- // ==============
- //
- // Works more reliably on longer time-frames, but is functional on any time-frame.
- // A '9' (or perfect '8') signals a potential reversal. Use with price action and candle stick patterns and other trends & indicators for support analysis.
- // A '13' countdown is a stronger reversal indicator, with the same caveats as above.
- // A '13' on or near a '9' setup is an extremely strong signal.
- // '9' setups or '13' countdowns across multiple time-frames are the best possible signal. e.g. a monthly 9, a weekly 9, a daily 9.
- //
- //@version=3
- study("TD Setup and Countdown", "TD Sequential", overlay=true)
- // TD Setup and Countdown //
- ShowEMAs = input(false)
- timeframe = input('W', title="VWAP Close Time Frame")
- showPrevVWAP = input(false, type=bool, title="Show Previous VWAP close")
- showSetup = input(true, "Show Setup")
- showCountdown = input(true, "Show Countdown")
- showPerfect = input(true, "Show Perfect Counts")
- invertColours = input(false, "Invert Colours")
- showOnlyCompletion = input(false, "Only Show Completions")
- showTDST = input(true, "Show TDST Support & Resistance")
- setupRecyclesOnNextBar = input(true, "Setup Recycles On Next Bar")
- flip = input(false, "Setup Commences After TD Price Flip")
- showRisk = input(false, "Show Risk Line")
- volatilitySmoothing = input(false, "Volatility Smoothing (Relaxed Setup)")
- // EMA's //
- EMA8 = ema(close,8)
- EMA21 = ema(close,21)
- EMA55 = ema(close,55)
- EMA200 = ema(close,200)
- plot(ShowEMAs?EMA8:na, color=#ffffff, linewidth=1, transp=0, title="EMA 8")
- plot(ShowEMAs?EMA21:na, color=#ffa800, linewidth=1, transp=0, title="EMA 21")
- plot(ShowEMAs?EMA55:na, color=#00a3ff, linewidth=1, transp=0, title="EMA 55")
- plot(ShowEMAs?EMA200:na, color=#ff006b, linewidth=1, transp=0, title="EMA 200")
- // TD Code //
- shortColour = invertColours ? red : green
- longColour = invertColours ? green : red
- smoothedColour = aqua
- setupShort = na, setupLong = na, setupCount = na, setupColour = na, perfectSetup = na
- setupShort := if (close < close[4] and (not(volatilitySmoothing) or close < close[5]))
- 0
- else
- if (flip)
- if (nz(setupShort[1]) == 0 and close[1] < close[5] and close > close[4])
- 1
- else
- if (nz(setupShort[1]) == 0)
- 0
- else
- nz(setupShort[1] + 1)
- else
- if (setupShort[1] == 9)
- setupRecyclesOnNextBar ? 1 : 0
- else
- nz(setupShort[1] + 1)
- setupLong := if (close > close[4] and (not(volatilitySmoothing) or close > close[5]))
- 0
- else
- if (flip)
- if (nz(setupLong[1]) == 0 and close[1] > close[5] and close < close[4])
- 1
- else
- if (nz(setupLong[1]) == 0)
- 0
- else
- nz(setupLong[1] + 1)
- else
- if (setupLong[1] == 9)
- setupRecyclesOnNextBar ? 1 : 0
- else
- nz(setupLong[1] + 1)
- setupCount := max(setupShort, setupLong)
- setupColour := setupShort > 0 ? setupLong > 0 ? smoothedColour : shortColour : longColour
- perfectSetup := showPerfect and ((setupShort == 8 and (high >= high[1] and high >= high[2])) or (setupShort == 9 and (high >= high[2] and high >= high[3])) or (setupLong == 8 and (low <= low[1] and low <= low[2])) or (setupLong == 9 and (low <= low[2] and low <= low[3])))
- plotchar(showSetup and (not(showOnlyCompletion) or barstate.islast) and setupCount == 1, title="Setup 1", char="1", color=setupColour, transp=0)
- plotchar(showSetup and (not(showOnlyCompletion) or barstate.islast) and setupCount == 2, title="Setup 2", char="2", color=setupColour, transp=0)
- plotchar(showSetup and (not(showOnlyCompletion) or barstate.islast) and setupCount == 3, title="Setup 3", char="3", color=setupColour, transp=0)
- plotchar(showSetup and (not(showOnlyCompletion) or barstate.islast) and setupCount == 4, title="Setup 4", char="4", color=setupColour, transp=0)
- plotchar(showSetup and (not(showOnlyCompletion) or barstate.islast) and setupCount == 5, title="Setup 5", char="5", color=setupColour, transp=0)
- plotchar(showSetup and (not(showOnlyCompletion) or barstate.islast) and setupCount == 6, title="Setup 6", char="6", color=setupColour, transp=0)
- plotchar(showSetup and (not(showOnlyCompletion) or barstate.islast) and setupCount == 7, title="Setup 7", char="7", color=setupColour, transp=0)
- plotchar(not(perfectSetup) and (not(showOnlyCompletion) or barstate.islast) and showSetup and setupCount == 8, title="Setup 8", char="8", color=setupColour, transp=0)
- plotchar(not(perfectSetup) and showSetup and setupCount == 9, title="Setup 9", char="⓽", color=setupColour, transp=0)
- plotchar(perfectSetup and showSetup and setupCount == 8, title="Perfect setup 8", char="➑", color=setupColour, transp=0)
- plotchar(perfectSetup and showSetup and setupCount == 9, title="Perfect setup 9", char="➒", color=setupColour, transp=0)
- cdownShort = na, cdownLong = na, cdownColour = na, cdownCount = na, perfect8 = na, perfectCountdown = na
- lastCompletedSetup = na, setupHigh = na, setupLow = na, cancelCountdown = na, recycleCountdown = na
- LONG = -1, SHORT = 1, CANCELLED = 0
- recycleCountdown := if (setupShort == 9 and lastCompletedSetup[1] == SHORT) or (setupLong == 9 and lastCompletedSetup[1] == LONG)
- (highest(9) - lowest(9)) >= (setupHigh[1] - setupLow[1]) and (setupHigh[1] - setupLow[1]) * 1.618 > (highest(9) - lowest(9))
- setupHigh := recycleCountdown or (setupShort == 9 and lastCompletedSetup[1] != SHORT) or (setupLong == 9 and lastCompletedSetup[1] != LONG) ? highest(9) : setupHigh[1]
- setupLow := recycleCountdown or (setupShort == 9 and lastCompletedSetup[1] != SHORT) or (setupLong == 9 and lastCompletedSetup[1] != LONG) ? lowest(9) : setupLow[1]
- cancelCountdown := (lastCompletedSetup[1] == SHORT and high < setupLow) or
- (lastCompletedSetup[1] == LONG and low > setupHigh) or
- recycleCountdown
- lastCompletedSetup := setupLong == 9 ? LONG : (setupShort == 9 ? SHORT : (((cdownShort[1] == 13 and setupShort[1] != 9) or (cdownLong[1] == 13 and setupLong[1] != 9) or cancelCountdown) ? CANCELLED : lastCompletedSetup[1]))
- cdownShort := (lastCompletedSetup != SHORT or cancelCountdown) ? 0 : (close >= high[2] ? (nz(cdownShort[1]) % 13) + 1 : nz(cdownShort[1]) % 13)
- cdownLong := (lastCompletedSetup != LONG or cancelCountdown) ? 0 : (close <= low[2] ? (nz(cdownLong[1]) % 13) + 1 : nz(cdownLong[1]) % 13)
- cdownCount := max(cdownShort, cdownLong)
- cdownColour := cdownShort > 0 ? shortColour : longColour
- perfect8 := cdownCount < 8 ? na : cdownCount == 8 ? close : perfect8[1]
- perfectCountdown := showPerfect and ((cdownShort == 13 and high >= perfect8) or (cdownLong and low <= perfect8))
- plotchar(showCountdown and (not(showOnlyCompletion) or barstate.islast) and cdownCount == 1 and cdownCount[1] != 1, title="Countdown 1", char="①", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(showCountdown and (not(showOnlyCompletion) or barstate.islast) and cdownCount == 2 and cdownCount[1] == 1, title="Countdown 2", char="②", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(showCountdown and (not(showOnlyCompletion) or barstate.islast) and cdownCount == 3 and cdownCount[1] == 2, title="Countdown 3", char="③", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(showCountdown and (not(showOnlyCompletion) or barstate.islast) and cdownCount == 4 and cdownCount[1] == 3, title="Countdown 4", char="④", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(showCountdown and (not(showOnlyCompletion) or barstate.islast) and cdownCount == 5 and cdownCount[1] == 4, title="Countdown 5", char="⑤", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(showCountdown and (not(showOnlyCompletion) or barstate.islast) and cdownCount == 6 and cdownCount[1] == 5, title="Countdown 6", char="⑥", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(showCountdown and (not(showOnlyCompletion) or barstate.islast) and cdownCount == 7 and cdownCount[1] == 6, title="Countdown 7", char="⑦", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(showCountdown and (not(showOnlyCompletion) or barstate.islast) and cdownCount == 8 and cdownCount[1] == 7, title="Countdown 8", char="⑧", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(showCountdown and (not(showOnlyCompletion) or barstate.islast) and cdownCount == 9 and cdownCount[1] == 8, title="Countdown 9", char="⑨", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(showCountdown and (not(showOnlyCompletion) or barstate.islast) and cdownCount == 10 and cdownCount[1] == 9, title="Countdown 10", char="⑩", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(showCountdown and (not(showOnlyCompletion) or barstate.islast) and cdownCount == 11 and cdownCount[1] == 10, title="Countdown 11", char="⑪", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(showCountdown and (not(showOnlyCompletion) or barstate.islast) and cdownCount == 12 and cdownCount[1] == 11, title="Countdown 12", char="⑫", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(not(perfectCountdown) and showCountdown and cdownCount == 13 and cdownCount[1] == 12, title="Countdown 13", char="⑬", location=location.belowbar, color=cdownColour, transp=0)
- plotchar(perfectCountdown and showCountdown and cdownCount == 13 and cdownCount[1] == 12, title="Perfect Countdown 13", char="⓭", location=location.belowbar, color=cdownColour, transp=0)
- plotshape(showCountdown and cancelCountdown, title="Countdown broke setup support/resistance", location=location.belowbar, style=shape.xcross, color=cdownColour, transp=0)
- tdstSupport = na, tdstResistance = na, tdRisk = na, riskbar = na
- tdstResistance := not(showTDST) ? na : (setupLong == 9 ? highest(9) : (close > tdstResistance[1] ? na : tdstResistance[1]))
- tdstSupport := not(showTDST) ? na : (setupShort == 9 ? lowest(9) : (close < tdstSupport[1] ? na : tdstSupport[1]))
- alertcondition(close > tdstResistance[1] or close < tdstSupport[1], title="Close outside TDST range", message="Close outside TDST range")
- plot(tdstResistance, title="TDST Resistance", color=longColour, style=linebr)
- plot(tdstSupport, title="TDST Support", color=shortColour, style=linebr)
- if (not(showRisk))
- tdRisk := na
- else
- if (setupLong == 9)
- riskbar := -1 * lowestbars(9)[0]
- tdRisk := low[riskbar] - tr[riskbar]
- else
- if (setupShort == 9)
- riskbar = -1 * highestbars(9)[0]
- tdRisk := high[riskbar] + tr[riskbar]
- else
- tdRisk := min(open, close) < tdRisk[1] and max(open, close) > tdRisk[1] ? na : tdRisk[1]
- plot(tdRisk, title="TD Risk", color=aqua, style=circles, linewidth=1)
- // VWAP Stdev Previous Day Close //
- start = security(tickerid, timeframe, time)
- newSession = iff(change(start), 1, 0)
- vwapsum = 0.0
- vwapsum :=iff(newSession, hl2*volume, vwapsum[1]+hl2*volume)
- volumesum = 0.0
- volumesum := iff(newSession, volume, volumesum[1]+volume)
- v2sum = 0.0
- v2sum := iff(newSession, volume*hl2*hl2, v2sum[1]+volume*hl2*hl2)
- myvwap = 0.0
- myvwap := vwapsum/volumesum
- dev = 0.0
- dev := sqrt(max(v2sum/volumesum - myvwap*myvwap, 0))
- prevwap = 0.0
- prevwap := iff(newSession, myvwap[1], prevwap[1])
- plot(showPrevVWAP ? prevwap : na, style=circles, color=close > prevwap ? green : red,title="VWAP Stdev Previous Day Close")
- // Volume Bars //
- //PRICE BARS ARE:
- //Bearish:
- //DARK RED when prices goes down and VOLUME is bigger than 150% of its (default 20 day) average, this indicates that price action is supported by a strong BEARISH VOLUME.
- //RED when prices goes down and VOLUME is BETWEEN 50% AND 150% of its (default 20 day) average, this indicates that volume is neither strong or weak.
- //ORANGE when prices goes down and VOLUME is less than 50% of its (default 20 day) average, so the volume is weak and doesn't support the price action.
- //Bullish:
- //DARK GREEN when prices goes UP and VOLUME is bigger than 150% of its (default 20 day) average, this indicates that the price action is supported by a strong BULLISH VOLUME.
- //GREEN when prices goes UP and VOLUME is BETWEEN 50% AND 150% of its (default 20 day) average, this indicates that volume is neither strong or weak.
- //LIGHT GREEN when prices goes UP and VOLUME is less than 50% of its (default 20 day) average, so the volume is weak and doesn't support the price action.
- length1=input(20, "Volume Bars Length", minval=1)
- avrg=sma(volume,length1)
- vold1 = volume > avrg*1.5 and close<open
- vold2 = volume >= avrg*0.5 and volume<=avrg*1.5 and close<open
- vold3 = volume < avrg *0.5 and close<open
- volu1 = volume > avrg*1.5 and close>open
- volu2 = volume >= avrg*0.5 and volume<=avrg*1.5 and close>open
- volu3 = volume< avrg*0.5 and close>open
- cold1=#800000
- cold2=#FF0000
- cold3=orange
- colu1=#006400
- colu2=lime
- colu3=#7FFFD4
- color = vold1 ? cold1 : vold2 ? cold2 : vold3 ? cold3 : volu1 ? colu1 : volu2 ? colu2 : volu3 ? colu3 : na
- barcolor(color)
- //End//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement