OPEN-SOURCE SCRIPT

Wave Modulation Demo

347
█ OVERVIEW

This script demonstrates Stacked Wave Modulation by visualizing four interconnected waves. Wave 1 is the base wave, influencing Wave 2's frequency, which in turn modulates Wave 3's amplitude, and finally, Wave 3 modulates Wave 4's phase. Explore the fascinating effects of wave modulation by adjusting the inputs for each wave and their modulation scales.

══════════════════════════════════════════════════

█ CONCEPTS

This script visualizes a cascade of wave modulations:

1 — Base Wave (Wave 1): This is the foundational wave. Its parameters (type, frequency, amplitude, phase, vertical shift) are directly controlled and serve as the basis for subsequent modulations.

2 — Frequency Modulation (Wave 2): Wave 2's frequency is modulated by Wave 1. As Wave 1 oscillates, it dynamically changes the frequency of Wave 2, creating interesting frequency variations. The Frequency Mod Scale input controls the intensity of this modulation.

3 — Amplitude Modulation (Wave 3): Building upon the cascade, Wave 3's amplitude is modulated by Wave 2. The peaks and troughs of Wave 2 influence the amplitude of Wave 3, resulting in amplitude variations. The Amplitude Mod Scale input adjusts the strength of this amplitude modulation.

4 — Phase Modulation (Wave 4): Finally, Wave 4's phase is modulated by Wave 3. Wave 3's oscillations shift the phase of Wave 4, leading to phase-related distortions and dynamic wave patterns. The Phase Mod Scale input determines the extent of phase modulation.

5 — Stacked Wave (Average): The script calculates and plots the average of all four waves, providing a composite view of the combined modulation effects.

══════════════════════════════════════════════════

█ FEATURES

The script is organized into input groups for each wave, allowing for detailed customization:

1 — Wave 1: Base Wave
   • Type: Select the waveform type for Wave 1 (Sine, Cosine, Triangle, Square).
   • Frequency (Hz): Sets the base frequency of Wave 1 in Hertz (cycles per second).
   • Amplitude: Controls the vertical amplitude or height of Wave 1.
   • Phase Shift (deg): Adjusts the phase shift of Wave 1 in degrees, shifting the wave horizontally.
   • Vertical Shift: Sets the vertical position of Wave 1 on the chart.

2 — Wave 2: Frequency Modulation
   • Type: Select the waveform type for Wave 2.
   • Base Frequency (Hz): Sets the base frequency of Wave 2, before modulation.
   • Amplitude: Controls the amplitude of Wave 2.
   • Phase Shift (deg): Adjusts the phase shift of Wave 2.
   • Vertical Shift: Sets the vertical position of Wave 2.
   • Frequency Mod Scale: Determines the degree to which Wave 1 modulates Wave 2's frequency. Higher values increase the modulation effect.

3 — Wave 3: Amplitude Modulation
   • Type: Select the waveform type for Wave 3.
   • Base Frequency (Hz): Sets the base frequency of Wave 3.
   • Amplitude: Controls the base amplitude of Wave 3, before modulation.
   • Phase Shift (deg): Adjusts the phase shift of Wave 3.
   • Vertical Shift: Sets the vertical position of Wave 3.
   • Amplitude Mod Scale: Determines the degree to which Wave 2 modulates Wave 3's amplitude. Higher values increase the modulation effect.

4 — Wave 4: Phase Modulation
   • Type: Select the waveform type for Wave 4.
   • Base Frequency (Hz): Sets the base frequency of Wave 4.
   • Amplitude: Controls the amplitude of Wave 4.
   • Phase Shift (deg): Sets the base phase shift of Wave 4, before modulation.
   • Vertical Shift: Sets the vertical position of Wave 4.
   • Phase Mod Scale: Determines the degree to which Wave 3 modulates Wave 4's phase. Higher values increase the modulation effect.

══════════════════════════════════════════════════

█ HOW TO USE

1. Add the "Stacked Wave Modulation Demo" script to your TradingView chart.
2. Explore the input settings. Each wave has its own group of customizable parameters.
3. Adjust the Type, Frequency, Amplitude, Phase Shift, and Vertical Shift for each wave to define their base characteristics.
4. Experiment with the modulation scales (Frequency Mod Scale, Amplitude Mod Scale, Phase Mod Scale) to control the intensity of the modulation effects between the waves.
5. Observe how the waves interact and how the modulations shape their forms and the final stacked wave (average).

══════════════════════════════════════════════════

█ NOTES

* This script utilizes the `waves` and `hsvColor` libraries. [kaigouthro] Look for other scripts on my profile.
* The frequencies are set in Hertz (cycles per second), which relate to bars on the chart. A frequency of 0.5 Hz means 0.5 cycles per bar, or 1 cycle every 2 bars.
* Adjusting the modulation scales allows you to fine-tune the visual impact of the modulation effects.
* The color of each wave plot is dynamically generated based on its value using the HSV color model for visual distinction.
* Feel free to modify and experiment with the script to create different modulation schemes or stacking methods.

Let me know if you have any other questions or would like further refinements!

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.