# Variable moving average standard deviation?

#### arod49

##### New member
I was wondering if its possible to add standard deviation to a variable moving average to create something similar to Bollinger Bands?

Sure, you can take the following code from this script and replace VixFix with whatever variable you want.

Code:
``````# BollingerBands code

input ShowBollingerBands = No;
input displace = 0;
input BBlength = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;

def sDev = stdev(data = VixFix[-displace], length = BBlength);
def MidLine = MovingAverage(averageType, data = VixFix[-displace], length = BBlength);

def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;
plot LB = if ShowBollingerBands then LowerBand else Double.NaN;
plot UB = if ShowBollingerBands then UpperBand else Double.NaN;
LB.SetDefaultColor(GetColor(0));
UB.SetDefaultColor(GetColor(5));``````

thank you and ill make sure to use the questions forum next time! I keep typing VariableMA in the Vixfix but its not working

@arod49 You need to define variableMA first then use VMA value in the BB code.

@arod49 post the entire code of what you’re trying to get done.

USe the ToS variable MA study. So the study must first define the variable MA and then you can use that value for the center of the bands.

On think or swim, Im looking for a study that charts not just the simple moving average but also draws a channel around the SMA of 1 standard deviation away from the SMA. Is there a study for that?

On think or swim, Im looking for a study that charts not just the simple moving average but also draws a channel around the SMA of 1 standard deviation away from the SMA. Is there a study for that?
Do a search for "sma deviation channels" and you'll find more than a few topics... Several studies exist... We shouldn't be expected to search for you and hand over the links...

First of all, no one is asking You for anything. A simple, "Their called Bollinger bands, a study already exists." or if you simply don't know what you are talking about, don't have to say anything. I don't know what they are because I don't use indicators like that, but for you to come on here acting like you do and then to be smug about, I don't don't even know what to say about that. "SMA deviation channels" isn't a thing. If answering questions on a forum for answering questions is an issue what are you even doing here?

@Brain Monkey I'm sorry you feel the way you do but the honest truth is that far too many members come asking questions and expecting to be hand fed rather than doing any actual research for themselves... Whether or not you fall into that category is subjective... It can be literally exhausting to come here throughout the day and see it happen over and over again... If you spent the time here that a few of us do then you would understand... I feel that a timely response to members questions is paramount, even if it isn't the answer they want...

Im sorry, I've been working on a variance / IV study all morning I've got a screaming hang over. Thank you for your hard work.

(P.S. ....Sorry, I couldnt help it)

Last edited:

87k+ Posts
655 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?