Advertisement
xmd79

Compound Sine Waves for Market Reversals

Oct 31st, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. //@version=5
  2. indicator(title='Compound Sine Waves for Market Reversals', precision=12)
  3.  
  4. // Input parameters for sine waves
  5. base_wave_height = input(100, title='Base Wave Height')
  6. base_wave_duration = input(161, title='Base Wave Duration')
  7. harmonic_wave_height = input(50, title='Harmonic Wave Height')
  8. harmonic_wave_duration = input(54, title='Harmonic Wave Duration')
  9. extra_harmonic_wave_height = input(25, title='Extra Harmonic Height')
  10. extra_harmonic_wave_duration = input(27, title='Extra Harmonic Duration')
  11.  
  12. n = bar_index
  13.  
  14. // Function to generate sine waves
  15. f_sine_wave(_wave_height, _wave_duration) =>
  16. _pi = 3.14159265359
  17. _w = 2 * _pi / _wave_duration
  18. _sine_wave = _wave_height * math.sin(_w * n)
  19. _sine_wave
  20.  
  21. // Calculate sine waves
  22. base_sine_wave = f_sine_wave(base_wave_height, base_wave_duration)
  23. harmonic_sine_wave = f_sine_wave(harmonic_wave_height, harmonic_wave_duration)
  24. extra_harmonic_sine_wave = f_sine_wave(extra_harmonic_wave_height, extra_harmonic_wave_duration)
  25.  
  26. // Combined sine wave
  27. compound_sine_wave = base_sine_wave + harmonic_sine_wave + extra_harmonic_sine_wave
  28.  
  29. // Detect crossover and crossunder for potential reversal points
  30. min_trigger = ta.crossover(base_sine_wave, compound_sine_wave)
  31. max_trigger = ta.crossunder(base_sine_wave, compound_sine_wave)
  32.  
  33. // Plotting the sine waves and triggers
  34. plot(series=base_sine_wave, title='Base Sine Wave', color=color.green)
  35. plot(series=harmonic_sine_wave, title='Harmonic Sine Wave', color=color.red)
  36. plot(series=extra_harmonic_sine_wave, title='Extra Harmonic Wave', color=color.blue)
  37. plot(series=compound_sine_wave, title='Compound Sine Wave', color=color.purple)
  38.  
  39. // Plotting the reversal signals
  40. plotshape(series=min_trigger, title='Min Trigger', style=shape.triangledown, location=location.absolute, color=color.black, size=size.small)
  41. plotshape(series=max_trigger, title='Max Trigger', style=shape.triangleup, location=location.absolute, color=color.white, size=size.small)
  42.  
  43. // Displaying market sentiment based on the sine wave pattern
  44. bgcolor(close > compound_sine_wave ? color.new(color.green, 90) : na)
  45. bgcolor(close < compound_sine_wave ? color.new(color.red, 90) : na)
  46.  
  47. // Alert conditions for potential reversals
  48. alertcondition(min_trigger, title='Min Trigger Alert', message='Potential Market Bottom Detected!')
  49. alertcondition(max_trigger, title='Max Trigger Alert', message='Potential Market Top Detected!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement