Stock futures

Stock futures inch higher after another losing week on Wall Street

thinkscript

# hint: AAAAAAAAAAAA_Jin # – Version: 21 # – By: Mr Stockboto # – Release Date: June 11, 2017 #hint: 5 Day Volume Period Weighted Moving Average (VWAP), #hint: Mid Point half way between Weighted Moving Average (WMA) 34 and Hull MA (HMA) 5, TTM Squeeze, #hint: Day VWAP based McClellan Summation Index # This script displays: # 5 Day Ago Anchored VWAP. # WMA 34, Mid Point, with a cloud between the two. # Blue Cloud Mid Point is above WMA 34. Red Cloud Mid Point is below WMA 34 # Labels at top left of chart display: # VWAP # Green when price is above the VWAP Line, Red price is currently below VWAP Line. # Cyan when within VWAPCrossWithin number of bars from close crossing any VWAP line. # +2 means price is above VWAP +2 line. # +1 price is above VWAP +1 line, but below the +2 line # Line price is betwen the VWAP line and the +/- 1 line. Which can be determined by Red/Green color. # -1 price is below VWAP +1 line, but above the -1 line # -2 means price is below VWAP +2 line. # (#) number within () is the number of bars since close crossed the indicated VWAP line # Cloud # Red Mid Point is below WMA 34. Green Mid Point is below WMA 34. # (#) number within () is number of bars since Mid Point Crossed WMA # Slope # Green Slope is positive, Red Slope value is negative (i.e. below zero) # +/_# is the slope value. # (#) number within () is number of bars since slope flipped above/below zero. # Change # Green Change is positive, Red Change value is negative (i.e. below zero) # +/_# is the Change value. There is no (#) for Change. # MSI # Green MSI is positive, Red MSI value is negative (i.e. below zero) # +/_# is the MSI value. There is no (#) for MSI. # TTM # Green when TTM Squeeze Histogram is above zero # Red when Histogram is below zero # Gray when Histogram is zero # Letter N indicate Normal, S indicates TTM is currently in a Squeeze. # (#) number within () indicates number of bars since TTM Histogram crossed above/below zero. # CYAN / DARK GRAY boxes to the right of each component label contains the parameter value # assigned to each. It is dark gray when the cross happened beyond the parameter number of bars, # it is cyan when the cross happened within shown # of bars. Except for Change, change is a range # of +/- # shown, so if parameter is set to 5, then it will be dark gray when change is greater # than or equal to negative 5 and less than or equal to positive 5. It will be cyan when # the value of change is beyond that range. declare lower; # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN PARAMETERS SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # input VWAPIntraAnchor = 5; input VWAPDaysAnchor = 22; input ShowFlags = yes; input ShowVWAP = no; input ShowMSI = yes; input ShowSlope = yes; input ShowMACloud = no; input ShowFlipLabels = yes; input ShowVFI = no; input ShowVFISlope = no; input ShowVFILabels = yes; input ShowMSILabels = yes; input ShowRTHBorders = yes; input MACrossWithin = 5; input VWAPCrossWithin = 5; input TTMCrossWithin = 5; input TTMCrossLevel = 2; input SlopeCrossWithin = 5; input Change5Beyond = 5; input Change15Beyond = 25; input ChangeDayBeyond = 10; # # # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN GLOBAL VARIABLES SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def ConfirmSlopeChange = if GetAggregationPeriod() < AggregationPeriod.THIRTY_MIN then .01 else if GetAggregationPeriod() == AggregationPeriod.THIRTY_MIN then .01 else .01; def currentDate = GetYYYYMMDD(); def firstChartDate = LowestAll(currentDate); def lastTradingDate = if !IsNaN(close) and IsNaN(close[-1]) then currentDate else Double.NaN; def lastChartDate = HighestAll(lastTradingDate); def daysTillLast = CountTradingDays( if currentDate > lastChartDate then lastChartDate else currentDate, lastChartDate); # This process provides variables identifying begin and end of the day # and the true begin and end of regular trading hours, if extended hours are # displayed or not, regardless of stock/future instrument displayed on the chart # without requiring the user to provide any values such as 0930 for start time. def RTHStart = RegularTradingStart(GetYYYYMMDD()); def RTHEnd = RegularTradingEnd(GetYYYYMMDD()); def startDay = if RTHStart != RTHStart[1] then yes else no; def endDay = if RTHEnd != RTHEnd[1] then yes else no; def isTradingHours = if GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() <= RegularTradingEnd(GetYYYYMMDD()) then yes else no; def tradingStart = if isTradingHours and (!isTradingHours[1] or startDay) then yes else no; def tradingEnd = if isTradingHours[1] and (!isTradingHours or endDay) then yes else no; # # # # # # # # # # # # # # # # # # # # # # # BEGIN SCRIPTS SECTION # # # # # # # # # # # # # # # # # # # # # # # # script Normalize { input CurrentValue = 0; input OldScaleHigh = 1; input OldScaleLow = 0; input NewScaleHigh = 1; input NewScaleLow = 0; def ValueAsPercent = 1 – ((OldScaleHigh – CurrentValue) / (OldScaleHigh – OldScaleLow)); plot Value = (ValueAsPercent * (NewScaleHigh – NewScaleLow)) + NewScaleLow; } # END script Normalize # # # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN MOVING AVERAGE SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # # input hma5AverageType = AverageType.SIMPLE; input hma5Period = 5; input wma34AverageType = AverageType.WEIGHTED; input wma34Period = 34; def maMultiplier = 1000; def hma5 = MovingAverage(hma5AverageType, close, hma5Period); plot wma34 = MovingAverage(wma34AverageType, close, wma34Period); plot midPoint = wma34 + ((hma5 – wma34) / 2); def MaLongFlag = if midPoint[1] < wma34[1] and midPoint >= wma34 then yes else no; def MaShortFlag = if midPoint[1] >= wma34[1] and midPoint < wma34 then yes else no; def MaCrossBar = if MaLongFlag or MaShortFlag then BarNumber() else MaCrossBar[1]; def MaFromCross = BarNumber() – MaCrossBar; def MaInRange = if MaFromCross <= MACrossWithin then yes else no; def GreenCloud = if midPoint >= wma34 then yes else no; def RedCloud = if midPoint < wma34 then yes else no; # # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN TTM_SQUEEZE SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # def TTMSqueeze = TTM_Squeeze().SqueezeAlert; def TTMHistogram = TTM_Squeeze().Histogram; def TTMLongFlag = if (TTMHistogram[1] < TTMCrossLevel and TTMHistogram >= TTMCrossLevel) then yes else no; def TTMShortFlag = if TTMHistogram[1] >= -TTMCrossLevel and TTMHistogram < -TTMCrossLevel then yes else no; def TTMCrossBar = if TTMLongFlag or TTMShortFlag then BarNumber() else TTMCrossBar[1]; def TTMFromCross = BarNumber() – TTMCrossBar; def TTMInRange = if TTMFromCross <= TTMCrossWithin then yes else no; def GreenTTM = if TTMHistogram >= TTMCrossLevel then yes else no; def RedTTM = if TTMHistogram < -TTMCrossLevel then yes else no; def TTMUp = TTMHistogram > TTMHistogram[1]; def TTMDown = TTMHistogram < TTMHistogram[1]; # # # # # # # # # # # # # # # # # # # # # # # # BEGIN VWAP SECTION # # # # # # # # # # # # # # # # # # # # # # # # input vwapMidWidth = 1.0; input vwapWideWidth = 2.0; input vwapSlopeLength = 5; input vwapSlopeLookBack = 8; def AnchorDaysAgo = if GetAggregationPeriod() < AggregationPeriod.DAY then VWAPIntraAnchor else VWAPDaysAnchor; def totalChartDays = CountTradingDays( firstChartDate, lastChartDate); #def totalChartDays = lastChartDate – firstChartDate; def remainder = totalChartDays % AnchorDaysAgo; def newDay = CompoundValue(1, currentDate != currentDate[1], yes); def dayNumber = if BarNumber() == 0 then 0 else if newDay then dayNumber[1] + 1 else dayNumber[1]; def anchorCount = if BarNumber() == 0 then 0 else if newDay and dayNumber < remainder – 1 then 1 else if newDay and anchorCount[1] == AnchorDaysAgo then 1 else if newDay then anchorCount[1] + 1 else anchorCount[1]; def volumeSum; def volumeVwapSum; def volumeVwap2Sum; if newDay and anchorCount == 1 { volumeSum = volume; volumeVwapSum = volume * vwap; volumeVwap2Sum = volume * Sqr(vwap); } else { volumeSum = CompoundValue(1, volumeSum[1] + volume, volume); volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap); volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap)); } def price = volumeVwapSum / volumeSum; def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum – Sqr(price), 0)); plot vwapLine = price; plot vwapMidUpper = price + vwapMidWidth * deviation; plot vwapMidLower = price + -vwapMidWidth * deviation; plot vwapWideUpper = price + vwapWideWidth * deviation; plot vwapWideLower = price + -vwapWideWidth * deviation; def vwapSlope = ((vwapLine – vwapLine[vwapSlopeLength]) / vwapSlopeLength) / close * 100000; def vwapSlopeUp = if vwapSlope[vwapSlopeLookBack] > 1 then yes else no; def vwapSlopeDn = if vwapSlope[vwapSlopeLookBack] < -1 then yes else no; def vwapSlopeUpFlag = if vwapSlopeLength == fold i1 = 0 to vwapSlopeLength while vwapSlopeUp[i1] do i1 then yes else no; def vwapSlopeDnFlag = if vwapSlopeLength == fold i2 = 0 to vwapSlopeLength while vwapSlopeDn[i2] do i2 then yes else no; def vwapCrossBar; vwapCrossBar = if (close[1] < vwapWideUpper and close > vwapWideUpper) or (close[1] > vwapWideUpper and close < vwapWideUpper) or (close[1] > vwapWideLower and close < vwapWideLower) or (close[1] < vwapWideLower and close > vwapWideLower) or (close[1] > vwapMidUpper and close < vwapMidUpper) or (close[1] < vwapMidUpper and close > vwapMidUpper) or (close[1] > vwapMidLower and close < vwapMidLower) or (close[1] < vwapMidLower and close > vwapMidLower) or (close[1] > vwapLine and close < vwapLine) or (close[1] < vwapLine and close > vwapLine) then BarNumber() else vwapCrossBar[1]; def vwapFromCross = BarNumber() – vwapCrossBar; def vwapInRange = if vwapFromCross <= VWAPCrossWithin then yes else no; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN McClellan Summation Index SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def mcFastLength = 8; def mcSlowLength = 21; def mcMultiplier = 1000; def SlopeLength = 5; def SlopeLookBack = 8; def IsCumulative = yes; def RatioAdjusted = yes; def advances = close * mcMultiplier; def declines = vwapLine * mcMultiplier; def breadth; def neutral_level; def raw; if (RatioAdjusted) { raw = advances – declines; if 1 == 3 { # For resting change 1 == 3 to 1 == 1 and insert desired breadth value below. breadth = raw; } else if raw >= 1250 or raw <= -1250 { breadth = fold bigIndex = 0 to 1000 with foldRawBig = raw while foldRawBig > 1250 or foldRawBig < -1250 do if raw / bigIndex < 1250 or raw / bigIndex > -1250 then raw / bigIndex else if raw / (bigIndex + 0.1) < 1250 and raw / (bigIndex + 0.1) > -1250 then raw / (bigIndex + 0.1) else if raw / (bigIndex + 0.2) < 1250 and raw / (bigIndex + 0.2) > -1250 then raw / (bigIndex + 0.2) else if raw / (bigIndex + 0.3) < 1250 and raw / (bigIndex + 0.3) > -1250 then raw / (bigIndex + 0.3) else if raw / (bigIndex + 0.4) < 1250 and raw / (bigIndex + 0.4) > -1250 then raw / (bigIndex + 0.4) else if raw / (bigIndex + 0.5) < 1250 and raw / (bigIndex + 0.5) > -1250 then raw / (bigIndex + 0.5) else if raw / (bigIndex + 0.6) < 1250 and raw / (bigIndex + 0.6) > -1250 then raw / (bigIndex + 0.6) else if raw / (bigIndex + 0.7) < 1250 and raw / (bigIndex + 0.7) > -1250 then raw / (bigIndex + 0.7) else if raw / (bigIndex + 0.8) < 1250 and raw / (bigIndex + 0.8) > -1250 then raw / (bigIndex + 0.8) else if raw / (bigIndex + 0.9) < 1250 and raw / (bigIndex + 0.9) < -1250 then raw / (bigIndex + 0.9) else raw; } else if raw >= 10 or raw <= -10 or raw == 0 { breadth = raw; } else { breadth = fold smallIndex = 0 to 1000 with foldRawSmall = raw while foldRawSmall > -10 and foldRawSmall < 10 do if raw * smallIndex > 10 or raw * smallIndex < -10 then raw * smallIndex else if raw * (smallIndex + 0.1) > 10 or raw * (smallIndex + 0.1) < -10 then raw * (smallIndex + 0.1) else if raw * (smallIndex + 0.2) > 10 or raw * (smallIndex + 0.2) < -10 then raw * (smallIndex + 0.2) else if raw * (smallIndex + 0.3) > 10 or raw * (smallIndex + 0.3) < -10 then raw * (smallIndex + 0.3) else if raw * (smallIndex + 0.4) > 10 or raw * (smallIndex + 0.4) < -10 then raw * (smallIndex + 0.4) else if raw * (smallIndex + 0.5) > 10 or raw * (smallIndex + 0.5) < -10 then raw * (smallIndex + 0.5) else if raw * (smallIndex + 0.6) > 10 or raw * (smallIndex + 0.6) < -10 then raw * (smallIndex + 0.6) else if raw * (smallIndex + 0.7) > 10 or raw * (smallIndex + 0.7) < -10 then raw * (smallIndex + 0.7) else if raw * (smallIndex + 0.8) > 10 or raw * (smallIndex + 0.8) < -10 then raw * (smallIndex + 0.8) else if raw * (smallIndex + 0.9) > 10 or raw * (smallIndex + 0.9) < -10 then raw * (smallIndex + 0.9) else raw; } neutral_level = 75; } else { raw = Double.NaN; breadth = advances – declines; neutral_level = 75; } def emaFastCorr = ExpAverage(CompoundValue(1, if !IsNaN(breadth) then breadth else emaFastCorr[1], 0), mcFastLength); def emaSlowCorr = ExpAverage(CompoundValue(1, if !IsNaN(breadth) then breadth else emaSlowCorr[1], 0), mcSlowLength); def mcClellanOsc = if !IsNaN(close) then emaFastCorr – emaSlowCorr else Double.NaN; def mcClellanSummationIndex = mcClellanSummationIndex[1] + if !IsNaN(breadth) then mcClellanOsc else 0; plot MSI; if IsNaN(close) { MSI = Double.NaN; } else if (IsCumulative) { MSI = Round(neutral_level + mcClellanSummationIndex, 0); } else { MSI = Round(neutral_level + mcClellanOsc – (10 * emaFastCorr + 20 * emaSlowCorr), 0); } def MSIUp = if MSI > MSI[1] then yes else no; def MSIDown = if MSI < MSI[1] then yes else no; plot SlopePhaseMSI = MSI; def Slope = MSI – MSI[1]; def SIHigh = HighestAll(MSI); def SILow = LowestAll(MSI); def SlpHigh = HighestAll(Slope); def SlpLow = LowestAll(Slope); plot SlopePlot = Normalize(Slope, SlpHigh, SlpLow, SIHigh, SILow); def Change = Slope – Slope[1]; def ChangeThreshold = if GetAggregationPeriod() >= AggregationPeriod.DAY then ChangeDayBeyond else if GetAggregationPeriod() >= AggregationPeriod.FIFTEEN_MIN then Change15Beyond else if GetAggregationPeriod() < AggregationPeriod.FIFTEEN_MIN then Change5Beyond else Change5Beyond; def ChangeConfirmed = if Change <= -ChangeThreshold or Change >= ChangeThreshold then yes else no; def SlopeUp = Slope > Slope[1]; def SlopeDown = Slope < Slope[1]; def SlopeFlip = if (Slope[1] < 0 and Slope >= 0) or (Slope[1] > 0 and Slope <= 0) then yes else no; def SlopeFlipBar = if SlopeFlip then BarNumber() else SlopeFlipBar[1]; def SlopeFromFlip = BarNumber() – SlopeFlipBar; def SlopeInRange = if SlopeFromFlip <= SlopeCrossWithin then yes else no; plot SlopeFlipUp = if (Slope[1] < ConfirmSlopeChange and Slope >= ConfirmSlopeChange) then MSI else Double.NaN; plot SlopeFlipDown = if (Slope[1] > -ConfirmSlopeChange and Slope <= -ConfirmSlopeChange) then MSI else Double.NaN; def ChangeAtFlip = if SlopeFlip then Change else ChangeAtFlip[1]; def ChangeInit = if SlopeFlip then yes else if ChangeInit[1] and ChangeAtFlip * Change < 0 then no else ChangeInit[1]; def SlopePhase = {default “Continuation”, “Initiation”, “Termination”}; if ChangeInit { SlopePhase = SlopePhase.Initiation; } else if !ChangeInit and ChangeAtFlip * Change < 0 { SlopePhase = SlopePhase.Termination; } else { SlopePhase = SlopePhase.Continuation; } def SlopeDirection = {default “None”, “ConfirmedUp”, “UnConfirmedUp”, “ConfirmedDown”, “UnConfirmedDown”, “ReinstatedDown”}; if Slope >= ConfirmSlopeChange { SlopeDirection = SlopeDirection.ConfirmedUp; } else if Slope >= 0 and Slope < ConfirmSlopeChange { SlopeDirection = SlopeDirection.UnConfirmedUp; } else if Slope <= -ConfirmSlopeChange { SlopeDirection = SlopeDirection.ConfirmedDown; } else if Slope < 0 and Slope > -ConfirmSlopeChange { SlopeDirection = SlopeDirection.UnConfirmedDown; } else { SlopeDirection = SlopeDirection.None; } # # # # # # # # # # # # # # # # # # # # # BEGIN VFI SECTION # # # # # # # # # # # # # # # # # # # # # # input VFISmoothLength = 8; input length = 50; input maxVolumeCutOff = 2.5; Assert(maxVolumeCutOff > 0, “‘max volume cut off’ must be positive: ” + maxVolumeCutOff); def cutOff = 0.2 * StDev(Log(hlc3) – Log(hlc3[1]), 30) * close; def hlcChange = hlc3 – hlc3[1]; def avgVolume = Average(volume, 50)[1]; def minVolume = Min(volume, avgVolume * maxVolumeCutOff); def dirVolume = if hlcChange > cutOff then minVolume else if hlcChange < -cutOff then -minVolume else 0; def vfiRaw = ExpAverage(Sum(dirVolume, length) / avgVolume, 3); def VFI = Inertia(vfiRaw, VFISmoothLength); plot VFIPlot = Normalize(VFI, HighestAll(VFI), LowestAll(VFI), SIHigh, SILow); def VFISlope = Round((VFI – VFI[1]), 2); def VFIHigh = HighestAll(VFISlope); def VFILow = LowestAll(VFISlope); plot VFISlopePlot = Normalize(VFISlope, VFIHigh, VFILow, SIHigh, SILow); def VFIChange = VFISlope – VFISlope[1]; def VSlope = Round((VFISlope * 10), 2); def VChange = Round(VFIChange, 2); def VFIUp = VFI >= VFI[1]; def VFIDown = VFI < VFI[1]; # # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN 3C SPECIFIC SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # input UpWindow = 20; input DownWindow = 50; input MALength = 2; input CCCLength = 1; input Show3C = no; input ShowLine = yes; input SmoothLength = 15; def TSV; if AbsValue(close – close[1]) > high – low && close[1] > close then { TSV = -1; } else if AbsValue(close – close [1]) > high – low && close > close [1] then { TSV = 1; } else if AbsValue (close – close[1]) < high – low then { TSV = ((close – close[1]) / (high – low)) * Power(volume, (3 / 4)); } else { TSV = 0; } def TSVX = Average(TSV, MALength); def UpCondition = (TSVX > TSVX[UpWindow]); def DownCondition = (TSVX < TSVX[DownWindow]); def CCC = If(UpCondition, If (DownCondition, 0, 1), If (DownCondition, -1, 0)); def ThreeC = TotalSum(Average(CCC, CCCLength)); def ThreeCLine = Inertia(ThreeC, SmoothLength); def ThreeCUp = if ThreeCLine >= ThreeCLine[1] then yes else no; def ThreeCDown = if ThreeCLine < ThreeCLine[1] then yes else no; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN TRADE DIRECTION FLAG SPECIFIC SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # SET LONG CRITERIA HERE plot FlagLong = if TTMUp and ThreeCUp and VFIUp and MSIUp then SlopePlot else Double.NaN; # # SET SHORT CRITERIA HERE plot FlagShort = if TTMDown and ThreeCDown and VFIDown and MSIDown then SlopePlot else Double.NaN; # # EDITING BELOW THIS POINT IS GENERALLY NOTE NECESSARY plot FlagBoth = if FlagLong and FlagShort then SlopePlot else Double.NaN; # # # # # # # # # # # # # # # # # # # # # # # BEGIN DISPLAY SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # EDITING THIS SECTION IS GENERALLY NOT NECESSARY FlagLong.SetPaintingStrategy(PaintingStrategy.ARROW_UP); #FlagLong.SetPaintingStrategy(PaintingStrategy.POINTS); FlagLong.SetLineWeight(5); FlagLong.SetDefaultColor(Color.GREEN); FlagLong.HideBubble(); FlagLong.HideTitle(); FlagLong.SetHiding(if !ShowFlags then yes else no); FlagShort.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); #FlagShort.SetPaintingStrategy(PaintingStrategy.POINTS); FlagShort.SetLineWeight(5); FlagShort.SetDefaultColor(Color.RED); FlagShort.HideBubble(); FlagShort.HideTitle(); FlagShort.SetHiding(if !ShowFlags then yes else no); FlagBoth.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS); FlagBoth.SetLineWeight(5); FlagBoth.SetDefaultColor(Color.CYAN); FlagBoth.HideBubble(); FlagBoth.HideTitle(); FlagBoth.SetHiding(if !ShowFlags then yes else no); midPoint.SetStyle(Curve.LONG_DASH); midPoint.SetDefaultColor(Color.MAGENTA); midPoint.SetLineWeight(2); midPoint.HideBubble(); midPoint.HideTitle(); midPoint.SetHiding(if !ShowMACloud then yes else no); wma34.SetDefaultColor(Color.DARK_GRAY); wma34.SetLineWeight(2); wma34.HideBubble(); wma34.HideTitle(); wma34.SetHiding(if !ShowMACloud then yes else no); AddCloud(if ShowMACloud then wma34 else Double.NaN, if ShowMACloud then midPoint else Double.NaN, CreateColor(255, 0, 0), CreateColor(55, 55, 200)); vwapLine.SetStyle(Curve.FIRM); vwapLine.SetDefaultColor(Color.CYAN); vwapLine.SetDefaultColor(Color.MAGENTA); vwapLine.SetLineWeight(2); vwapLine.HideBubble(); vwapLine.HideTitle(); vwapLine.SetHiding(if !ShowVWAP then yes else no); vwapWideUpper.SetStyle(Curve.FIRM); vwapWideUpper.SetDefaultColor(Color.GREEN); vwapWideUpper.SetLineWeight(1); vwapWideUpper.HideBubble(); vwapWideUpper.HideTitle(); vwapWideUpper.SetHiding(if !ShowVWAP then yes else no); vwapMidUpper.SetStyle(Curve.LONG_DASH); vwapMidUpper.SetDefaultColor(Color.GREEN); vwapMidUpper.SetLineWeight(1); vwapMidUpper.HideBubble(); vwapMidUpper.HideTitle(); vwapMidUpper.SetHiding(if !ShowVWAP then yes else no); vwapMidLower.SetStyle(Curve.LONG_DASH); vwapMidLower.SetDefaultColor(Color.RED); vwapMidLower.SetLineWeight(1); vwapMidLower.HideBubble(); vwapMidLower.HideTitle(); vwapMidLower.SetHiding(if !ShowVWAP then yes else no); vwapWideLower.SetStyle(Curve.FIRM); vwapWideLower.SetDefaultColor(Color.RED); vwapWideLower.SetLineWeight(1); vwapWideLower.HideBubble(); vwapWideLower.HideTitle(); vwapWideLower.SetHiding(if !ShowVWAP then yes else no); SlopePlot.SetPaintingStrategy(PaintingStrategy.LINE); SlopePlot.AssignValueColor(if Slope >= Slope[1] then Color.CYAN else Color.PLUM); SlopePlot.SetLineWeight(3); SlopePlot.HideBubble(); SlopePlot.HideTitle(); SlopePlot.SetHiding(if !ShowSlope then yes else no); SlopeFlipUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP); SlopeFlipUp.SetLineWeight(3); SlopeFlipUp.SetDefaultColor(Color.WHITE); SlopeFlipUp.HideTitle(); SlopeFlipUp.HideBubble(); SlopeFlipUp.SetHiding(if !ShowSlope then yes else no); SlopeFlipDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); SlopeFlipDown.SetLineWeight(3); SlopeFlipDown.SetDefaultColor(Color.WHITE); SlopeFlipDown.HideBubble(); SlopeFlipDown.HideTitle(); SlopeFlipDown.SetHiding(if !ShowSlope then yes else no); MSI.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS); MSI.AssignValueColor( if Slope == 0 or SlopeDirection == SlopeDirection.None then Color.BLUE else if SlopeDirection == SlopeDirection.ConfirmedUp then Color.GREEN else if SlopeDirection == SlopeDirection.UnConfirmedUp then Color.BLUE else if SlopeDirection == SlopeDirection.ConfirmedDown then Color.DARK_RED else if SlopeDirection == SlopeDirection.UnConfirmedDown then Color.BLUE else Color.WHITE); MSI.SetLineWeight(3); MSI.HideTitle(); MSI.HideBubble(); MSI.SetHiding(if !ShowMSI then yes else no); SlopePhaseMSI.SetPaintingStrategy(PaintingStrategy.POINTS); SlopePhaseMSI.AssignValueColor(if SlopePhase == SlopePhase.Continuation then MSI.TakeValueColor() else if SlopePhase == SlopePhase.Initiation then Color.ORANGE else if SlopePhase == SlopePhase.Termination then Color.BLUE else Color.YELLOW); SlopePhaseMSI.SetLineWeight(3); SlopePhaseMSI.HideTitle(); SlopePhaseMSI.HideBubble(); SlopePhaseMSI.SetHiding(if !ShowMSI then yes else no); VFIPlot.SetLineWeight(3); VFIPlot.AssignValueColor(if VFI >= VFI[1] then Color.cyan else Color.PLUM); VFIPlot.SetHiding(if !ShowVFI then yes else no); VFISlopePlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS); VFISlopePlot.AssignValueColor(color.DARK_GRAY); VFISlopePlot.SetLineWeight(2); VFISlopePlot.HideTitle(); VFISlopePlot.HideBubble(); VFISlopePlot.SetHiding(if ShowVFISlope then no else yes); AddVerticalLine(ShowRTHBorders and tradingStart, “Trading S”, Color.GRAY); AddVerticalLine(ShowRTHBorders and tradingEnd, “Trading E”, Color.GRAY); AddVerticalLine(ShowRTHBorders and tradingStart and tradingEnd, “Trading S&E”, Color.GRAY); AddLabel(ShowMSILabels, ” MSI: ” + MSI , if MSI >= 0 then Color.GREEN else Color.RED); AddLabel(ShowMSILabels, “ | MSlope: ” + Slope + ” (” + Slope[1] + ” : ” + Slope[2] + ” : ” + Slope[3] + “) Xed ” + SlopeFromFlip + ” ” , if Slope >= 0 then Color.GREEN else Color.RED); AddLabel(ShowMSILabels, ” MChange: ” + Change + ” (” + Change[1] + ” : ” + Change[2] + ” : ” + Change[3] + “) ” , if Change >= 0 and ChangeConfirmed then Color.GREEN else if Change < 0 and ChangeConfirmed then Color.RED else Color.WHITE); AddLabel(ShowVFILabels, ” VFI: ” + Round(VFI, 0) + ” (” + Round(VFI[1], 0) + ” : ” + Round(VFI[2], 0) + ” : ” + Round(VFI[3], 0) + “) ” , if VFI >= 0 then Color.GREEN else Color.RED); AddLabel(ShowVFILabels, ” |VSlope: ” + Round(VSlope, 0) + ” (” + Round(VSlope[1], 0) + ” : ” + Round(VSlope[2], 0) + ” : ” + Round(VSlope[3], 0) + “) ” , if VSlope >= 0 then Color.GREEN else Color.RED); AddLabel(ShowVFILabels, “VChange: ” + VChange + ” (” + VFIChange[1] + ” : ” + VFIChange[2] + ” : ” + VFIChange[3] + “) ” , if VChange >= 0 then Color.GREEN else Color.RED); AddLabel(ShowFlipLabels, ” VWAP ” + if close > vwapWideUpper then “+2 (” + vwapFromCross + “) ” else if close < vwapWideLower then “-2 (” + vwapFromCross + “) ” else if close > vwapMidUpper then “+1 (” + vwapFromCross + “) ” else if close < vwapMidLower then “-1 (” + vwapFromCross + “) ” else “Line (” + vwapFromCross + “) ” , if close > vwapLine then Color.GREEN else if close < vwapLine then Color.RED else Color.GRAY); AddLabel(ShowFlipLabels, ” Cloud (” + MaFromCross + “) “, if GreenCloud then Color.GREEN else if !GreenCloud then Color.RED else Color.GRAY); AddLabel(ShowFlipLabels, ” TTM ” + if TTMSqueeze then “s ” + AsText(TTMHistogram , NumberFormat.TWO_DECIMAL_PLACES) + ” (” + TTMFromCross + “) ” else “n ” + AsText(TTMHistogram , NumberFormat.TWO_DECIMAL_PLACES) + ” (” + TTMFromCross + “) ” , if TTMHistogram == 0 then Color.GRAY else if TTMHistogram > 0 then Color.GREEN else Color.RED); AddLabel(yes, “3C TSVX ” + Round(TSVX, 0) + ” (” + Round(TSVX[1], 0) + ” : ” + Round(TSVX[2], 0) + ” : ” + Round(TSVX[3], 0) + “) ” , if ThreeCUp then Color.GREEN else Color.RED); AddChartBubble(FlagLong and !FlagLong[1], msi, “S ” + Slope + “\nC ” + change + “\nC ” + close, color.green); AddChartBubble(FlagShort and !FlagShort[1], msi, “S ” + Slope + “\nC ” + change + “\nC ” + close, color.red);

