xmd79

SAR Oscillator [LUX]

Aug 26th, 2022
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
  2. // © LuxAlgo
  3.  
  4. //@version=5
  5. indicator("SAR Oscillator [LUX]")
  6. //------------------------------------------------------------------------------
  7. //Settings
  8. //-----------------------------------------------------------------------------{
  9. acc = input.float(0.01, 'Acceleration'
  10. , minval = 0
  11. , maxval = 1
  12. , step = .01)
  13.  
  14. inc = input.float(0.02, 'Increment'
  15. , minval = 0
  16. , maxval = 1
  17. , step = .01)
  18.  
  19. lim = input.float(0.20, 'Maximum'
  20. , minval = 0
  21. , maxval = 1
  22. , step = .1)
  23.  
  24. //Style
  25. np_css = input.color(#2157f3, 'Normalized Price'
  26. , group = 'Colors')
  27.  
  28. sp_css = input.color(#ffe400, 'Normalized SAR'
  29. , group = 'Colors')
  30.  
  31. fill_css_0 = input.color(color.new(#FF0000, 0), 'Fill Gradient'
  32. , inline = 'inline0'
  33. , group = 'Colors')
  34.  
  35. fill_css_1 = input.color(color.new(#FFFF00, 80), ''
  36. , inline = 'inline0'
  37. , group = 'Colors')
  38.  
  39. fill_css_2 = input.color(color.new(#39FF14, 0), ''
  40. , inline = 'inline0'
  41. , group = 'Colors')
  42.  
  43. //-----------------------------------------------------------------------------}
  44. //Calculation
  45. //-----------------------------------------------------------------------------{
  46. var max = 0.
  47. var min = 0.
  48.  
  49. inp = input(close)
  50.  
  51. sar = ta.sar(acc, inc, lim)
  52. cross = ta.cross(inp, sar)
  53.  
  54. max := cross ? math.max(high, sar) : math.max(high, max)
  55. min := cross ? math.min(low, sar) : math.min(low, min)
  56.  
  57. posc = ((inp - sar) / (max - min) * 100)*-1
  58. sosc = (((sar - min) / (max - min) - .5) * -200)*-1
  59.  
  60. //-----------------------------------------------------------------------------}
  61. //Plot
  62. //-----------------------------------------------------------------------------{
  63. gradient_0 = color.from_gradient(sosc, -100, 0, fill_css_0, fill_css_1)
  64. gradient_1 = color.from_gradient(sosc, 0, 100, gradient_0, fill_css_2)
  65.  
  66. plot_0 = plot(posc, 'Normalized Price'
  67. , color = np_css)
  68.  
  69. plot_1 = plot(sosc, 'Normalized SAR'
  70. , color = sp_css)
  71.  
  72. plot(cross ? sosc : na, 'SAR Dots'
  73. , color = sosc == -100 ? fill_css_2 : fill_css_0
  74. , style = plot.style_circles
  75. , linewidth = 4)
  76.  
  77. fill(plot_0, plot_1, gradient_1)
  78.  
  79. hline(50)
  80. hline(-50)
Advertisement
Add Comment
Please, Sign In to add comment