 # [LAVA] Ultimate Nonlinear Oscillator

a guest
Nov 2nd, 2014
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. study(title="[LAVA] Ultimate Nonlinear Oscillator", shorttitle="UNO_L", overlay=true)
2.
3. length7 = input(7, minval=1, title="Fast"), length14 = input(14, minval=1, title="Slow"), length28 = input(28, minval=1, title="Long")
4. mult = input(2.5, type=float, minval=0.001, maxval=50, title="BB Multiplier")
5. sense = input(100, minval=0.0001, maxval=200, title="Sensitivity")
6. show = input(false, type=bool, title="Show EMA?")
7. source = hl2
8.
9. average(bp, tr_, length) => sum(bp, length) / sum(tr_, length)
10.
11. true_hi = highest(close, length14), true_lo = lowest(close, length14)
12. uppers = lowest(high, length14), lowers = highest(low, length14)
13. high_ = max(high, close), low_ = min(low, close)
14. bp = close - low_, tr_ = high_ - low_, tp_ = uppers - lowers
15. avg7 = average(bp, tr_, length7), avg14 = average(bp, tr_, length14), avg28 = average(bp, tr_, length28)
16.
17. bbd = 4 * stdev(source, length7*3) / sma(source, length7*3)
18. bbi = lowest(sma(bbd,4),42)>=bbd and bbd<bbd
19.
20. out = sense * (4*avg7 + 2*avg14 + avg28)/7
21. upper = uppers-out*(tp_*.015)
22. lower = lowers+out*(tp_*.015)
23. svgs = ema((upper+lower)/2, length7*3)
24. show_svgs = show ? svgs : na
25. vol = sma(volume, length7*3)
26. a_svgs = (bbi or (svgs > high and vol>vol)) and high < upper and barssince(high>=svgs)<length7 ? true : false
27. b_svgs = (bbi or (svgs < low and vol>vol)) and low > lower and barssince(low<=svgs)<length7 ? true : false
28. a_line = barssince(a_svgs)<14 and (vol>vol or bbi) and true_hi==true_hi ? true_hi : na
29. b_line = barssince(b_svgs)<14 and (vol>vol or bbi) and true_lo==true_lo ? true_lo : na
30.
31. p5 = plot(a_line, color=red, title="DOS TOP", linewidth=2, style=circles)
32. p3 = plot(upper, color=red, title="UNO TOP", linewidth=1)
33. p1 = plot(show_svgs, color=white, title="UNO SLOW", linewidth=1)
34. p4 = plot(lower, color=lime, title="UNO BOT", linewidth=1)
35. p6 = plot(b_line, color=lime, title="DOS BOT", linewidth=2, style=circles)