Page 1 of 7

### Guppy's Multiple Moving Average and Convergence/Divergence

Posted: Fri Feb 26, 2010 7:49 pm
GMMA (Guppy's Multiple Moving Average) is 12 EMA lines:

1) Short (Fast) Group:
EMA(3), EMA(5), EMA(8), EMA(10), EMA(12), EMA(15)

1) Long (Slow) Group:
EMA(30), EMA(35), EMA(40), EMA(45), EMA(50), EMA(60)

GMMACD (Guppy's Multiple Moving Average Convergence/Divergence) is calculated as:
f = SUM(Fast EMA's)
s = SUM(Slow EMA's)
GMMACD = (s - f) / s * 100

GMMA.lua
Code: Select all
function Init()
indicator:name("Guppy's Multiple Moving Average");
indicator:requiredSource(core.Tick);
indicator:type(core.Indicator);

indicator.parameters:addColor("S_COLOR", "Color for the short EMA group", "", core.rgb(0, 0, 255));
indicator.parameters:addColor("L_COLOR", "Color for the long EMA group", "", core.rgb(255, 0, 0));
end

local source = nil;
local EMAs = {};    -- an array of outputs

function CreateEMA(index, N, color, name)
local label;
-- line label
label = "EMA" .. N;
-- create the line
EMAs[index] = instance:addStream(label, core.Line, name .. label, label,
color, source:first() + N - 1);
end

function Prepare()
source = instance.source;
local name;

-- set the indicator name (use the short name of our indicator: GMMA)
name = profile:id() .. "(" .. source:name() .. ")";
instance:name(name);

CreateEMA(0, 3, instance.parameters.S_COLOR, name);
CreateEMA(1, 5, instance.parameters.S_COLOR, name);
CreateEMA(2, 8, instance.parameters.S_COLOR, name);
CreateEMA(3, 10, instance.parameters.S_COLOR, name);
CreateEMA(4, 12, instance.parameters.S_COLOR, name);
CreateEMA(5, 15, instance.parameters.S_COLOR, name);

CreateEMA(6, 30, instance.parameters.L_COLOR, name);
CreateEMA(7, 35, instance.parameters.L_COLOR, name);
CreateEMA(8, 40, instance.parameters.L_COLOR, name);
CreateEMA(9, 45, instance.parameters.L_COLOR, name);
CreateEMA(10, 50, instance.parameters.L_COLOR, name);
CreateEMA(11, 60, instance.parameters.L_COLOR, name);
end

function CalcEMA(index, N, period)
local first;

first = source:first() + N - 1;
if period < first then
return ;
elseif period == first then
-- range: period - N + 1, period - N + 2, ..., period
local range = core.rangeTo(period, N);
EMAs[index][period] = core.avg(source, range);
else
local k;
k = 2.0 / (N + 1.0);
-- EMA - PRICE * K - PREV EMA * (1 - K)
EMAs[index][period] = source[period] * k + EMAs[index][period - 1] * (1 - k);
end
end

function Update(period)
CalcEMA(0, 3, period);
CalcEMA(1, 5, period);
CalcEMA(2, 8, period);
CalcEMA(3, 10, period);
CalcEMA(4, 12, period);
CalcEMA(5, 15, period);

CalcEMA(6, 30, period);
CalcEMA(7, 35, period);
CalcEMA(8, 40, period);
CalcEMA(9, 45, period);
CalcEMA(10, 50, period);
CalcEMA(11, 60, period);
end

GMMACD.lua
Code: Select all
function Init()
indicator:name("Guppy's Multiple Moving Average Convergence/Divergence");
indicator:requiredSource(core.Tick);
indicator:type(core.Oscillator);

indicator.parameters:addColor("COLOR", "Indicator's Color", "", core.rgb(255, 0, 0));
end

local source = nil;
local GMMA = nil;
local out = nil;
local first = nil;

function Prepare()
source = instance.source;
local name;
-- set the indicator name (use the short name of our indicator: GMMA)
name = profile:id() .. "(" .. source:name() .. ")";
instance:name(name);
GMMA = core.indicators:create("GMMA", source);
first = GMMA:getStream(11):first();
out = instance:addStream("H", core.Bar, name .. ".H", "H", instance.parameters.COLOR, first);
end

function Update(period, mode)
GMMA:update(mode);

if (period >= first) then
local f, s;
f = GMMA:getStream(0)[period] + GMMA:getStream(1)[period] + GMMA:getStream(2)[period] +
GMMA:getStream(3)[period] + GMMA:getStream(4)[period] + GMMA:getStream(5)[period];
s = GMMA:getStream(6)[period] + GMMA:getStream(7)[period] + GMMA:getStream(9)[period] +
GMMA:getStream(9)[period] + GMMA:getStream(10)[period] + GMMA:getStream(11)[period];
out[period] = (f - s) / s * 100;
end
end

GMMA.lua

GMMACD.lua

Note: you must have GMMA.lua installed in order to use GMMACD.lua

Version that allows you to define EMA periods.
CGMMA.lua

CGMMACD.lua

Note: you must have CGMMA.lua installed in order to use CGMMACD.lua

GMMACD Overlay.lua

### Re: Guppy's Multiple Moving Average and Convergence/Divergence

Posted: Mon Jun 07, 2010 4:38 am
hi any chance for a signal when the oscilaltor crossess above/below the 0 line
Thanks

### Re: Guppy's Multiple Moving Average and Convergence/Divergence

Posted: Tue Jun 08, 2010 1:29 pm

### Re: Guppy's Multiple Moving Average and Convergence/Divergence

Posted: Tue Aug 31, 2010 2:24 pm
Thanks a lot for this one.
I've just started using GMMA and I already love it.

But I'm also a very unexperienced demo trader so...
Can someone, please, explain it to me how this GMMACD indicator works?

Cheers

### Re: Guppy's Multiple Moving Average and Convergence/Divergence

Posted: Thu Sep 02, 2010 12:10 pm
As said in the first post GMMACD is the indicator which shows relationship between fast and slow moving averages of GMMA indicator. When the indicator is above zero, the sum of fast MA's is above the sum of slow MAs, when it is below zero - the fast MA's are below slow MA's. The using of the "cross zero" signal is similar to use of two MA intersection. When it goes above zero - it indicates the uptrend. When it goes below zero - it indicates the downtrend. Because, like any MA indicator is a bit inertial (i.e. it shows signal with a lag), the trend must be long enough to be successfully detected.

### Re: Guppy's Multiple Moving Average and Convergence/Divergence

Posted: Tue Sep 21, 2010 4:15 pm
GMMA Style Update

### Re: Guppy's Multiple Moving Average and Convergence/Divergence

Posted: Thu Jan 12, 2012 4:14 am
Great job. Thank you.
Could you possibly add a line following the ends of the bars of the histogram - something like the slow CCI line in Woodies CCI indicator. It would make the indicator even more readable. Its colour could be specified by the user.

Cheers

### Re: Guppy's Multiple Moving Average and Convergence/Divergence

Posted: Fri Jan 13, 2012 3:48 am

### Re: Guppy's Multiple Moving Average and Convergence/Divergence

Posted: Fri Jan 13, 2012 7:20 am
Nice work!

Simple and effective indicator!

Could we please have the OPTION of changing the time frames for the EMA's used? Example:

2,5,10,17,25,50 for the short (FAST) and
50,100,200,350,500,1000 for the long (SLOW) groups

Thanks!
sjc

### Re: Guppy's Multiple Moving Average and Convergence/Divergence

Posted: Sun Jan 15, 2012 4:42 am