Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator(title='Sine Wave with Fear and Greed Indicators', overlay=false)
- // Input parameters for sine waves and MA
- base_wave_height = input(100, title='Base Wave Height')
- base_wave_frequency = input(1, title='Base Wave Frequency (Cycles)')
- harmonic_height = input(30, title='Harmonic Wave Height')
- harmonic_frequency = input(2, title='Harmonic Frequency (Cycles)')
- ma_length = input(10, title='MA Length for Ribbon')
- // Function to generate sine wave
- f_sine_wave(height, frequency) =>
- freq = 2 * math.pi * frequency
- height * math.sin(freq * (bar_index / 100)) // Control frequency scaling over time
- // Main sine wave
- main_wave = f_sine_wave(base_wave_height, base_wave_frequency)
- // Inner harmonic sine waves (representing fear and greed)
- inner_harmonic1 = f_sine_wave(harmonic_height, harmonic_frequency)
- inner_harmonic2 = f_sine_wave(harmonic_height * 0.5, harmonic_frequency * 1.5) // More subtle harmonic
- // Create an MA ribbon based on the main wave and harmonics
- ma_ribbon = ta.sma(main_wave + inner_harmonic1 + inner_harmonic2, ma_length)
- // Plotting the waves and the MA ribbon
- plot(main_wave, title='Main Sine Wave', color=color.blue)
- plot(inner_harmonic1, title='First Harmonic Wave (Greed)', color=color.green)
- plot(inner_harmonic2, title='Second Harmonic Wave (Fear)', color=color.red)
- plot(ma_ribbon, title='MA Ribbon', color=color.orange, linewidth=2)
- // Highlight areas of fear and greed
- bgcolor(inner_harmonic1 > main_wave ? color.new(color.green, 90) : na, title='Greed Area')
- bgcolor(inner_harmonic2 < main_wave ? color.new(color.red, 90) : na, title='Fear Area')
- // Alerts for significant wave conditions
- greed_condition = ta.crossover(inner_harmonic1, main_wave) // Corrected usage for crossover
- fear_condition = ta.crossunder(inner_harmonic2, main_wave) // Corrected usage for crossunder
- alertcondition(greed_condition, title='Greed Alert', message='Degree of Greed Detected!')
- alertcondition(fear_condition, title='Fear Alert', message='Degree of Fear Detected!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement