Guest User

Squeeze Momentum Indicator v3 with MTF support [LazyBear]

a guest
Oct 11th, 2014
7,821
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. //
  2. // @author LazyBear
  3. // List of all my indicators:
  4. // https://docs.google.com/document/d/15AGCufJZ8CIUvwFJ9W-IKns88gkWOKBCvByMEvm5MLo/edit?usp=sharing
  5. // v3 - MTF support added
  6. // v2 - fixed a typo, where BB multipler was always stuck at 1.5. [Thanks @ucsgears]
  7. // v1 - initial release
  8. //
  9. study(shorttitle = "SQZMOM_MTF_LB", title="Squeeze Momentum Indicator v3 [LazyBear]", overlay=false)
  10.  
  11. length = input(20, title="BB Length")
  12. mult = input(2.0,title="BB MultFactor")
  13. lengthKC=input(20, title="KC Length")
  14. multKC = input(1.5, title="KC MultFactor")
  15.  
  16. useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)
  17. useCustomTimeframe=input(false)
  18. customTimeframe=input("D", type=resolution)
  19.  
  20. source = useCustomTimeframe ? security(tickerid, customTimeframe, close) : close
  21. h=useCustomTimeframe ? security(tickerid, customTimeframe, high) : high
  22. l=useCustomTimeframe ? security(tickerid, customTimeframe, low) : low
  23. tr_t=useCustomTimeframe ? security(tickerid, customTimeframe, tr) : tr
  24.  
  25. // Calculate BB
  26. basis = sma(source, length)
  27. dev = mult * stdev(source, length)
  28. upperBB = basis + dev
  29. lowerBB = basis - dev
  30.  
  31. // Calculate KC
  32. ma = sma(source, lengthKC)
  33. range = useTrueRange ? tr_t : (h - l)
  34. rangema = sma(range, lengthKC)
  35. upperKC = ma + rangema * multKC
  36. lowerKC = ma - rangema * multKC
  37.  
  38. sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
  39. sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
  40. noSqz = (sqzOn == false) and (sqzOff == false)
  41.  
  42. val = linreg(source - avg(avg(highest(h, lengthKC), lowest(l, lengthKC)),sma(source,lengthKC)),
  43. lengthKC,0)
  44.  
  45. bcolor = iff( val > 0,
  46. iff( val > nz(val[1]), lime, green),
  47. iff( val < nz(val[1]), red, maroon))
  48. scolor = noSqz ? blue : sqzOn ? black : gray
  49. plot(val, color=bcolor, style=histogram, linewidth=4)
  50. plot(0, color=scolor, style=cross, linewidth=2)
Advertisement
Comments
Add Comment
Please, Sign In to add comment