xmd79

cosine wave modified

Mar 14th, 2023
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © DarkPoolTrading
  3. // Based on the Function Sine Wave Indicator by RicardoSantos
  4.  
  5. //@version=5
  6. indicator(title='Function Cosine Wave', precision=12)
  7.  
  8. // Inputs
  9. wave_height = input.float(100, "Wave Height")
  10. wave_duration = input.float(161, "Wave Duration")
  11. wave_duration_bigwave = input.float(217, "Big Wave Duration")
  12.  
  13. n = bar_index
  14.  
  15. f_cosine_wave(_wave_height, _wave_duration) =>
  16. _pi = 3.14159265359
  17. _w = 2 * _pi / _wave_duration
  18. _cosine_wave = _wave_height * math.sin(_w * n + _pi / 2)
  19. _cosine_wave
  20.  
  21. f_cosine_wave2(_wave_height, _wave_duration_bigwave) =>
  22. _pi = 3.14159265359
  23. _w2 = 2 * _pi / _wave_duration_bigwave
  24. _cosine_wave2 = _wave_height * math.sin(_w2 * n + _pi / 2)
  25. _cosine_wave2
  26.  
  27. wave = f_cosine_wave(wave_height, wave_duration)
  28. //wave2 = f_cosine_wave(wave_height, close)
  29. big_wave = f_cosine_wave2(wave_height, wave_duration_bigwave)
  30.  
  31. oscillator = wave - big_wave // Stationary oscillator
  32.  
  33. plot(series=oscillator, title='Stationary Oscillator', color=color.blue, linewidth=2)
  34. hline(0, title="Zero line", color=color.gray, linestyle=hline.style_dotted)
  35.  
  36. //end of this part
  37.  
  38. //study(title="[RS]Compounded Risk Score", shorttitle="CRS")
  39. // if you took a trade for every bars close for the duration of the length
  40. // how would those trades fair atm?
  41. // values closer to (100 | -100) are better for its (bull | bear), closer to 0 will be closer to break eaven.
  42. // this indicator is optimal for trending markets.
  43.  
  44. length = input(100)
  45. avg_length = input(25)
  46.  
  47. f_compound_risk(_source, _length) =>
  48. _total = 0.0
  49. _absolute = 0.0
  50. for _i = 1 to _length by 1
  51. _container0 = _total
  52. _container1 = _absolute
  53. _total := _container0 + _source[0] - _source[_i]
  54. _absolute := _container1 + math.abs(_source[0] - _source[_i])
  55. _absolute
  56. if _total > 0
  57. _container = _total
  58. _total := _total / _absolute
  59. _total
  60. else
  61. _container = _total
  62. _total := 0 - math.abs(_container) / _absolute
  63. _total
  64. _total * 100
  65.  
  66. //inp = input(close)
  67.  
  68. cr = f_compound_risk(oscillator, length)
  69. ma = ta.ema(cr, avg_length)
  70.  
  71. plot(series=cr, color=color.new(color.black, 0))
  72. plot(series=ma, color=color.new(color.navy, 0))
  73. hline(100)
  74. hline(50)
  75. hline(0)
  76. hline(-50)
  77. hline(-100)
  78.  
  79. //end of this part
  80.  
Advertisement
Add Comment
Please, Sign In to add comment