xmd79

Waves Decomposition

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