namile

Squeeze Momentum Indicator [LazyBear]

Feb 21st, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // @author LazyBear
  3. // List of all my indicators: https://www.tradingview.com/v/4IneGo8h/
  4. // https://www.tradingview.com/script/nqQ1DT5a-Squeeze-Momentum-Indicator-LazyBear/
  5. study(shorttitle = "SQZMOM_LB", title="Squeeze Momentum Indicator [LazyBear]", overlay=false)
  6.  
  7. length = input(20, title="BB Length")
  8. mult = input(2.0,title="BB MultFactor")
  9. lengthKC=input(20, title="KC Length")
  10. multKC = input(1.5, title="KC MultFactor")
  11.  
  12. useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)
  13.  
  14. // Calculate BB
  15. source = close
  16. basis = sma(source, length)
  17. dev = multKC * stdev(source, length)
  18. upperBB = basis + dev
  19. lowerBB = basis - dev
  20.  
  21. // Calculate KC
  22. ma = sma(source, lengthKC)
  23. range = useTrueRange ? tr : (high - low)
  24. rangema = sma(range, lengthKC)
  25. upperKC = ma + rangema * multKC
  26. lowerKC = ma - rangema * multKC
  27.  
  28. sqzOn  = (lowerBB > lowerKC) and (upperBB < upperKC)
  29. sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
  30. noSqz  = (sqzOn == false) and (sqzOff == false)
  31.  
  32. val = linreg(source  -  avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)),
  33.             lengthKC,0)
  34.  
  35. bcolor = iff( val > 0,
  36.             iff( val > nz(val[1]), lime, green),
  37.             iff( val < nz(val[1]), red, maroon))
  38. scolor = noSqz ? blue : sqzOn ? black : gray
  39. plot(val, color=bcolor, style=histogram, linewidth=4)
  40. plot(0, color=scolor, style=cross, linewidth=2)
Add Comment
Please, Sign In to add comment