Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator(title='Function Cosine Wave with Reversal Key Points', precision=12)
- wave_height = input(100)
- wave_duration = input(161)
- wave_duration_bigwave = input(217)
- reversal = input(5)
- n = bar_index
- f_cosine_wave(_wave_height, _wave_duration, _reversal) =>
- _pi = 3.14159265359
- _w = 2 * _pi / _wave_duration
- _cosine_wave = _wave_height * math.sin(_w * n + _pi / 2)
- _reversal_point = _wave_height * math.sin(_w * n + _pi / 2 + _pi)
- _is_reversal = (n % _reversal == 0)
- _cosine_wave := _is_reversal ? _reversal_point : _cosine_wave
- _cosine_wave
- f_cosine_wave2(_wave_height, _wave_duration_bigwave, _reversal) =>
- _pi = 3.14159265359
- _w2 = 2 * _pi / _wave_duration_bigwave
- _cosine_wave2 = _wave_height * math.sin(_w2 * n + _pi / 2)
- _reversal_point2 = _wave_height * math.sin(_w2 * n + _pi / 2 + _pi)
- _is_reversal2 = (n % _reversal == 0)
- _cosine_wave2 := _is_reversal2 ? _reversal_point2 : _cosine_wave2
- _cosine_wave2
- wave = f_cosine_wave(wave_height, wave_duration, reversal)
- big_wave = f_cosine_wave2(wave_height, wave_duration_bigwave, reversal)
- plot(series=wave, title='Normal', color=color.new(#FFFFFF, 0))
- plot(series=big_wave, title='Normal', color=color.new(#FFFFFF, 0))
- length = input(100)
- avg_length = input(25)
- 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])
- _absolute
- if _total > 0
- _container = _total
- _total := _total / _absolute
- _total
- else
- _container = _total
- _total := 0 - math.abs(_container) / _absolute
- _total
- _total * 100
- cr = f_compound_risk(wave, 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)
Add Comment
Please, Sign In to add comment