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.

Moderator: admin

Standard Deviation Indicator

Postby Alexander.Gettinger » Thu Apr 29, 2010 1:41 am

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.

StdDev.png


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));
end

local 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);
end

function 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
(1.2 KiB) Downloaded 1789 times

Normalized Standard Deviation Indicator.lua
(3.01 KiB) Downloaded 87 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 3237
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Standard Deviation Indicator

Postby keyrama » Thu Apr 29, 2010 1:56 am

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

Postby Nikolay.Gekht » Thu Apr 29, 2010 8:08 am

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: 1222
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Standard Deviation Indicator

Postby keyrama » Thu Apr 29, 2010 9:16 am

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

Postby Alexander.Gettinger » Tue Oct 12, 2010 1:37 am

Update indicator.
Added method of MA.

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));
end

local 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);
end

function 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
(1.72 KiB) Downloaded 1174 times

StdDev with Alert.lua
(10.29 KiB) Downloaded 333 times

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: 3237
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Standard Deviation Indicator

Postby Kactassem » Mon Oct 18, 2010 12:20 pm

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

Postby Coondawg71 » Sun Feb 02, 2014 8:14 am

Can we please add Alert function to this 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 Signal Alerts.png
Std Dev2 with 3 levels of signals
User avatar
Coondawg71
FXCodeBase: Graduate
 
Posts: 324
Joined: Sat Jan 15, 2011 11:45 am

Re: Standard Deviation Indicator

Postby Apprentice » Mon Feb 03, 2014 6:46 am

Standard Deviation Indicator with Alert Added.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 18850
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Standard Deviation Indicator

Postby SenseClash » Sun Jul 13, 2014 12:27 pm

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
07-07 Chart USD_CAD 5m.jpg
SenseClash
 
Posts: 24
Joined: Sun Jul 13, 2014 12:16 pm

Re: Standard Deviation Indicator

Postby Apprentice » Sun Jul 13, 2014 1:37 pm

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.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 18850
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Next

Return to Custom Indicators

Who is online

Users browsing this forum: Bing [Bot] and 25 guests