Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // @author LazyBear
- // List of all my indicators:
- // https://docs.google.com/document/d/15AGCufJZ8CIUvwFJ9W-IKns88gkWOKBCvByMEvm5MLo/edit?usp=sharing
- // v3 - MTF support added
- // v2 - fixed a typo, where BB multipler was always stuck at 1.5. [Thanks @ucsgears]
- // v1 - initial release
- //
- study(shorttitle = "SQZMOM_MTF_LB", title="Squeeze Momentum Indicator v3 [LazyBear]", overlay=false)
- length = input(20, title="BB Length")
- mult = input(2.0,title="BB MultFactor")
- lengthKC=input(20, title="KC Length")
- multKC = input(1.5, title="KC MultFactor")
- useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)
- useCustomTimeframe=input(false)
- customTimeframe=input("D", type=resolution)
- source = useCustomTimeframe ? security(tickerid, customTimeframe, close) : close
- h=useCustomTimeframe ? security(tickerid, customTimeframe, high) : high
- l=useCustomTimeframe ? security(tickerid, customTimeframe, low) : low
- tr_t=useCustomTimeframe ? security(tickerid, customTimeframe, tr) : tr
- // Calculate BB
- basis = sma(source, length)
- dev = mult * stdev(source, length)
- upperBB = basis + dev
- lowerBB = basis - dev
- // Calculate KC
- ma = sma(source, lengthKC)
- range = useTrueRange ? tr_t : (h - l)
- rangema = sma(range, lengthKC)
- upperKC = ma + rangema * multKC
- lowerKC = ma - rangema * multKC
- sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
- sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
- noSqz = (sqzOn == false) and (sqzOff == false)
- val = linreg(source - avg(avg(highest(h, lengthKC), lowest(l, lengthKC)),sma(source,lengthKC)),
- lengthKC,0)
- bcolor = iff( val > 0,
- iff( val > nz(val[1]), lime, green),
- iff( val < nz(val[1]), red, maroon))
- scolor = noSqz ? blue : sqzOn ? black : gray
- plot(val, color=bcolor, style=histogram, linewidth=4)
- plot(0, color=scolor, style=cross, linewidth=2)
Advertisement