Bollinger Bands with EMA

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

Bollinger Bands with EMA

Postby Alexander.Gettinger » Fri Apr 16, 2010 5:31 pm

Original Bollinger Bands with an EMA instead of a simple ma.

MiddleLine = EMA(N)
TopLile = MiddleLine + (D * StdDev)
BottomLine = MiddleLine — (D * StdDev)
D - standard deviations.

1.JPG


Code: Select all
function Init()
    indicator:name("Bollinger Bands with EMA");
    indicator:description("Original Bollinger Bands with an EMA instead of a simple ma");
    indicator:requiredSource(core.Tick);
    indicator:type(core.Indicator);

    indicator.parameters:addDouble("N", "Number of periods", "Number of periods", 20.0);
    indicator.parameters:addDouble("Dev", "Number of standard deviations", "Number of standard deviations", 2.0);
   
    indicator.parameters:addColor("clrBBP", "clrBBP", "clrBBP", core.rgb(255, 0, 0));
    indicator.parameters:addColor("clrBBM", "clrBBM", "clrBBM", core.rgb(0, 255, 0));
    indicator.parameters:addColor("clrBBA", "clrBBA", "clrBBA", core.rgb(0, 0, 255));
end

local N;
local D;

local first;
local source = nil;

local TL = nil;
local BL = nil;

local MA=nil;

-- Routine
function Prepare()
    N = instance.parameters.N;
    D = instance.parameters.Dev;
   
    source = instance.source;
    first = source:first()+N-1;

    local name = "Bollinger Bands with EMA (" .. N .. ", " .. D .. ")";
    instance:name(name);
   
    MA = core.indicators:create("EMA", source, N);
   
    TL = instance:addStream("TL", core.Line, name .. ".TL", "TL", instance.parameters.clrBBP, first)
    BL = instance:addStream("BL", core.Line, name .. ".BL", "BL", instance.parameters.clrBBM, first)
    AL = instance:addStream("AL", core.Line, name .. ".AL", "AL", instance.parameters.clrBBA, first)
end

-- Indicator calculation routine
function Update(period,mode)
    MA:update(mode);
    if(period >= first) then
     local ml=MA.DATA[period];
     local d = core.stdev(source, core.rangeTo(period, N));
     TL[period] = ml + D * d;
     BL[period] = ml - D * d;
     AL[period] = ml;
    end
end
Attachments
BB_EMA.lua
(1.75 KiB) Downloaded 1860 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 3785
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Bollinger Bands with EMA

Postby Thecity » Sun Apr 26, 2015 2:54 pm

Could you add all the grafic options like the standard bollinger bands, please? Thanks in advance.
Thecity
 
Posts: 6
Joined: Thu Apr 16, 2015 8:39 am


Re: Bollinger Bands with EMA

Postby Apprentice » Fri Oct 19, 2018 4:12 am

The indicator was revised and updated.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Return to Custom Indicators

Who is online

Users browsing this forum: Baidu [Spider] and 21 guests