xmd79

my custom stationary waves cycles

Jan 12th, 2023
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 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(161)
  12. wave_duration_bigwave = input(217)
  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. //end of this part
  41.  
  42.  
  43. //study(title="[RS]Compounded Risk Score", shorttitle="CRS")
  44. // if you took a trade for every bars close for the duration of the length
  45. // how would those trades fair atm?
  46. // values closer to (100 | -100) are better for its (bull | bear), closer to 0 will be closer to break eaven.
  47. // this indicator is optimal for trending markets.
  48.  
  49. length = input(100)
  50. avg_length = input(25)
  51.  
  52. f_compound_risk(_source, _length) =>
  53. _total = 0.0
  54. _absolute = 0.0
  55. for _i = 1 to _length by 1
  56. _container0 = _total
  57. _container1 = _absolute
  58. _total := _container0 + _source[0] - _source[_i]
  59. _absolute := _container1 + math.abs(_source[0] - _source[_i])
  60. _absolute
  61. if _total > 0
  62. _container = _total
  63. _total := _total / _absolute
  64. _total
  65. else
  66. _container = _total
  67. _total := 0 - math.abs(_container) / _absolute
  68. _total
  69. _total * 100
  70.  
  71. //inp = input(close)
  72.  
  73. cr = f_compound_risk(wave, length)
  74. ma = ta.ema(cr, avg_length)
  75.  
  76. plot(series=cr, color=color.new(color.black, 0))
  77. plot(series=ma, color=color.new(color.navy, 0))
  78. hline(100)
  79. hline(50)
  80. hline(0)
  81. hline(-50)
  82. hline(-100)
  83.  
  84. //end of this part
  85.  
  86. // Define amplitude, frequency, and phase
  87. pi = 3.14159
  88. amplitude = 50
  89. frequency = 2 * pi / 20
  90. phase = 0
  91.  
  92. inp = ma
  93. // Generate sine wave
  94. sine_wave = amplitude * math.sin(frequency * inp + phase)
  95. // Plot sine wave on price chart
  96. plot(sine_wave, color=color.new(color.red, 0), linewidth=2)
Advertisement
Add Comment
Please, Sign In to add comment