thinkscript

#hint: The JIN indicator includes a trend and a money flow component to help traders forecast future price direction input ReleaseVerson = “Genie Change Histogram 20180816 A”; declare lower; # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN PARAMETERS SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # input LevelMultiplier = 1; input ColorScheme = 0; #hint ColorScheme: Select color scheme to be displayed. DEFINED VALUES ARE: 0 = Normal, 1 = Color Blind Due to an anomaly in TOS changing ColorScheme value via Script Editor interface does not always work, so change it within the script instead. input ShowFibLines = no; #hint ShowFibLines: The indicator vertical display area is divided by and displays the key Fibonacci ratios and the extremes and 38.2, 61.8 above and below the 50% or mid-point of JIN’s range. These display lines help to normalize the indicator lines vis a vis each other. input FLOAverageType = AverageType.WEIGHTED; #hint FLOAverageType: Type used for the averages withing FLO calcuation. # # # # # # # # # # # # # # # # # # # # BEGIN PLOT SECTION # # # # # # # # # # # # # # # # # # # # # plot HistogramPlot; input GenieAverageType = AverageType.EXPONENTIAL; input GeniePeriod = 21; # # # # # # # # # # # # # # # # # # # # # # BEGIN PLOT SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN BUSINESS PROCESS SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN MOVING AVERAGE SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # # def Genie = Inertia(MovingAverage(GenieAverageType, close, GeniePeriod), 3); def SlopeDir = Genie; def GenieSlope = Inertia(Genie – Genie[1], 8); def HistogramValue = Inertia(GenieSlope – GenieSlope[1], 5); HistogramPlot = HistogramValue; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN DISPLAY SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN DEFINE GLOBAL COLOR ASSIGNMENT SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # DefineGlobalColor(“Blue 300”, CreateColor(117, 125, 232)); DefineGlobalColor(“Blue 500”, CreateColor(63, 81, 181)); DefineGlobalColor(“Blue 900”, CreateColor(0, 41, 132)); DefineGlobalColor(“Red 300”, CreateColor(255, 121, 97)); DefineGlobalColor(“Red 500”, CreateColor(244, 67, 54)); DefineGlobalColor(“Red 900”, CreateColor(183, 28, 28)); DefineGlobalColor(“Green 300”, CreateColor(128, 226, 126)); DefineGlobalColor(“Green 500”, CreateColor(76, 175, 80)); DefineGlobalColor(“Green 900”, CreateColor(8, 127, 35)); DefineGlobalColor(“Amber 500”, CreateColor(255, 193, 7)); DefineGlobalColor(“Amber 900”, CreateColor(255, 111, 0)); DefineGlobalColor(“Gray 800”, CreateColor(68, 68, 68)); DefineGlobalColor(“Gray 500”, CreateColor(158, 158, 158)); DefineGlobalColor(“Gray 200”, CreateColor(238, 238, 238)); DefineGlobalColor(“Indigo 500”, CreateColor(63, 81, 181)); DefineGlobalColor(“White”, CreateColor(255, 255, 255)); DefineGlobalColor(“Black”, CreateColor(0, 0, 0)); # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN VERTICLE LINES SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN LABELS SECTION # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # BEGIN DISPLAY SECTION # # # # # # # # # # # # # # # # # # # # # # # # HistogramPlot.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); HistogramPlot.DefineColor(“Up”, GlobalColor(“Green 500”)); HistogramPlot.DefineColor(“Down”, GlobalColor(“Red 900”)); HistogramPlot.DefineColor(“Flat”, GlobalColor(“Blue 500”)); HistogramPlot.AssignValueColor( if HistogramValue > HistogramValue[1] then GlobalColor(“Blue 300”) else if HistogramValue < HistogramValue[1] then GlobalColor(“Red 900”) else GlobalColor(“Gray 500”)); HistogramPlot.SetLineWeight(5); HistogramPlot.HideBubble(); HistogramPlot.HideTitle(); HistogramPlot.SetHiding(no); AssignPriceColor( if HistogramValue > HistogramValue[1] and Genie > Genie[1] then GlobalColor(“Green 500”) else if HistogramValue < HistogramValue[1] and Genie < Genie[1] then GlobalColor(“Red 900”) else GlobalColor(“Blue 500”));

