xmd79

Function Sine Wave

Mar 13th, 2023
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. //@version=4
  2. study(title='Function Sine Wave')
  3. wave_height = input(100)
  4. wave_duration = input(50)
  5.  
  6. f_sine_wave_1(_wave_height, _wave_duration) =>
  7. _pi = 3.14159265359
  8. _w = 2 * _pi / _wave_duration
  9. _sine_wave = _wave_height * sin(_w * bar_index)
  10. _sine_wave
  11. f_sine_wave_2(_wave_height, _wave_duration) =>
  12. _pi = 3.14159265359
  13. _w = 2 * _pi / _wave_duration
  14. _sine_wave = _wave_height * sin(_w * bar_index)
  15. _sine_wave
  16.  
  17. wave = f_sine_wave_1(wave_height, wave_duration)
  18. wave2 = f_sine_wave_2(wave_height, close)
  19. plot(series=wave, title='Normal', color=color.black)
  20. plot(series=wave2, title='Price as cycle duration', color=color.red)
  21. //end of this part
  22.  
  23. length = input(50)
  24. src = wave
  25. //----
  26. sum=0.,sumw=0.
  27. for i = 1 to length
  28. w = sin(2*3.14*i/length)/i
  29. sumw := sumw + w
  30. sum := sum + w*src[i-1]
  31. //----
  32. plot(sum/sumw,"Plot",#ff1100,2,transp=0)
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment