Swing Trading Indicators

declare lower; input paintBars =yes ; # hint paintBars: Yes to color price bars. input diFilter = Yes; #hint diFilter: No to turn off DI filter. input avgFilter = Yes; #hint avgFilter: No to turn off mov. avg. filter. input prFilter = Yes; #hint prFilter: No to turn off price filter. input price = close; #hint price: price fundamental. input prMom = 1; #hint prMom: offset for price (mom)entum. input diLength = 13; #hint diLength: For DI+, DI- calc, and mom sum. input signal = 13; #hint signal: Horiz. position of the Sig line. ############################################# # Keltner Channel and Bollinger Band Squeeze: input avgType = AverageType.SIMPLE; # Mov. avg type. input avgLength = 20; # length for band and channel mov. avg. input numDev = 2.0; # number of std devs of band. input factor = 1.5; # factor for offsetting channel. def MA = MovingAverage(avgType, price, avgLength); # inSqueeze is true if the upper band is inside the upper channel: def inSqueeze = (MA + numDev * StDev(price, avgLength)) < (MA + (factor * Average(TrueRange(high, close, low), avgLength))); # ############################################# def hiDiff = high - high[1]; def loDiff = low[1] - low; def ATR = WildersAverage(TrueRange(high, close, low), diLength); # diDif is ("DI+" - "DI-") def diDif = (100 * WildersAverage(if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0, diLength) / ATR) – (100 * WildersAverage(if loDiff > hiDiff and loDiff > 0 then loDiff else 0, diLength) / ATR); rec ppsDir = CompoundValue(1, if !IsNaN(PPS().BuySignal) then 1 else if !IsNaN(PPS().SellSignal) then -1 else ppsDir[1], 0); def diUp = !diFilter or (diFilter and diDif > 0 and diDif > diDif[1]); def diDn = !diFilter or (diFilter and diDif < 0 and diDif < diDif[1]); def avgUp = !avgFilter or (avgFilter and price > MA); def avgDn = !avgFilter or (avgFilter and price < MA); # Price momentum sums: def sumUp = if prFilter then Sum(price > price[prMom], diLength) else 0; def sumDn = if prFilter then Sum(price < price[prMom], diLength) else 0; # prLbl=Off: Hide price momentum label. # prLbl=All: Show prMom, sumUp and sumDn values. # prLbl=UD: Show only sumUp and sumDn values. input prLbl = {default Off, All, UD}; AddLabel(prLbl != prLbl.Off, (if prLbl == prLbl.All then "prMom=" + prMom + " :: " else "") + "U=" + sumUp + " :: D=" + sumDn, if sumUp > sumDn then Color.GREEN else if sumUp < sumDn then Color.magenta else Color.GRAY); # dir is 1 if last PPS signal was up, and up filters are valid or turned off; dir is -1 if last PPS signal was down, and down filters are valid or turned off. rec dir = CompoundValue(1, if ppsDir > 0 and avgUp and diUp then 1 else if ppsDir < 0 and avgDn and diDn then -1 else dir[1], 0); # Count the number of times dir is in one direction. rec dirCnt = compoundValue(1, if dir crosses 0 then 1 else dirCnt[1] + 1, 0); # If dir is up (> 0) then add to dirCnt the sum of price bars moving up, else add to dir the sum of price bars moving down. plot Count = if !IsNaN(close) then if dir > 0 then dirCnt + sumUp else dirCnt + sumDn else Double.NaN; # Sig is colored differently when in or out of squeeze. plot Sig = if !IsNaN(close) then signal else Double.NaN; Sig.SetPaintingStrategy(PaintingStrategy.POINTS); Sig.AssignValueColor(if inSqueeze then Color.DARK_GRAY else Color.WHITE); Sig.SetDefaultColor(Color.GRAY); Count.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS); Count.AssignValueColor(if dir > 0 then if Count > Sig then Color.GREEN else Color.blue else if Count > Sig then Color.gray else Color.magenta); AssignPriceColor(if !paintBars then Color.CURRENT else if dir > 0 then if Count > Sig then Color.GREEN else Color.uptick else if dir < 0 then if Count > Sig then Color.gray else Color.gray else Color.GRAY); ## END STUDY

Thinkorswim custom indicators