thinkscript

#———————————————–begin code declare upper;input price = close;input displace = 0;def length3ema = 3;def length15ema = 15;def length30ema = 30;def length60ema = 60;plot avgexp3 = ExpAverage(data = price[-displace], length = length3ema);avgexp3.SetDefaultColor(Color.Gray);plot avgexp15 = ExpAverage(data = price[-displace], length = length15ema);avgexp15.SetDefaultColor(Color.Gray);AddCloud(avgexp3, avgexp15);plot avgexp30 = ExpAverage(data = price[-displace], length = length30ema);avgexp30.SetDefaultColor(Color.Gray);plot avgexp60 = ExpAverage(data = price[-displace], length = length60ema);avgexp60.SetDefaultColor(Color.Gray);AddCloud(avgexp30, avgexp60); #———————————————–end code

thinkScript

#THE SOFTWARE. 

# 

  

script WMA_Smooth { 

input price = hl2; 

plot smooth = (4 * price 

+ 3 * price[1] 

+ 2 * price[2] 

+ price[3]) / 10; 

} 

  

script Phase_Accumulation { 

# This is Ehler’s Phase Accumulation code. It has a full cycle delay. 

# However, it computes the correction factor to a very high degree. 

# 

input price = hl2; 

  

rec Smooth; 

rec Detrender; 

rec Period; 

rec Q1; 

rec I1; 

rec I1p; 

rec Q1p; 

rec Phase1; 

rec Phase; 

rec DeltaPhase; 

rec DeltaPhase1; 

rec InstPeriod1; 

rec InstPeriod; 

def CorrectionFactor; 

  

if barNumber() <= 5 

then { 

Period = 0; 

Smooth = 0; 

Detrender = 0; 

CorrectionFactor = 0; 

Q1 = 0; 

I1 = 0; 

Q1p = 0; 

I1p = 0; 

Phase = 0; 

Phase1 = 0; 

DeltaPhase1 = 0; 

DeltaPhase = 0; 

InstPeriod = 0; 

InstPeriod1 = 0; 

} else { 

CorrectionFactor = 0.075 * Period[1] + 0.54; 

  

# Smooth and detrend my smoothed signal: 

Smooth = WMA_Smooth(Price); 

Detrender = ( 0.0962 * Smooth 

+ 0.5769 * Smooth[2] 

– 0.5769 * Smooth[4] 

– 0.0962 * Smooth[6] ) * CorrectionFactor; 

  

# Compute Quadrature and Phase of Detrended signal: 

Q1p = ( 0.0962 * Detrender 

+ 0.5769 * Detrender[2] 

– 0.5769 * Detrender[4] 

– 0.0962 * Detrender[6] ) * CorrectionFactor; 

I1p = Detrender[3]; 

  

# Smooth out Quadrature and Phase: 

I1 = 0.15 * I1p + 0.85 * I1p[1]; 

Q1 = 0.15 * Q1p + 0.85 * Q1p[1]; 

  

# Determine Phase 

if I1 != 0 then { 

# Normally, ATAN gives results from -pi/2 to pi/2. 

# We need to map this to circular coordinates 0 to 2pi 

  

if Q1 

 

    >= 0 and I1 > 0 then { # Quarant 1 

 

Phase1 = ATan(absValue(Q1/I1)); 

} else if Q1 >= 0 and I1 < 0 then { # Quadrant 2 

Phase1 = Double.PI – ATan(absValue(Q1/I1)); 

} else if Q1 < 0 and I1 < 0 then { # Quadrant 3 

Phase1 = Double.PI + ATan(absValue(Q1/I1)); 

} else { # Quadrant 4 

Phase1 = 2*Double.PI – ATan(absValue(Q1/I1)); 

} 

} else if Q1 > 0 then { # I1 == 0, Q1 is positive 

Phase1 = Double.PI/2; 

} else if Q1 < 0 then { # I1 == 0, Q1 is negative 

Phase1 = 3*Double.PI/2; 

} else { # I1 and Q1 == 0 

Phase1 = 0; 

} 

  

# Convert phase to degrees 

Phase = Phase1 * 180 / Double.PI; 

  

if Phase[1] < 90 and Phase > 270 then { 

# This occurs when there is a big jump from 360-0 

DeltaPhase1 = 360 + Phase[1] – Phase; 

} else { 

DeltaPhase1 = Phase[1] – Phase; 

} 

  

# Limit our delta phases between 7 and 60 

if DeltaPhase1 < 7 

then { 

DeltaPhase = 7; 

} else if DeltaPhase1 > 60 then { 

DeltaPhase = 60; 

} else { 

DeltaPhase = DeltaPhase1; 

} 

  

# Determine Instantaneous period: 

InstPeriod1 = 

-1*(fold i=0 to 40 with v=0 do 

if v < 0 then 

v 

else if v > 360 then 

-i 

else 

v + getValue(DeltaPhase, i, 41) 

); 

  

if InstPeriod1 <= 0 then { 

InstPeriod = InstPeriod[1]; 

} else { 

InstPeriod = InstPeriod1; 

} 

  

Period = 0.25*InstPeriod + 0.75*Period[1]; 

} 

plot DC = period; 

} 

  

