xmd79

Waves Decomposition with volume

May 5th, 2023
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. //@version=5
  2. indicator("Waves Decomposition", overlay=false)
  3.  
  4. wave_height = input(100)
  5. wave_duration = input(162)
  6. wave_duration_bigwave = input(216)
  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(100)
  38. avg_length = input(25)
  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.  
  68. //end of this part
  69.  
  70. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  71. // © bit_ai_zine
  72.  
  73.  
  74. //@version=5
  75. //indicator(title="[Bit_Ai_zone]RSI columns", shorttitle="[Bit_Ai_zone]RSI columns", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
  76.  
  77. ma(source, length, type) =>
  78. switch type
  79. "SMA" => ta.sma(source, length)
  80. "Bollinger Bands" => ta.sma(source, length)
  81. "EMA" => ta.ema(source, length)
  82. "SMMA (RMA)" => ta.rma(source, length)
  83. "WMA" => ta.wma(source, length)
  84. "VWMA" => ta.vwma(source, length)
  85.  
  86. rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings") //
  87. rsiSourceInput = input.source(close, "Source", group="RSI Settings")
  88. maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
  89. maLengthInput = input.int(5, title="MA Length", group="MA Settings")
  90.  
  91. up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
  92. down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
  93. rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
  94. rsiMA = ma(rsi, maLengthInput, maTypeInput)
  95.  
  96. rsicolor = color.rgb(214, 212, 212)
  97.  
  98. if rsi < 30
  99. rsicolor := color.red
  100. if rsi > 70
  101. rsicolor := color.green
  102. if rsi < 20
  103. rsicolor := color.black
  104.  
  105. plot(rsi, "RSI", color=rsicolor , style = plot.style_columns)
  106. plot(rsiMA, "RSI-based MA", color=color.black)
  107.  
  108.  
  109.  
  110.  
Advertisement
Add Comment
Please, Sign In to add comment