Standard Deviation Measurement Tool

kurtsmock Updated   
If you like the script please come back and leave me a comment or find me on the interwebs. I get notified you "liked" it... but I have no idea if you actually use it. So, let me know =)

The script uses the open price as the mean and calculates the standard deviation from the open price on a per candle basis

- Goal: -
To establish a mean based on the Open Price and calculate the standard deviation.
The reason for this is if the Open is the mean, then the Standard deviation implies a standardized distance a given candle can be expected to travel
from the open price

- Edge: -
If you know that there is a 68%/95%/99.7% probability that price will NOT move more than
One Standard Deviation/Two Standard Deviations/Three Standard Deviations from the open price respectively
you can set reasonable price targets that relate to those probabilities in a given timeframe.
e.g. if you're on a 1h chart and your target is 3.5% from the open price, but 1 standard deviation of the hourly candle is equal to 0.78%.
You can make assumptions on either:
- The reasonableness of your target
- The holding period likely required for the trade.

Also, Standard Deviation is a function of volatility and this tool provides a unique mechanism for measuring volatility as well on a candle by candle basis

- Customization Options-
- Set 3 independent upper and lower standard deviations.
- Each set of standard deviations are on a switch so you can show 1, 2, or 3 sets of standard deviations
- You can set the distribution width
- Though it's not recommended, you can change the mean source.
- There is a switch to show the standard deviation on only the real-time bar or real-time and historical bars.

- How I Think About This Script -
This strategy is predicated the same principle as Bollinger Bands: the reality that 68% of all data points will fall within one standard deviation of the mean, 96% of all data points will fall within two standard deviations, and 98% of al data points will fall within 3 standard deviations. By understanding the standard deviation, you can possibly infer an edge by understanding the probabilistic range price will be bound to the limits of standard deviation rules according to their probabilistic outcomes for the single candle on any given timeframe. Bollinger Bands are designed to provide this information with the mean being a 20-period moving average and this indicator.

This indicator is designed to provide standard deviation information with the mean being based on the distance price travels away from the open of individual candles in the lookback period.
If you use a strategy where you enter on major candle closes, this can be useful to set targets for those entries based on the intended hold period or at least add/remove validity to other target metrics.

Your target is at the 1.618 Fibonacci level and your confirmation triggers on the 4h candle close (H4 if that's your thing lol). You set up the indicator based on the standard deviation of price movement in 4h candles over the last week.
Let's say the indicator shows that the 1.618 Fibonacci level is 3 standard deviations away.
This being the case this statistically indicates that within the next 4 hours, you have a very low probability of achieving your target (>2%). This doesn't invalidate your target, but it does indicate a low probability of achieving it in the next 4hrs. With this information, you can infer that you are either going to be (a) really lucky (b) in this trade for a lot longer than 4hrs or (c) your target is unrealistic given your intended hold period.

You can develop a more probabilistically favorable hold period calculation by looking at the standard deviation on a higher time frame (e.g. 1d-1w).

Bonus feature: You'll find that the 2 and 3 standard deviations will often "cluster" and these clusters often provide future S/R levels. That's a pretty sweet feature no one things to look for. But, try it. Find a cluster of 2nd and 3rd stdevs that are in somewhat of a horizontal pattern (usually the result of a range) and you'll find that to be a good s/r area. Even better if you use the 3.2 standard deviation, you'll find that is a fantastic breakout signal!

So, you can use it for target setting, a confluence test, a reasonableness test, or just a measurement tool.

This was the first TV script I ever wrong.. Got taken down. But, I've re-released it because there are other TV scripts that attempt to do this but are completely wrong.
Please be careful about using other people's scripts. Always validate the math of the script before you use it if possible.
Stay safe out there and I hope all your dreams come true.
Release Notes:
Balipour sent me a message saying that he noticed I have an "Expected Move" tag for this script, that this is not the "expected move" and so please get rid of the tag and correct the description or he will have to leave a comment to correct me. Further, he advanced his attempt to impose his will by saying that if I don't he will have to report my script to one of the moderators, of which... he is not. Now, he says this script is not related to expected move despite the fact that "A stock's "expected move" represents the one standard deviation expected range for a stock's price in the future. A one standard deviation range encompasses 68% of the expected outcomes, so a stock's expected move is the magnitude of that stock's future price movements with 68% certainty." (Chris, 2016)

While it is correct that this script doesn't provide the precise expected move formula (Price * Implied_Volatility * sqrt(Number_of_Calendar_Days/365) and yes this script doesn't address options, the script does directly relate to the tag "expected move." Like... very directly relate. Because expected move is predicated on standard deviation of returns. But, nonetheless, in the interest of being a good sport, we'll allow balipour to have it his way because... why not. He took the time out of his day to tell me I need to take the time out of my day to appease him and now he has successfully stolen my very valuable time and so we all might as well get something out of it. So. tag removed BaliPour. Way to go.

We'll also invite an allow him to make his comment on why my description about probability and standard deviation are incorrect so he can show us all how much smarter he is than me, which I'm sure he will be excited to do. I hope that he invests as much time into this comment as he has asked me to invest in editing my script descriptions & tags at his demand.

Chris. (2016, November 12). Expected Move Explained (Options Trading) | projectoption. Retrieved February 6, 2021
Release Notes:
Updated for v5.
Changed how stdev is calculated. Uses close now, which is more typical, but it adds/subtracts the standard deviation from the open so you the plots stay in one place through the course of the bar.
Still is a pretty useful script for at a glance standard deviations.
Let me know if any changes should be made.
Release Notes:
Added Labels:
Show or hide label that marks the current standard deviation level. Labels can display the current standard deviation multiplier and/or the price of the standard deviation level
Labels are offset by a user-defined number of bars.
Also, I fixed up the settings menu a bit for aesthetics.
Release Notes:
More options.
Choose Plot Style, Line Width, To Join or Not To Join. That is the question we must ask.
Also fixed a bug where the labels didn't disappear when you unchecked that stdev level from the settings.
Let me know if there's anything more we need to do with this.
Release Notes:
On request: MTF capability.
Higher and Lower Timeframe standard deviations.
Also, You can offset the plot now as well.

Note: The only problem with adding MTF capability is that you'll get errors when the settings are out of alignment. The error you'll get is descriptive enough to make sense to ya.

Open-source script

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 a publication 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.

Want to use this script on a chart?