script Ehler_MAMA { 

input price = hl2; 

input FastLimit = 0.5; 

input SlowLimit = 0.05; 

  

rec Period; 

rec Period_raw; 

rec Period_cap; 

rec Period_lim; 

  

rec Smooth; 

rec Detrender; 

rec I1; 

rec Q1; 

rec jI; 

rec jQ; 

rec I2; 

rec Q2; 

rec I2_raw; 

rec Q2_raw; 

  

rec Phase; 

rec DeltaPhase; 

rec DeltaPhase_raw; 

rec alpha; 

rec alpha_raw; 

  

rec Re; 

rec Im; 

rec Re_raw; 

rec Im_raw; 

  

rec SmoothPeriod; 

rec vmama; 

rec vfama; 

  

def CorrectionFactor = Phase_Accumulation(price).CorrectionFactor; 

  

if barNumber() <= 5 

then { 

Smooth = 0; 

Detrender = 0; 

  

Period = 0; 

Period_raw = 0; 

Period_cap = 0; 

Period_lim = 0; 

I1 = 0; 

Q1 = 0; 

I2 = 0; 

Q2 = 0; 

jI = 0; 

jQ = 0; 

I2_raw = 0; 

Q2_raw = 0; 

Re = 0; 

Im = 0; 

Re_raw = 0; 

Im_raw = 0; 

SmoothPeriod = 0; 

Phase = 0; 

DeltaPhase = 0; 

DeltaPhase_raw = 0; 

alpha = 0; 

alpha_raw = 0; 

vmama = 0; 

vfama = 0; 

} else { 

# Smooth and detrend my smoothed signal: 

Smooth = WMA_Smooth(Price); 

Detrender = ( 0.0962 * Smooth 

+ 0.5769 * Smooth[2] 

– 0.5769 * Smooth[4] 

– 0.0962 * Smooth[6] ) * CorrectionFactor; 

  

Q1 = ( 0.0962 * Detrender 

+ 0.5769 * Detrender[2] 

– 0.5769 * Detrender[4] 

– 0.0962 * Detrender[6] ) * CorrectionFactor; 

I1 = Detrender[3]; 

  

jI = ( 0.0962 * I1 

+ 0.5769 * I1[2] 

– 0.5769 * I1[4] 

– 0.0962 * I1[6] ) * CorrectionFactor; 

  

jQ = ( 0.0962 * Q1 

+ 0.5769 * Q1[2] 

– 0.5769 * Q1[4] 

– 0.0962 * Q1[6] ) * CorrectionFactor; 

  

# This is the complex conjugate 

I2_raw = I1 – jQ; 

Q2_raw = Q1 + jI; 

  

I2 = 0.2*I2_raw + 0.8*I2_raw[1]; 

Q2 = 0.2*Q2_raw + 0.8*Q2_raw[1]; 

  

Re_raw = I2*I2[1] + Q2*Q2[1]; 

Im_raw = I2*Q2[1] – Q2*I2[1]; 

  

Re = 0.2*Re_raw + 0.8*Re_raw[1]; 

Im = 0.2*Im_raw + 0.8*Im_raw[1]; 

  

# Compute the phase 

if Re != 0 and Im != 0 then { 

Period_raw = 2*double.PI / atan(Im/Re); 

} else { 

Period_raw = 0; 

} 

  

if Period_raw > 1.5*Period_raw[1] then { 

Period_cap = 1.5*Period_raw[1]; 

} else if Period_raw < 0.67 * Period_raw[1] { 

Period_cap = 0.67 * Period_raw[1]; 

} else { 

Period_cap = Period_raw; 

} 

  

if Period_cap < 6 then { 

Period_lim = 6; 

} else if Period_cap > 50 then { 

Period_lim = 50; 

} else { 

Period_lim = Period_cap; 

} 

  

Period = 0.2*Period_lim + 0.8*Period_lim[1]; 

SmoothPeriod = 0.33*Period + 0.67*SmoothPeriod[1]; 

  

if I1 != 0 then { 

Phase = ATan(Q1 / I1); 

} else if Q1 > 0 then { # Quadrant 1: 

Phase = Double.Pi/2; 

} else if Q1 < 0 then { # Quadrant 4: 

Phase = -Double.Pi/2; 

} else { # Both numerator and denominator are 0. 

Phase = 0; 

} 

  

DeltaPhase_raw = Phase[1] – Phase; 

If DeltaPhase_raw < 1 then { 

DeltaPhase = 1; 

} else { 

DeltaPhase = DeltaPhase_raw; 

} 

  

alpha_raw = FastLimit / DeltaPhase; 

If alpha_raw < SlowLimit then { 

alpha = SlowLimit; 

} else { 

alpha = alpha_raw; 

} 

vmama = alpha*Price + (1 – alpha)*vmama[1]; 

vfama = 0.5*alpha*vmama + (1 – 0.5*alpha)*vfama[1]; 

} 

  

plot MAMA = vmama; 

plot FAMA = vfama; 

} 

  

