# ============================================================ # MIZAN presents: Closing Argument — thinkScript · v1.0 # mizanquant.com/free · free & open source · a QWERTY Options Inc. tool # # WHAT IT DOES # Two gauges built on the Synthetic VIX concept Larry Williams # published in Active Trader (2007), run in both directions. The # DOUBT gauge measures how far price has dropped below its recent # high-water mark: it spikes when fear peaks, historically the # neighborhood of capitulation lows. The CLOSE gauge is its mirror, # measuring how far price has stretched above its recent low-water # mark: it spikes when euphoria peaks, historically the neighborhood # where positions get wrapped up. Each gauge carries its own # statistical band; dots mark the bar a spike begins. It describes # crowd extremes; it does not advise. # # ORIGINALITY NOTE # Original in-house implementation of the published concept. It # shares no code with any Buy-the-Dip or VIX Fix script, and the # concept credit belongs to Larry Williams. # # INSTALL (thinkorswim desktop) # Charts > Studies > Edit Studies > Create > delete the template, # paste this whole file, name it, OK, Apply. # ============================================================ declare lower; # ----- INPUTS ----- input lookback = 22; # bars for the water marks input bandLength = 50; # stat band window over each gauge input bandStdevs = 2.0; # spike threshold in standard deviations input useTrendFilter = yes; # mute DOUBT spike dots below the long average input trendLength = 200; input trendAvgType = AverageType.SIMPLE; input showSpikeDots = yes; input showStatusLabel = yes; # ----- THE TWO GAUGES ----- def hiWater = Highest(close, lookback); def loWater = Lowest(close, lookback); def doubtVal = if hiWater > 0 then (hiWater - low) / hiWater * 100 else 0; def closeVal = if loWater > 0 then (high - loWater) / loWater * 100 else 0; # ----- STATISTICAL SPIKE BANDS ----- def doubtEdge = Average(doubtVal, bandLength) + bandStdevs * StDev(doubtVal, bandLength); def closeEdge = Average(closeVal, bandLength) + bandStdevs * StDev(closeVal, bandLength); def trendAvg = MovingAverage(trendAvgType, close, trendLength); def trendOK = if useTrendFilter then close >= trendAvg else 1; def doubtSpiking = doubtVal > doubtEdge; def closeSpiking = closeVal > closeEdge; def doubtStart = doubtSpiking and !doubtSpiking[1] and trendOK; def closeStart = closeSpiking and !closeSpiking[1]; # ----- PLOTS ----- plot DoubtGauge = doubtVal; DoubtGauge.AssignValueColor(if doubtSpiking then Color.GREEN else Color.DARK_GREEN); DoubtGauge.SetLineWeight(2); plot CloseGauge = closeVal; CloseGauge.AssignValueColor(if closeSpiking then Color.ORANGE else Color.DARK_ORANGE); CloseGauge.SetLineWeight(2); plot DoubtBand = doubtEdge; DoubtBand.SetDefaultColor(Color.DARK_GREEN); DoubtBand.SetStyle(Curve.SHORT_DASH); DoubtBand.SetLineWeight(1); plot CloseBand = closeEdge; CloseBand.SetDefaultColor(Color.DARK_RED); CloseBand.SetStyle(Curve.SHORT_DASH); CloseBand.SetLineWeight(1); plot DoubtDot = if showSpikeDots and doubtStart then doubtVal else Double.NaN; DoubtDot.SetPaintingStrategy(PaintingStrategy.POINTS); DoubtDot.SetDefaultColor(Color.CYAN); DoubtDot.SetLineWeight(4); plot CloseDot = if showSpikeDots and closeStart then closeVal else Double.NaN; CloseDot.SetPaintingStrategy(PaintingStrategy.POINTS); CloseDot.SetDefaultColor(Color.MAGENTA); CloseDot.SetLineWeight(4); # ----- STATUS ----- AddLabel(showStatusLabel, "DOUBT " + Round(doubtVal, 2) + (if doubtSpiking then " SPIKING" else "") + " | CLOSE " + Round(closeVal, 2) + (if closeSpiking then " SPIKING" else ""), if closeSpiking then Color.ORANGE else if doubtSpiking then Color.GREEN else Color.LIGHT_GRAY); AddLabel(showStatusLabel and useTrendFilter and !trendOK, "BELOW " + trendLength + " MA - doubt dots muted", Color.GRAY); # ----- ALERTS ----- Alert(doubtStart, "Closing Argument: fear spiked above its band", Alert.BAR, Sound.Bell); Alert(closeStart, "Closing Argument: euphoria spiked above its band", Alert.BAR, Sound.Bell); Alert(!doubtSpiking and doubtSpiking[1], "Closing Argument: fear cooled back inside", Alert.BAR, Sound.Ding); Alert(!closeSpiking and closeSpiking[1], "Closing Argument: euphoria cooled back inside", Alert.BAR, Sound.Ding); # ----- SCAN EXPORTS ----- plot ScanDoubt = doubtVal; ScanDoubt.Hide(); plot ScanClose = closeVal; ScanClose.Hide(); plot ScanDoubtSpike = if doubtSpiking then 1 else 0; ScanDoubtSpike.Hide(); plot ScanCloseSpike = if closeSpiking then 1 else 0; ScanCloseSpike.Hide(); # Concept: Larry Williams' Synthetic VIX (Active Trader, 2007), # applied in both directions. Implementation: original, QWERTY # Options Inc. # Educational tool. It describes crowd extremes; it does not give # advice, and no output is a recommendation to buy or sell anything. # Trading involves substantial risk of loss. mizanquant.com/terms