这个指标是根据顾比均线计算的MACD图,下面是源码;
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