-- Description from the http://www.metaquotes.net/techanalysis/indicators/alligator -- initializes the indicator function Init() indicator:name("Alligator"); indicator:description("") indicator:requiredSource(core.Tick); indicator:type(core.Indicator); indicator.parameters:addInteger("JawN", "Number of periods for smoothing the alligator jaw", "", 13); indicator.parameters:addInteger("JawS", "Number of periods for shifting the alligator jaw", "", 8); indicator.parameters:addColor("JawC", "Color of the the alligator jaw", "", core.rgb(0, 0, 255)); indicator.parameters:addInteger("TeethN", "Number of periods for smoothing the alligator teeth", "", 8); indicator.parameters:addInteger("TeethS", "Number of periods for shifting the alligator teeth", "", 5); indicator.parameters:addColor("TeethC", "Color of the the alligator teeth", "", core.rgb(255, 0, 0)); indicator.parameters:addInteger("LipsN", "Number of periods for smoothing the alligator lips", "", 5); indicator.parameters:addInteger("LipsS", "Number of periods for shifting the alligator lips", "", 3); indicator.parameters:addColor("LipsC", "Color of the the alligator lips", "", core.rgb(0, 255, 0)); indicator.parameters:addString("MTH", "Smoothing method", "", "MVA"); indicator.parameters:addStringAlternative("MTH", "MVA", "", "MVA"); indicator.parameters:addStringAlternative("MTH", "EMA", "", "EMA"); indicator.parameters:addStringAlternative("MTH", "LWMA", "", "LWMA"); end -- lines parameters local JawN, JawS; local TeethN, TeethS; local LipsN, LipsC; -- indicator source local source; -- lines local Jaw, Teeth, Lips; -- lines sources local JawSrc, TeethSrc, LipsSrc; -- process parameters and prepare for calculations function Prepare() JawN = instance.parameters.JawN; JawS = instance.parameters.JawS; TeethN = instance.parameters.TeethN; TeethS = instance.parameters.TeethS; LipsN = instance.parameters.LipsN; LipsS = instance.parameters.LipsS; source = instance.source; JawSrc = core.indicators:create(instance.parameters.MTH, source, JawN, core.rgb(0, 0, 0)); TeethSrc = core.indicators:create(instance.parameters.MTH, source, TeethN, core.rgb(0, 0, 0)); LipsSrc = core.indicators:create(instance.parameters.MTH, source, LipsN, core.rgb(0, 0, 0)); local name = profile:id() .. "(" .. source:name() .. ", " .. JawN .. "(" .. JawS .. ")," .. TeethN .. "(" .. TeethS .. ")," .. LipsN .. "(" .. LipsS .. "))"; instance:name(name); Jaw = instance:addStream("Jaw", core.Line, name .. ".Jaw", "Jaw", instance.parameters.JawC, JawSrc.DATA:first() + JawS, JawS); Teeth = instance:addStream("Teeth", core.Line, name .. ".Teeth", "Teeth", instance.parameters.TeethC, TeethSrc.DATA:first() + TeethS, TeethS); Lips = instance:addStream("Lips", core.Line, name .. ".Lips", "Lips", instance.parameters.LipsC, LipsSrc.DATA:first() + LipsS, LipsS); end -- Indicator calculation routine function Update(period, mode) JawSrc:update(mode); TeethSrc:update(mode); LipsSrc:update(mode); if (period + JawS >= 0 and period >= JawSrc.DATA:first()) then Jaw[period + JawS] = JawSrc.DATA[period]; end if (period + TeethS >= 0 and period >= TeethSrc.DATA:first()) then Teeth[period + TeethS] = TeethSrc.DATA[period]; end if (period + LipsS >= 0 and period >= LipsSrc.DATA:first()) then Lips[period + LipsS] = LipsSrc.DATA[period]; end end