## Standard Deviation Indicator

Here you can post and download custom indicators. PLEASE: Do not start topics unless you are posting your own indicator, they will be moved to appropriate section even if you do.

### Standard Deviation Indicator

The formula is:
StdDev (i) = SQRT (AMOUNT (j = i - N, i) / N)
AMOUNT (j = i - N, i) = SUM ((ApPRICE (j) - MA (ApPRICE (i), N, i)) ^ 2)
Where:
StdDev (i) — Standard Deviation of the current bar;
SQRT — square root;
AMOUNT(j = i - N, i) — sum of squares from j = i - N to i;
N — smoothing period;
ApPRICE (j) — the price of the j-th bar;
MA (ApPRICE (i), N, i) — any moving average of the current bar for N periods;
ApPRICE (i) — the price of the current bar.

Code: Select all
`function Init()    indicator:name("Standard Deviation Indicator");    indicator:description("Technical indicator named Standard Deviation (StdDev) measures the market volatility.");    indicator:requiredSource(core.Tick);    indicator:type(core.Oscillator);        indicator.parameters:addInteger("N", "N", "Period", 20);    indicator.parameters:addColor("clrStdDev", "Color of StdDev", "Color of StdDev", core.rgb(0, 255, 0));endlocal first;local source = nil;local MA;local N;function Prepare()    source = instance.source;    N=instance.parameters.N;    MA = core.indicators:create("MVA", source, N);    first = MA.DATA:first()+N;    local name = profile:id() .. "(" .. source:name() .. ", " .. N .. ")";    instance:name(name);    StdDev = instance:addStream("StdDev", core.Line, name .. ".StdDev", "StdDev", instance.parameters.clrStdDev, first);endfunction Update(period, mode)    MA:update(mode);    if (period>first+N) then     local dAmount=0.;     local dMovingAverage=MA.DATA[period];     local i;     for i=0,N,1 do      dAmount=dAmount+math.pow((source[period-i]-dMovingAverage),2);     end     StdDev[period]=math.sqrt(dAmount/N);    end end`

StdDev.lua

Normalized Standard Deviation Indicator.lua
Alexander.Gettinger
FXCodeBase: Confirmed User

Posts: 3625
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

### Re: Standard Deviation Indicator

Hi there,

Great but could you explain how do we interpret it efficiently ?

Thanks,

Keyrama
keyrama

Posts: 23
Joined: Wed Apr 28, 2010 1:34 pm
Location: http://www.en-bourse.fr

### Re: Standard Deviation Indicator

The indicator shows how much the price at the particular period differs from the price expected in the trend (i.e. sequence of the prices which looks predictable). So, higher value can point to the change of the price direction.
Nikolay.Gekht
FXCodeBase: Base Builder

Posts: 1223
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

### Re: Standard Deviation Indicator

Ok, that's what i thought.
That means when a peak is starting to fall back, price as started the correction of the move.
On 20 periods it seems too laggy for me, but around 16periods and not too choppy.

What is interesting is that it reflects well the gravity model, so maybe we could the use the symetry to anticipate where price starts and ends a corrective move.

I will look if there is something good to get out of this indicator.

Thanks,

keyrama
keyrama

Posts: 23
Joined: Wed Apr 28, 2010 1:34 pm
Location: http://www.en-bourse.fr

### Re: Standard Deviation Indicator

Update indicator.

Code: Select all
`function Init()    indicator:name("Standard Deviation Indicator");    indicator:description("Technical indicator named Standard Deviation (StdDev) measures the market volatility.");    indicator:requiredSource(core.Tick);    indicator:type(core.Oscillator);        indicator.parameters:addInteger("N", "N", "Period", 20);    indicator.parameters:addString("Method", "Method", "", "MVA");    indicator.parameters:addStringAlternative("Method", "MVA", "", "MVA");    indicator.parameters:addStringAlternative("Method", "EMA", "", "EMA");    indicator.parameters:addStringAlternative("Method", "KAMA", "", "KAMA");    indicator.parameters:addStringAlternative("Method", "LWMA", "", "LWMA");    indicator.parameters:addStringAlternative("Method", "TMA", "", "TMA");    indicator.parameters:addColor("clrStdDev", "Color of StdDev", "Color of StdDev", core.rgb(0, 255, 0));endlocal first;local source = nil;local MA;local N;local Method;function Prepare()    source = instance.source;    N=instance.parameters.N;    Method=instance.parameters.Method;    MA = core.indicators:create(Method, source, N);    first = MA.DATA:first()+N;    local name = profile:id() .. "(" .. source:name() .. ", " .. N .. ", " .. Method .. ")";    instance:name(name);    StdDev = instance:addStream("StdDev", core.Line, name .. ".StdDev", "StdDev", instance.parameters.clrStdDev, first);endfunction Update(period, mode)    MA:update(mode);    if (period>first+N) then     local dAmount=0.;     local dMovingAverage=MA.DATA[period];     local i;     for i=0,N,1 do      dAmount=dAmount+math.pow((source[period-i]-dMovingAverage),2);     end     StdDev[period]=math.sqrt(dAmount/N);    end end`

StdDev2.lua

This indicator provides Audio / Email Alerts on Standard Deviation Line / Triger Lines Cross.
Make sure to define the trigger line which is different from default 0.
Alexander.Gettinger
FXCodeBase: Confirmed User

Posts: 3625
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

### Standard Deviation Indicator

Since a workcenter has only 6 standard values, why would you want the standard value key to have more than that?
Kactassem

Posts: 3
Joined: Thu Aug 19, 2010 8:38 am
Location: United States

### Re: Standard Deviation Indicator

Please allow three levels of Standard Deviation to be entered by user.

Each breach of level would trigger an Audible and Visual alert within the StdDev2 indicator panel as illustrated in attached image. Alert will have "Dialog box alert" function.

Thanks!

sjc
Attachments
Std Dev2 with 3 levels of signals

Coondawg71

Posts: 324
Joined: Sat Jan 15, 2011 11:45 am

### Re: Standard Deviation Indicator

Apprentice
FXCodeBase: Confirmed User

Posts: 20850
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

### Re: Standard Deviation Indicator

I like using two moving averages of standard deviations and taking a trade when they cross. For example, when a 10-period simple moving average of the standard deviation crosses over the 20-period SMA of the SD, as shown in the attached example. It shows me that volatility has increased in a way that is more useful than Bollinger bands. Would you be willing to create an indicator for this?
Attachments
SenseClash

Posts: 24
Joined: Sun Jul 13, 2014 12:16 pm

### Re: Standard Deviation Indicator

From what I can see, u have two Standard Deviation Indicator attached to the chart.

Can u give a more detailed description.
Probably with formula and a description of the desired presentation.

Apprentice
FXCodeBase: Confirmed User

Posts: 20850
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Next