xmd79

function cosine wave osc

Jun 1st, 2024
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 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.  
  9.  
  10. wave_height = input(100)
  11. wave_duration = input(456)
  12. wave_duration_bigwave = input(678)
  13.  
  14. n = bar_index
  15.  
  16. f_cosine_wave(_wave_height, _wave_duration) =>
  17. _pi = 3.14159265359
  18. _w = 2 * _pi / _wave_duration
  19. _cosine_wave = _wave_height * math.sin(_w * n + _pi / 2)
  20. _cosine_wave
  21.  
  22. f_cosine_wave2(_wave_height, _wave_duration_bigwave) =>
  23. _pi = 3.14159265359
  24. _w2 = 2 * _pi / _wave_duration_bigwave
  25. _cosine_wave2 = _wave_height * math.sin(_w2 * n + _pi / 2)
  26. _cosine_wave2
  27.  
  28. wave = f_cosine_wave(wave_height, wave_duration)
  29. //wave2 = f_cosine_wave(wave_height, close)
  30. big_wave = f_cosine_wave2(wave_height, wave_duration_bigwave)
  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. //plot(series=wave2, title='Price as cycle duration', color=#C9A0DC)
  36.  
  37. //end of this part
  38.  
  39.  
  40. //study(title="[RS]Compounded Risk Score", shorttitle="CRS")
  41. // if you took a trade for every bars close for the duration of the length
  42. // how would those trades fair atm?
  43. // values closer to (100 | -100) are better for its (bull | bear), closer to 0 will be closer to break eaven.
  44. // this indicator is optimal for trending markets.
  45.  
  46. length = input(100)
  47. avg_length = input(25)
  48.  
  49. f_compound_risk(_source, _length) =>
  50. _total = 0.0
  51. _absolute = 0.0
  52. for _i = 1 to _length by 1
  53. _container0 = _total
  54. _container1 = _absolute
  55. _total := _container0 + _source[0] - _source[_i]
  56. _absolute := _container1 + math.abs(_source[0] - _source[_i])
  57. _absolute
  58. if _total > 0
  59. _container = _total
  60. _total := _total / _absolute
  61. _total
  62. else
  63. _container = _total
  64. _total := 0 - math.abs(_container) / _absolute
  65. _total
  66. _total * 100
  67.  
  68. //inp = input(close)
  69.  
  70. cr = f_compound_risk(wave, length)
  71. ma = ta.ema(cr, avg_length)
  72.  
  73. plot(series=cr, color=color.new(color.black, 0))
  74. plot(series=ma, color=color.new(color.navy, 0))
  75. hline(100)
  76. hline(50)
  77. hline(0)
  78. hline(-50)
  79. hline(-100)
  80.  
  81. //end of this part
  82.  
  83.  
Add Comment
Please, Sign In to add comment