xmd79

Function Cosine Wave with Reversal Key Points pine

Dec 30th, 2023
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. //@version=5
  2. indicator(title='Function Cosine Wave with Reversal Key Points', precision=12)
  3.  
  4. wave_height = input(100)
  5. wave_duration = input(161)
  6. wave_duration_bigwave = input(217)
  7. reversal = input(5)
  8.  
  9. n = bar_index
  10.  
  11. f_cosine_wave(_wave_height, _wave_duration, _reversal) =>
  12. _pi = 3.14159265359
  13. _w = 2 * _pi / _wave_duration
  14. _cosine_wave = _wave_height * math.sin(_w * n + _pi / 2)
  15. _reversal_point = _wave_height * math.sin(_w * n + _pi / 2 + _pi)
  16. _is_reversal = (n % _reversal == 0)
  17. _cosine_wave := _is_reversal ? _reversal_point : _cosine_wave
  18. _cosine_wave
  19.  
  20. f_cosine_wave2(_wave_height, _wave_duration_bigwave, _reversal) =>
  21. _pi = 3.14159265359
  22. _w2 = 2 * _pi / _wave_duration_bigwave
  23. _cosine_wave2 = _wave_height * math.sin(_w2 * n + _pi / 2)
  24. _reversal_point2 = _wave_height * math.sin(_w2 * n + _pi / 2 + _pi)
  25. _is_reversal2 = (n % _reversal == 0)
  26. _cosine_wave2 := _is_reversal2 ? _reversal_point2 : _cosine_wave2
  27. _cosine_wave2
  28.  
  29. wave = f_cosine_wave(wave_height, wave_duration, reversal)
  30. big_wave = f_cosine_wave2(wave_height, wave_duration_bigwave, reversal)
  31.  
  32. plot(series=wave, title='Normal', color=color.new(#FFFFFF, 0))
  33. plot(series=big_wave, title='Normal', color=color.new(#FFFFFF, 0))
  34.  
  35. length = input(100)
  36. avg_length = input(25)
  37.  
  38. f_compound_risk(_source, _length) =>
  39. _total = 0.0
  40. _absolute = 0.0
  41. for _i = 1 to _length by 1
  42. _container0 = _total
  43. _container1 = _absolute
  44. _total := _container0 + _source[0] - _source[_i]
  45. _absolute := _container1 + math.abs(_source[0] - _source[_i])
  46. _absolute
  47. if _total > 0
  48. _container = _total
  49. _total := _total / _absolute
  50. _total
  51. else
  52. _container = _total
  53. _total := 0 - math.abs(_container) / _absolute
  54. _total
  55. _total * 100
  56.  
  57. cr = f_compound_risk(wave, 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.  
Add Comment
Please, Sign In to add comment