Advertisement
xmd79

Sine Wave with Fear and Greed Indicators

Oct 31st, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. //@version=5
  2. indicator(title='Sine Wave with Fear and Greed Indicators', overlay=false)
  3.  
  4. // Input parameters for sine waves and MA
  5. base_wave_height = input(100, title='Base Wave Height')
  6. base_wave_frequency = input(1, title='Base Wave Frequency (Cycles)')
  7. harmonic_height = input(30, title='Harmonic Wave Height')
  8. harmonic_frequency = input(2, title='Harmonic Frequency (Cycles)')
  9. ma_length = input(10, title='MA Length for Ribbon')
  10.  
  11. // Function to generate sine wave
  12. f_sine_wave(height, frequency) =>
  13. freq = 2 * math.pi * frequency
  14. height * math.sin(freq * (bar_index / 100)) // Control frequency scaling over time
  15.  
  16. // Main sine wave
  17. main_wave = f_sine_wave(base_wave_height, base_wave_frequency)
  18.  
  19. // Inner harmonic sine waves (representing fear and greed)
  20. inner_harmonic1 = f_sine_wave(harmonic_height, harmonic_frequency)
  21. inner_harmonic2 = f_sine_wave(harmonic_height * 0.5, harmonic_frequency * 1.5) // More subtle harmonic
  22.  
  23. // Create an MA ribbon based on the main wave and harmonics
  24. ma_ribbon = ta.sma(main_wave + inner_harmonic1 + inner_harmonic2, ma_length)
  25.  
  26. // Plotting the waves and the MA ribbon
  27. plot(main_wave, title='Main Sine Wave', color=color.blue)
  28. plot(inner_harmonic1, title='First Harmonic Wave (Greed)', color=color.green)
  29. plot(inner_harmonic2, title='Second Harmonic Wave (Fear)', color=color.red)
  30. plot(ma_ribbon, title='MA Ribbon', color=color.orange, linewidth=2)
  31.  
  32. // Highlight areas of fear and greed
  33. bgcolor(inner_harmonic1 > main_wave ? color.new(color.green, 90) : na, title='Greed Area')
  34. bgcolor(inner_harmonic2 < main_wave ? color.new(color.red, 90) : na, title='Fear Area')
  35.  
  36. // Alerts for significant wave conditions
  37. greed_condition = ta.crossover(inner_harmonic1, main_wave) // Corrected usage for crossover
  38. fear_condition = ta.crossunder(inner_harmonic2, main_wave) // Corrected usage for crossunder
  39. alertcondition(greed_condition, title='Greed Alert', message='Degree of Greed Detected!')
  40. alertcondition(fear_condition, title='Fear Alert', message='Degree of Fear Detected!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement