Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © peacefulLizard50262
- //@version=5
- indicator("Epanechnikov algo fct")
- import lastguru/DominantCycle/2 as d
- sine_wave(_wave_height, _wave_duration, _phase_shift, _phase_shift_2) =>
- _pi = math.pi
- _w = 2 * _pi / _wave_duration
- _sine_wave = _wave_height * math.sin(_w * bar_index + _phase_shift + _phase_shift_2)
- _sine_wave
- // Epanechnikov kernel function
- epanechnikov_kernel(_src, _size, _h, _r) =>
- _currentWeight = 0.0
- _cumulativeWeight = 0.0
- for i = 0 to _size
- y = _src[i]
- u = math.pow(i, 2) / (math.pow(_h, 2) * _r)
- w = (u >= 1) ? 0 : (3. / 4) * (1 - math.pow(u, 2))
- _currentWeight := _currentWeight + y * w
- _cumulativeWeight := _cumulativeWeight + w
- _currentWeight / _cumulativeWeight
- phase = input.float(-45, "Phase") * math.pi/180
- // Estimations
- epk = epanechnikov_kernel(close, 50, 2, 1)
- source = epk - ta.sma(epk, 9)
- cycle = math.round(d.mamaPeriod(source, 1, 2048))
- var cycles = array.new<float>(1)
- var count_cycles = array.new<int>(1)
- if not array.includes(cycles, cycle)
- array.push(cycles, cycle)
- array.push(count_cycles, 1)
- else
- index = array.indexof(cycles, cycle)
- array.set(count_cycles, index, array.get(count_cycles, index) + 1)
- max_index = array.indexof(count_cycles, array.max(count_cycles))
- max_cycle = array.get(cycles, max_index)
- sine = sine_wave(ta.max(math.abs(source)), max_cycle, phase, 0)
- plot(source)
- plot(sine, color = color.orange)
Advertisement
Add Comment
Please, Sign In to add comment