declare lower; 

input price = hl2; 

input FastLimit = 0.5; 

input SlowLimit = 0.05; 

  

def MAMA = Ehler_MAMA(price, FastLimit, SlowLimit).MAMA; 

def FAMA = Ehler_MAMA(price, FastLimit, SlowLimit).FAMA; 

  

Plot MADIFF = (mama-fama); 

        madiff.SetPaintingStrategy(paintingStrategy.HISTOGRAM); 

        madiff.AssignValueColor (if madiff >= 0.00 then (color.green) else (color.red)); 

  

Plot MALine = madiff; 

        maline.AssignValueColor (if madiff >= 0.00 then (color.green) else (color.red)); 

thinkScript

# Dual Moving Averages with clouds and cross arrows 

#Labels added by SFL 

#TOS Title = CloudBetween2MovingAverages 

#hint:Cloud usage between two moving averages 

 

declare upper; 

 

#  Input Code 

input price = close;#hint close:Select the price of choice 

input fastLength = 8;#hint fastLength:The fast average length 

input fastAvgType = AverageType.SIMPLE;#hint fastAvgType:Select the average type 

input slowLength = 20;#hint slowLength:The slow average length 

input slowAvgType = AverageType.SIMPLE; #hint slowAvgType:Select the average type 

input Show_Crosses = YES;#hint Show_Crosses:Toggles crossing arrows ON/OFF 

 

