OPEN-SOURCE SCRIPT
SMA Background + Crossovers (20, 50, 200)

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.
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.