-- initializes the indicator function Init() indicator:name("DeMarker"); indicator:description("") indicator:requiredSource(core.Bar); indicator:type(core.Oscillator); indicator.parameters:addInteger("N", "Number of periods for smoothing", "", 14); indicator.parameters:addColor("C", "Color of the oscillator", "", core.rgb(0, 127, 127)); end local source; local first; local out; local max; local min; local smax; local smin; local n; -- process parameters and prepare for calculations function Prepare() n = instance.parameters.N; source = instance.source; max = instance:addInternalStream(source:first() + 1); min = instance:addInternalStream(source:first() + 1); smax = core.indicators:create("MVA", max, n, core.rgb(0, 0, 0)); smin = core.indicators:create("MVA", min, n, core.rgb(0, 0, 0)); first = smax.DATA:first(); name = profile:id() .. "(" .. n .. ")"; instance:name(name); out = instance:addStream("DeM", core.Line, name .. ".DeM", "DeM", instance.parameters.C, first); out:addLevel(0); out:addLevel(0.3); out:addLevel(0.5); out:addLevel(0.7); out:addLevel(1); end -- Indicator calculation routine function Update(period, mode) if (period > source:first() + 1) then if (source.high[period] > source.high[period - 1]) then max[period] = source.high[period] - source.high[period - 1] else max[period] = 0; end if (source.low[period] < source.low[period - 1]) then min[period] = source.low[period - 1] - source.low[period]; else min[period] = 0; end end smax:update(mode); smin:update(mode); if (period >= first) then local vmax; local vmin; vmax = smax.DATA[period]; vmin = smin.DATA[period]; if (vmax == 0 and vmin == 0) then out[period] = nil; else out[period] = vmax / (vmax + vmin); end end end