-- More information about this indicator can be found at: -- http://fxcodebase.com/code/viewtopic.php?f=17&t=22665 -- Id: 7191 --+------------------------------------------------------------------+ --| Copyright © 2018, Gehtsoft USA LLC | --| http://fxcodebase.com | --+------------------------------------------------------------------+ --| Support our efforts by donating | --| Paypal : https://goo.gl/9Rj74e | --| Patreon : https://goo.gl/GdXWeN | --| BitCoin : 15VCJTLaz12Amr7adHSBtL9v8XomURo9RF | --| BitCoin Cash : 1BEtS465S3Su438Kc58h2sqvVvHK9Mijtg | --| Ethereum : 0x8C110cD61538fb6d7A2B47858F0c0AaBd663068D | --| LiteCoin : LLU8PSY2vsq7B9kRELLZQcKf5nJQrdeqwD | --+------------------------------------------------------------------+ -- -- Stocks & Commodities V. 20:11 (40-42): Using The Fisher Transform by John F. Ehlers -- function Init() indicator:name("Ehlers Fisher Transform"); indicator:description("John Ehlers' Fisher Transform Indicator"); indicator:requiredSource(core.Bar); indicator:type(core.Oscillator); indicator.parameters:addInteger("N", "Number of periods", "", 10); indicator.parameters:addString("Source", "Price source", "", "M2"); indicator.parameters:addStringAlternative("Source", "Typical (H+L+C)/3", "", "M3"); indicator.parameters:addStringAlternative("Source", "Median (H+L)/2", "", "M2"); indicator.parameters:addStringAlternative("Source", "Close", "", "C"); indicator.parameters:addColor("Fisher_color", "Color of Fisher", "", core.rgb(0, 0, 255)); indicator.parameters:addColor("Trigger_color", "Color of Trigger", "", core.rgb(255, 0, 0)); end local N; local first, first1; local source = nil; local SRC = nil; local Fisher = nil; local Trigger = nil; local Value = nil; function Prepare(nameOnly) N = instance.parameters.N; source = instance.source; first = source:first() + N - 1; first1 = first + 1; local srcmode = instance.parameters.Source; local srcmodename; if srcmode == "M3" then SRC = source.typical; srcmodename = "Typical"; elseif srcmode == "M2" then SRC = source.median; srcmodename = "Median"; else SRC = source.close; srcmodename = "Close"; end local name = profile:id() .. "(" .. source:name() .. "," .. srcmodename .. "," .. tostring(N) .. ")"; instance:name(name); if (not (nameOnly)) then Fisher = instance:addStream("Fisher", core.Line, name .. ".Fisher", "Fisher", instance.parameters.Fisher_color, first); Fisher:setPrecision(math.max(2, instance.source:getPrecision())); Trigger = instance:addStream("Trigger", core.Line, name .. ".Trigger", "Trigger", instance.parameters.Trigger_color, first1); Trigger:setPrecision(math.max(2, instance.source:getPrecision())); Value = instance:addInternalStream(first, 0); end end function Update(period) if period >= first and source:hasData(period) then local minLow, maxHigh = mathex.minmax(source, period - N + 1, period); local price = SRC[period]; local value; if minLow == maxHigh then value = 0; else local value_1 = 0; if period >= first1 then value_1 = Value[period - 1]; end value = 0.33 * 2 * ((price - minLow) / (maxHigh - minLow) - 0.5) + 0.67 * value_1; end if value > 0.99 then value = 0.9999; end if value < -0.99 then value = -0.9999; end Value[period] = value; local fisher_1 = 0; if period >= first1 then fisher_1 = Fisher[period - 1]; end Fisher[period] = 0.5 * math.log((1 + value) / (1 - value)) + 0.5 * fisher_1; if period >= first1 then Trigger[period] = Fisher[period - 1]; end end end