-- Description from the http://www.investopedia.com/articles/trading/03/022603.asp -- initializes the indicator function Init() indicator:name("Elder-Ray"); indicator:description("") indicator:requiredSource(core.Bar); indicator:type(core.Oscillator); indicator.parameters:addInteger("N", "Number of periods for smoothing", "", 13); indicator.parameters:addColor("BullC", "Color of the bull power line", "", core.rgb(255, 0, 0)); indicator.parameters:addColor("BearC", "Color of the bear power line", "", core.rgb(0, 255, 0)); end local source; local EMA; local Bull; local Bear; -- process parameters and prepare for calculations function Prepare() source = instance.source; EMA = core.indicators:create("EMA", source.close, instance.parameters.N, core.rgb(0, 0, 0)); local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.N .. ")"; instance:name(name); Bull = instance:addStream("Bull", core.Line, name .. ".Bull", "Bull", instance.parameters.BullC, EMA.DATA:first()); Bear = instance:addStream("Bear", core.Line, name .. ".Bear", "Bear", instance.parameters.BearC, EMA.DATA:first()); Bull:addLevel(0); end -- Indicator calculation routine function Update(period, mode) EMA:update(mode); if (period >= EMA.DATA:first()) then Bull[period] = source.high[period] - EMA.DATA[period]; Bear[period] = source.low[period] - EMA.DATA[period]; end end