OPEN-SOURCE SCRIPT

Price vs SMA

23
This indicator displays the current price in percentage terms, indicating whether it is above or below a selected simple moving average (SMA). It’s designed to be clean and minimal, with the option to display a brief sentence on the chart for added clarity.

The script calculates the distance between the current price and a chosen simple moving average (SMA) and expresses that distance as a percentage. By default, it uses the 200-period SMA, but you can adjust the length to any value, such as 50 or 100, depending on your trading style. A positive percentage means price is trading above the SMA, while a negative percentage means it is below.

The percentage difference is rounded to whole numbers and can be displayed directly in the chart legend if the “Indicator values” box is checked in the TradingView settings. This keeps the chart clean while still providing at-a-glance information about the price relative to your selected moving average.

For extra clarity, the script also includes an option to display a short sentence on the chart itself. This sentence will read “Price is x% above [SMA length] SMA” in green when price is above the SMA, or “Price is x% below [SMA length] SMA” in red when price is below. This visual cue makes it easy to interpret the relationship between price and the moving average without adding clutter.


免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。