# Standard Deviation Measurement Tool

5562 visningar
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
or
- 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.

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.

Example:
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!

Summary
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
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.

Want to use this script on a chart?

## Kommentarer

Very Good Tool thank you very much!
Svara
expert explanation, thanks
Svara
after calculating for 1STD ,2STD and 3STd , how do you no when 1STD(68%) has occur ,2995%0 and 3 STD (98%) with the band value given

Std Dev 1 2 3 Std Dev 2 Actual Actual % Nomal Nomal %
Uper 0.010057631 0.020154409 0.030251186 1 557 376.35% 100.936 68.20%
Lower -0.010135923 -0.0202327 -0.030329478 2 700 472.97% 141.192 95.40%
3 725 489.86% 147.704 100%
Svara
why is there not a "waka waka" tag for this script!!!! i am outraged!!!
Svara
JoshuaMcGowan
@JoshuaMcGowan, full disclosure im using bits and pieces of this code for a day trading model that is helping my account balance so at the end of the day not terribly concerned with tags n such lollll. great work sir regardless of the clowns
Svara
JoshuaMcGowan
@JoshuaMcGowan, Hey thanks a lot that means the world to me that its been useful to you =)
Svara
Spicy dramas is spicy. But just wanna say thanks for the script!
Svara
AzureKn1ght
@AzureKn1ght, haha. True. np and thanks for the comment. Yea sorry about that. I didn't realize that by updating the script I'd draw more attention to it. I'm not a drama kinda guy and I've always had a deep respect for BaliPour and love his work. For me, it was fine. I don't mind the challenge and being called out. I'm not a mathematician or a statistician. I'm just an accountant and I've only been trading for 3 years or so now. So, I'm sure there's a lot I can be corrected on. But, I really don't want him sliding in everyone's dm's like that.

Bullying should be called out right? I wouldn't necessarily think this fully rises to the level of bullying, but nonetheless, you go sending messages to people like that who are in a bad spot, its really going to hurt them and that's not right. Not over the technical nature of a script published over a year ago that no one is looking at. And if you feel the burning need to do so, try on some kindness and empathy. That's all. I appreciate the comment and hope you have a very profitable 2021
Svara
Fantastic overview of these levels , I'll be using it . Great if it could summarise percent of times price returns or breaches each level and reaches next !evel
Svara
Since you can't really do analysis of historical prices on TV with Pine to properly do this wouldn't using VWAP instead of open provide more reliable results. In my testing it seems to be a better approximation.
Svara