#  Moving Average Plot Code 

plot FastMva = MovingAverage( fastAvgType, price, fastLength ); 

plot SlowMva = MovingAverage( slowAvgType, price, slowLength ); 

 

#  Cloud Code 

AddCloud( FastMva, SlowMva, Color.YELLOW, Color.RED ); 

 

#  Crossing Code 

def CrossUp =  if Crosses(FastMva, SlowMva, CrossingDirection.above) then 1 else 0; 

Plot UpArrow = If CrossUp && Show_Crosses then low else double.nan; 

UpArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); 

UpArrow.SetLineWeight(3); 

UpArrow.SetDefaultColor(Color.GREEN); 

 

def CrossDown =  if Crosses(FastMva, SlowMva, CrossingDirection.below) then 1 else 0; 

Plot DownArrow = If CrossDown && Show_Crosses then high else double.nan; 

DownArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); 

DownArrow.SetLineWeight(3); 

DownArrow.SetDefaultColor(Color.RED); 

#  Label Code 

#AddLabel(Show_Crosses,”Cross = UP ARROW”,color.PINK); 

 

addlabel(1,”Slow MA(” +  slowLength  + “) is ” +  (If fastAvgType == AverageType.EXPONENTIAL then “Exponential average”  

else if  fastAvgType == AverageType.Hull then “Hull average”  

else if fastAvgType == AverageType.simple then “Simple average” 

else if fastAvgType == AverageType.wilders then “Wilders average” 

else if fastAvgType == AverageType.weighted then “Weighted average” 

else “”)   ,color.cyan); 

 

