xmd79

Waves Decomposition momentum

May 18th, 2023
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. //@version=5
  2. indicator("Waves Decomposition", overlay=false)
  3.  
  4. wave_height = input.int(100, "Wave Height")
  5. wave_duration = input.int(316, "Wave Duration")
  6. wave_duration_bigwave = input.int(420, "Big Wave Duration")
  7.  
  8. n = bar_index
  9.  
  10. inp = input(close)
  11. f_cosine_wave(_wave_height, _wave_duration, _n) =>
  12. _pi = 3.14159265359
  13. _w = 2 * _pi / _wave_duration
  14. _cosine_wave = _wave_height * math.sin(_w * _n + _pi / 2)
  15. _cosine_wave
  16.  
  17. f_cosine_wave2(_wave_height, _wave_duration_bigwave, _n) =>
  18. _pi = 3.14159265359
  19. _w2 = 2 * _pi / _wave_duration_bigwave
  20. _cosine_wave2 = _wave_height * math.sin(_w2 * _n + _pi / 2)
  21. _cosine_wave2
  22.  
  23. wave = f_cosine_wave(wave_height, wave_duration, n)
  24. big_wave = f_cosine_wave2(wave_height, wave_duration_bigwave, n)
  25.  
  26. wave_smoothed = ta.sma(wave, 20) // Apply moving average
  27. big_wave_smoothed = ta.sma(big_wave, 50) // Apply moving average
  28.  
  29. in_phase = (wave_smoothed + big_wave_smoothed) / 2
  30. quadrature = (wave_smoothed - big_wave_smoothed) / 2
  31.  
  32. plot(series=in_phase, title='In-Phase', color=color.new(#FFFFFF, 0))
  33. plot(series=quadrature, title='Quadrature', color=color.new(#FFFFFF, 0))
  34.  
  35. // study(title="[RS]Compounded Risk Score", shorttitle="CRS")
  36. // if you took a trade for every bars close for the duration of the length
  37. // how would those trades fair atm?
  38. // values closer to (100 | -100) are better for its (bull | bear), closer to 0 will be closer to break eaven.
  39. // this indicator is optimal for trending markets.
  40.  
  41. length = input.int(100, "Length")
  42. avg_length = input.int(25, "Average Length")
  43.  
  44. f_compound_risk(_source, _length) =>
  45. _total = 0.0
  46. _absolute = 0.0
  47. for _i = 1 to _length by 1
  48. _container0 = _total
  49. _container1 = _absolute
  50. _total := _container0 + _source[0] - _source[_i]
  51. _absolute := _container1 + math.abs(_source[0] - _source[_i])
  52. if _total > 0
  53. _container = _total
  54. _total := _total / _absolute
  55. _total
  56. else
  57. _container = _total
  58. _total := 0 - math.abs(_container) / _absolute
  59. _total
  60.  
  61. cr = f_compound_risk(in_phase, length)
  62. ma = ta.ema(cr, avg_length)
  63.  
  64. plot(series=cr, color=color.new(color.black, 0))
  65. plot(series=ma, color=color.new(color.navy, 0))
  66. hline(100)
  67. hline(50)
  68. hline(0)
  69. hline(-50)
  70. hline(-100)
Advertisement
Add Comment
Please, Sign In to add comment