# ============================================================ # MIZAN presents: Cross-Examination — EMA crossover — thinkScript · v1.0 # mizanquant.com/free · free & open source · a QWERTY Options Inc. tool # # WHAT IT DOES # The oldest trick in the book, done properly. A fast and a slow # moving average, a cloud between them colored by who is on top, and # arrows when the fast line overtakes the slow one under questioning. # Two things most versions skip: arrows can wait for the candle to # close (default on) so an intrabar wobble cannot paint and erase # them, and the alerts say actual words instead of a blank string. # Crossovers lag by design; that is the cost of their calm. It # describes the tape; it does not advise. # # ORIGINALITY NOTE # An EMA crossover is generic public methodology older than the # terminal you are reading this on. This implementation is written # from scratch in-house; no code is shared with any other version. # # INSTALL (thinkorswim desktop) # Charts > Studies > Edit Studies > Create > delete the template, # paste this whole file, name it, OK, Apply. # ============================================================ declare upper; # ----- INPUTS ----- input priceSource = close; input fastLength = 13; input slowLength = 48; input avgType = AverageType.EXPONENTIAL; input confirmOnClose = yes; # arrows wait for the bar to close input showCloud = yes; input showArrows = yes; input showStatusLabel = yes; # ----- THE TWO WITNESSES ----- plot FastLine = MovingAverage(avgType, priceSource, fastLength); FastLine.SetDefaultColor(Color.CYAN); FastLine.SetLineWeight(1); plot SlowLine = MovingAverage(avgType, priceSource, slowLength); SlowLine.SetDefaultColor(Color.LIGHT_GRAY); SlowLine.SetLineWeight(1); AddCloud(if showCloud then FastLine else Double.NaN, SlowLine, Color.DARK_GREEN, Color.DARK_RED); # ----- THE CROSSING, OPTIONALLY CLOSE-CONFIRMED ----- def rawUp = FastLine crosses above SlowLine; def rawDn = FastLine crosses below SlowLine; def barClosed = !IsNaN(close[-1]); def upSignal = if confirmOnClose then rawUp and barClosed else rawUp; def dnSignal = if confirmOnClose then rawDn and barClosed else rawDn; plot CrossUp = if showArrows and upSignal then low else Double.NaN; CrossUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP); CrossUp.SetDefaultColor(Color.GREEN); CrossUp.SetLineWeight(3); plot CrossDown = if showArrows and dnSignal then high else Double.NaN; CrossDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); CrossDown.SetDefaultColor(Color.RED); CrossDown.SetLineWeight(3); # ----- STATUS ----- def fastOnTop = FastLine > SlowLine; def spreadTicks = AbsValue(FastLine - SlowLine) / TickSize(); AddLabel(showStatusLabel, (if fastOnTop then "FAST OVER SLOW" else "SLOW OVER FAST") + " | spread " + Round(spreadTicks, 1) + " ticks", if fastOnTop then Color.GREEN else Color.RED); # ----- ALERTS THAT SPEAK ----- Alert(upSignal, "Cross-Examination: fast " + fastLength + " crossed above slow " + slowLength, Alert.BAR, Sound.Chimes); Alert(dnSignal, "Cross-Examination: fast " + fastLength + " crossed below slow " + slowLength, Alert.BAR, Sound.Bell); # ----- SCAN EXPORTS ----- plot ScanCrossUp = if upSignal then 1 else 0; ScanCrossUp.Hide(); plot ScanCrossDown = if dnSignal then 1 else 0; ScanCrossDown.Hide(); plot ScanFastOnTop = if fastOnTop then 1 else 0; ScanFastOnTop.Hide(); # Educational tool. It describes market conditions; 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