addlabel(1,”Fast MA(” +  fastLength  + “) is ” +  (If slowAvgType == AverageType.EXPONENTIAL then “Exponential average”  

else if  slowAvgType == AverageType.Hull then “Hull average”  

else if slowAvgType == AverageType.simple then “Simple average” 

else if slowAvgType == AverageType.wilders then “Wilders average” 

else if slowAvgType == AverageType.weighted then “Weighted average” 

else “”)   ,color.pink); 

# end 

thinkScript

#Start Script# 

declare lower; 

input show_bubbles= no; 

input show_shadow= yes; 

input show_ema= no; 

input show_historical_chop= yes; 

input trade_in_squeeze= yes; 

input show_mini_studies= no; 

 

##studies 

def value = MACD().”value”; 

def avg = MACD().”avg”; 

def dmiosc = DMI_Oscillator().”osc”; 

def vplus = VortexIndicator().”vi+”; 

def vminus = VortexIndicator().”vi-“; 

def squeezehist = TTM_Squeeze().”histogram”; 

def bbs = BollingerBandsSMA().”upperband”; 

def kelt = KeltnerChannels().”upper_band”; 

 

##Normalizers 

script normalizePlot { 

    input data = close; 

    input newRngMin = 1; 

    input newRngMax = 20; 

    input vertdisp= 0; 

    def hhData = HighestAll( data ); 

    def llData = LowestAll( data ); 

    plot nr = (((newRngMax – newRngMin) * (data – llData)) /  

                (hhData – llData)) + newRngMin; 

} 

 

#mobiuschoppiness  

def chopLength   = 14; 

def chopSignal   =  3; 

input CIx = {default CIB, CIA}; 

def CIA = 100 * Log( Sum( TrueRange(high, close, low), chopLength)) / ( Highest(close[1], chopLength) – Lowest(close[1], chopLength)) / Log(chopLength); 

def CIB = ((Log(Sum(TrueRange(high, close, low), chopLength) / 

(Highest(if high >= close[1] then high else close[1], chopLength) – Lowest( if low <= close[1] then low else close[1], chopLength))) / Log(10)) / (Log(chopLength) / Log(10))) * 100; 

def CI = if CIx == CIx.CIB then CIB else CIA; 

 

#Grail 

##Grail Inputs 

def showlastcrossover = yes; 

def lengthW = 2; 

def price = close; 

def lengthM = 3; 

def lengthM2 = 4; 

 

#Grail Calc’s and Cond’s 

def coeffW = lengthW * price * price – 2 * price * Sum(price, lengthW)[1] + Sum(price * price, lengthW)[1]; 

 

def coeffM = lengthM * price * price – 2 * price * Sum(price, lengthM)[1] + Sum(price * price, lengthM2)[1]; 

 

def EhlersWarrow = WildersAverage((Sum(coeffW * price, lengthW) / Sum(coeffW, lengthW)), lengthW); 

def EhlersMarrow = WildersAverage((ExpAverage((Sum(coeffM * price, lengthM) / Sum(coeffM, lengthM)), lengthM)), lengthM2); 

 

def conditionBELOW = Crosses(EhlersWarrow, EhlersMarrow, CrossingDirection.BELOW); 

def conditionABOVE = Crosses(EhlersWarrow, EhlersMarrow, CrossingDirection.ABOVE); 

 

## Grail Plots 

plot down = if conditionBELOW == yes then 21 else Double.NaN; 

plot up = if conditionABOVE == yes then 21 else Double.NaN; 

down.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); 

down.AssignValueColor(Color.YELLOW); 

down.SetLineWeight(2); 

up.SetPaintingStrategy(PaintingStrategy.ARROW_UP); 

up.AssignValueColor(Color.YELLOW); 

up.SetLineWeight(2); 

 

##modifications 

def macdosc = value – avg; 

def vortexosc = vplus – vminus; 

def squeeze = if bbs < kelt then yes else no; 

def volosc = (Average(volume, 12) – Average(volume, 26)); 

 

##conditions/plots 

plot volume = volosc; 

plot volume1 = 21; 

plot macd1= if trade_in_squeeze==no and squeeze==yes then double.nan else if macdosc > 0 then 18 else 16; 

plot macd2 = if trade_in_squeeze==no and squeeze==yes then double.nan else if macdosc < 0 then 18 else 16; 

plot dmi1 = if trade_in_squeeze==no and squeeze==yes then double.nan else if dmiosc > 0 then 14 else 12; 

plot dmi2 = if trade_in_squeeze==no and squeeze==yes then double.nan else if dmiosc < 0 then 14 else 12; 

plot vortex1 = if trade_in_squeeze==no and squeeze==yes then double.nan else if vortexosc > 0 then 10 else 8; 

plot vortex2 =  if trade_in_squeeze==no and squeeze==yes then double.nan else if vortexosc <= 0 then 10 else 8; 

plot squeezehist1 = if trade_in_squeeze==no and squeeze==yes then double.nan else if squeezehist > 0 then 6 else 4; 

plot squeezehist2 = if trade_in_squeeze==no and squeeze==yes then double.nan else if squeezehist < 0 then 6 else 4; 

plot insqueeze = if squeeze == yes then yes else 1; 

plot chop = if show_historical_chop == yes then 1 else double.nan; 

 

##styling 

###Coloring 

volume.DefineColor(“Highest”, Color.GREEN); 

volume.DefineColor(“Lowest”, Color.LIGHT_RED); 

volume.AssignNormGradientColor(9, volume.Color(“Lowest”), volume.Color(“Highest”)); 

