Pine Script doesn't have a built-in function for SMMA, so I used a recursive calculation based on the previous SMMA value. The first value is calculated using a simple moving average (ta.sma()), and for subsequent values, the formula incorporates the previous SMMA value. 20 EMA (Exponential Moving Average):
The 20-period EMA is calculated using ta.ema(). Plotting:The script plots both the 7 SMMA (orange line) and the 20 EMA (blue line) on the chart. Buy/Sell Signals:
A buy signal is generated when the 20 EMA crosses above the 7 SMMA. A sell signal is generated when the 20 EMA crosses below the 7 SMMA. These signals are marked with green "BUY" and red "SELL" labels on the chart. How to use: Copy and paste the code into TradingView's Pine Script editor. Add the script to a chart to visualize both moving averages and the crossover signals. Let me know if you need further modifications or have other requests!
In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publications is governed by House rules. You can favorite it to use it on a chart.
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.