FXCM Forex Trading

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 1063 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 2681
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 » Mon Apr 27, 2015 2:44 am

Style Option Added.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 16557
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Bollinger Bands with EMA

Postby Apprentice » Sun Aug 13, 2017 5:54 am

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


Return to Custom Indicators

Who is online

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