volume.Hide(); 

volume1.AssignValueColor(volume.TakeValueColor()); 

volume1.SetLineWeight(5); 

 

macd1.SetDefaultColor(Color.CYAN); 

macd2.SetDefaultColor(Color.CYAN); 

dmi1.SetDefaultColor(Color.CYAN); 

dmi2.SetDefaultColor(Color.CYAN); 

vortex1.SetDefaultColor(Color.CYAN); 

vortex2.SetDefaultColor(Color.CYAN); 

squeezehist1.SetDefaultColor(Color.CYAN); 

squeezehist2.SetDefaultColor(Color.CYAN); 

 

insqueeze.AssignValueColor(if squeeze == yes then Color.RED else Color.GREEN); 

insqueeze.SetPaintingStrategy(PaintingStrategy.POINTS); 

insqueeze.SetLineWeight(5); 

 

AddLabel(1, if CI <= 50 then “Trend Level: Trending” else if CI > 50 and CI <=68.2 then “Trend Level: Choppy” else “Trend Level: Very Choppy”, if CI <= 50 then Color.GREEN else if CI > 50 and CI <=68.2 then Color.YELLOW else Color.RED); 

 

chop.assignValueColor(if ci<=50 then color.dark_green else if ci>50 and ci<68.2 then color.yellow else color.dark_red); 

chop.setpaintingstrategy(PaintingStrategy.SQUARED_HISTOGRAM); 

 

 

###clouds 

AddCloud(macd1,  macd2,  Color.GREEN,  Color.RED); 

AddCloud(dmi1, dmi2, Color.GREEN, Color.RED); 

AddCloud(vortex1, vortex2, Color.GREEN, Color.RED); 

AddCloud(squeezehist1, squeezehist2, Color.GREEN, Color.RED); 

 

#special cloud 

#AddCloud(macd1,  macd2,  Color.GREEN,  Color.RED); 

 

###chartbubbles 

AddChartBubble(BarNumber() % 150 == 0 and show_bubbles==yes, 15, “MACD”, Color.YELLOW); 

AddChartBubble(BarNumber() % 150 == 0 and show_bubbles==yes, 11, “DMI”, Color.YELLOW); 

AddChartBubble(BarNumber() % 150 == 0 and show_bubbles==yes, 7, “Vortex”, Color.YELLOW); 

AddChartBubble(BarNumber() % 150 == 0 and show_bubbles==yes, 3, “Histogram”, Color.YELLOW); 

 

 

##Signal 

def allignedlong = if macd1 == 18 and dmi1 == 14 and vortex1 == 10 and squeezehist1 == 6 then 18 else if show_shadow==yes then 4 else double.nan; 

def allignedshort = if macd2 == 18 and dmi2 == 14 and vortex2 == 10 and squeezehist2 == 6 then 18 else if show_shadow == yes then 4 else double.nan; 

AddCloud(allignedlong, allignedshort, Color.GREEN, Color.RED); 

 

##T3 EMA Knot 

 

def n  =  7; 

def n1 = 10; 

def n2 = 14; 

def n3 = 21; 

def vf = 0.7; 

 

  def c = rsiwilder(); 

  def a = (Inertia(c, n) * (1 + vf)) –  

           (Inertia(Inertia(c, n), n) * vf); 

  def GD = ExpAverage(a,  n ); 

  def T1 = ExpAverage(GD, n1); 

  def T2 = ExpAverage(T1, n2); 

  def T3 = ExpAverage(T2, n3); 

 

def data = NormalizePlot(GD,1,20);  

def data1 = NormalizePlot(t1,1,20); 

def data2 = NormalizePlot(t2,1,20); 

def data3 = NormalizePlot(t3,1,20); 

def knot1= if data>data1 then 1 else -1; 

def knot2= if data1>data2 then 1 else -1; 

def knot3= if data2>data3 then 1 else -1; 

def knot4= if data1>data3 then 1 else -1; 

def knot= knot1+knot2+knot3+knot4; 

 

 

#EMA Plots 

plot ema = if show_ema==yes then data else double.nan; 

plot ema1 = if show_ema==yes then data1 else Double.NaN; 

plot ema2 = if show_ema==yes then data2 else Double.NaN; 

plot ema3 = if show_ema==yes then data3 else Double.Nan; 

 

addlabel(1, if between(knot, -1, 1) then “Knot Level: Knotted” else 

 

if between(knot, -2, 2) then “Knot Level: Loose” else if knot>2 then “Knot Level: Long” else “Knot Level: Short”, if between(knot, -1, 1) then color.gray else if knot==2 then color.dark_green else if knot==-2 then color.dark_red else if knot==3 or knot==4 then color.green else color.red);  

#addlabel(1, knot, color.white); 

 

#Mini studies 

#plot minimacd1= normalizeplot(value,18,16); 

#plot minimacd2= normalizeplot(avg,18,16); 

plot minimacd= if show_mini_studies==yes then normalizeplot(macdosc * -1,19,15) else double.nan; 

plot minidmi= if show_mini_studies==yes then normalizeplot(dmiosc * -1,15,11) else double.nan; 

plot minivortex= if show_mini_studies==yes then normalizeplot(vortexosc * -1,11,7) else double.nan; 

plot minisqueeze= if show_mini_studies==yes then normalizeplot(squeezehist * -1,7,3) else double.nan; 

plot minimacdzero= if show_mini_studies==yes then 17 else double.nan; 

plot minidmizero= if show_mini_studies==yes then 13 else double.nan; 

plot minivortexzero= if show_mini_studies==yes then 9 else double.nan; 

plot minisqueezezero=if show_mini_studies==yes then 5 else double.nan; 

 

#miniplots 

minimacd.setdefaultcolor(color.magenta); 

minidmi.setdefaultcolor(color.magenta); 

minivortex.setdefaultcolor(color.magenta); 

minisqueeze.setdefaultcolor(color.magenta); 

minimacdzero.setdefaultcolor(color.white); 

minidmizero.setdefaultcolor(color.white); 

minivortexzero.setdefaultcolor(color.white); 

minisqueezezero.setdefaultcolor(color.white); 

 

#End script 

thinkScript

declare lower; 

input length = 14; 

input trendSpeed = 25; 

input thresholdLine = 20; 

plot Threshold = thresholdLine; 

Threshold.setDefaultColor(color.green); 

Threshold.setStyle(curve.FIRM); 

Threshold.setLineWeight(2); 

plot Bullish_Power = DiPlus(length = length); 

Bullish_Power.setPaintingStrategy(paintingStrategy.HISTOGRAM); 

Bullish_Power.setLineWeight(5); 

Bullish_Power.setDefaultColor(color.white); 

plot Bearish_Power = DiMinus(length = length); 

Bearish_Power.setPaintingStrategy(paintingStrategy.HISTOGRAM); 

Bearish_Power.setLineWeight(5); 

Bearish_Power.setDefaultColor(color.red); 

plot Trend_Speed = ADX(length = length); 

Trend_Speed.setDefaultColor(color.yellow); 

Trend_Speed.setLineWeight(5); 

 

alert(crosses(Bullish_Power, Bearish_Power, CrossingDirection.ABOVE), “Power Shift Bullish”, Alert.BAR, sound.Ring); 

alert(crosses(Bullish_Power, Bearish_Power, CrossingDirection.BELOW), “Power Shift Bearish”, Alert.BAR, sound.Ring); 

alert(crosses(Trend_Speed, Threshold, CrossingDirection.ABOVE), “Trending”, Alert.BAR, sound.Ring); 

alert(crosses(Trend_Speed, Threshold, CrossingDirection.BELOW), “Choppy”, Alert.BAR, sound.Ring); 

# end  

Thinkorswim custom indicators