Advertisement
xmd79

stationary time series decomposition pine source

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