Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator("Waves Decomposition", overlay=false)
- wave_height = input.int(100, "Wave Height")
- wave_duration = input.int(316, "Wave Duration")
- wave_duration_bigwave = input.int(420, "Big Wave Duration")
- n = bar_index
- inp = input(close)
- f_cosine_wave(_wave_height, _wave_duration, _n) =>
- _pi = 3.14159265359
- _w = 2 * _pi / _wave_duration
- _cosine_wave = _wave_height * math.sin(_w * _n + _pi / 2)
- _cosine_wave
- f_cosine_wave2(_wave_height, _wave_duration_bigwave, _n) =>
- _pi = 3.14159265359
- _w2 = 2 * _pi / _wave_duration_bigwave
- _cosine_wave2 = _wave_height * math.sin(_w2 * _n + _pi / 2)
- _cosine_wave2
- wave = f_cosine_wave(wave_height, wave_duration, n)
- big_wave = f_cosine_wave2(wave_height, wave_duration_bigwave, n)
- wave_smoothed = ta.sma(wave, 20) // Apply moving average
- big_wave_smoothed = ta.sma(big_wave, 50) // Apply moving average
- in_phase = (wave_smoothed + big_wave_smoothed) / 2
- quadrature = (wave_smoothed - big_wave_smoothed) / 2
- plot(series=in_phase, title='In-Phase', color=color.new(#FFFFFF, 0))
- plot(series=quadrature, title='Quadrature', color=color.new(#FFFFFF, 0))
- // study(title="[RS]Compounded Risk Score", shorttitle="CRS")
- // if you took a trade for every bars close for the duration of the length
- // how would those trades fair atm?
- // values closer to (100 | -100) are better for its (bull | bear), closer to 0 will be closer to break eaven.
- // this indicator is optimal for trending markets.
- length = input.int(100, "Length")
- avg_length = input.int(25, "Average Length")
- f_compound_risk(_source, _length) =>
- _total = 0.0
- _absolute = 0.0
- for _i = 1 to _length by 1
- _container0 = _total
- _container1 = _absolute
- _total := _container0 + _source[0] - _source[_i]
- _absolute := _container1 + math.abs(_source[0] - _source[_i])
- if _total > 0
- _container = _total
- _total := _total / _absolute
- _total
- else
- _container = _total
- _total := 0 - math.abs(_container) / _absolute
- _total
- cr = f_compound_risk(in_phase, length)
- ma = ta.ema(cr, avg_length)
- plot(series=cr, color=color.new(color.black, 0))
- plot(series=ma, color=color.new(color.navy, 0))
- hline(100)
- hline(50)
- hline(0)
- hline(-50)
- hline(-100)
Advertisement
Add Comment
Please, Sign In to add comment