OPEN-SOURCE SCRIPT

SMA Background + Crossovers (20, 50, 200)

33
This Pine Script plots three Simple Moving Averages (SMA 20, 50, and 200) and visually highlights market conditions using both background colors and crossover signals. The background changes based on where the price is relative to the SMAs — light yellow when below the 20-day, dark yellow when below the 50-day, and red when below the 200-day — providing an instant visual cue of short-, medium-, and long-term weakness.

In addition, the script identifies and marks bullish and bearish crossovers among the SMAs (20/50, 50/200, and 20/200), using upward and downward triangles to signal momentum shifts. Each crossover can also trigger TradingView alerts, allowing the user to automate notifications for trend reversals. Overall, the code combines trend visualization, momentum detection, and alert functionality into one compact indicator.

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.