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);
out:addLevel(0);
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
Download:
Note: you must have GMMA.lua installed in order to use GMMACD.lua
Version that allows you to define EMA periods.
Note: you must have CGMMA.lua installed in order to use CGMMACD.lua