SMA Selectable Timeframe Alerts

168
The script triggers alerts when a candle closes above or below your selected SMA on the timeframes you choose, eliminating the uncertainty associated with TradingView’s built-in SMA alert triggers.

1. Install: Replace everything in Pine Editor with the new script, then Save → Add to chart.
2. Choose the SMA: Open the indicator’s Settings → Inputs. Set SMA length to 15, 25, 50, 100, 150, or 200.
3. Choose direction: Select Both, Above only, or Below only.
4. Choose timeframes: Under Alert Timeframes, check only those you want monitored.
5. Set the chart: Use a standard candlestick chart at or below the smallest selected timeframe. If 1h and 1D are selected, use a 1-hour chart or lower.
6. Create the alert: Select Create Alert → SMA Selectable Timeframe Alerts → Any alert() function call. Enable phone/email notifications and click Create.
Example notification:
NASDAQ:TSLA | 1D | Close crossed ABOVE SMA 200 | Close: 430.00 | SMA: 425.50

One alert covers one SMA length, your selected timeframes, and one stock. Repeat for additional SMA lengths or stocks.

Once created, it runs with TradingView closed, and you can change your visible chart timeframe. Recreate an alert whenever you change the script or its settings—existing alerts retain their original setup.

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.