OPEN-SOURCE SCRIPT
Sigma Distance From Moving Average

This is an indicator I've wanted to build for a while. The advent of AI and vibe coding circa 2026 made it feasible.
This is an iteration of the previous indicator I shared - % distance from moving average - which, as explained in the self-described title, displays the % distance an asset's current price sits above or below whatever moving average you enter on whatever timeframe you choose.
This new version expresses this distance as a z score rather than a %. The high level is we're going one level deeper - knowing how far an asset's current price is from its moving average is interesting, but what's more interesting is knowing how often this asset reaches this level above/below its moving average. Some assets are volatile, others less so. For something that moves a lot, being 15-20% above its 50 day moving average isn't all that rare. For something that doesn't move a lot, that might be a once in a ten thousand occurrence - we want to be able to quantify this. That's what this one does.
Enjoy!
This is an iteration of the previous indicator I shared - % distance from moving average - which, as explained in the self-described title, displays the % distance an asset's current price sits above or below whatever moving average you enter on whatever timeframe you choose.
This new version expresses this distance as a z score rather than a %. The high level is we're going one level deeper - knowing how far an asset's current price is from its moving average is interesting, but what's more interesting is knowing how often this asset reaches this level above/below its moving average. Some assets are volatile, others less so. For something that moves a lot, being 15-20% above its 50 day moving average isn't all that rare. For something that doesn't move a lot, that might be a once in a ten thousand occurrence - we want to be able to quantify this. That's what this one does.
Enjoy!
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.