-- More information about this indicator can be found at: -- http://fxcodebase.com/code/viewtopic.php?f=17&t=331 --+------------------------------------------------------------------+ --| Copyright © 2018, Gehtsoft USA LLC | --| http://fxcodebase.com | --+------------------------------------------------------------------+ --| Developed by : Mario Jemic | --| mario.jemic@gmail.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 | --+------------------------------------------------------------------+ -- Indicator profile initialization routine -- Defines indicator profile properties and indicator parameters -- TODO: Add minimal and maximal value of numeric parameters and default color of the streams function AddParam(id, frame , Flag) indicator.parameters:addGroup(id.. ". Time Frame"); indicator.parameters:addBoolean("USE".. id, "Use this Slot", "", Flag); indicator.parameters:addString("TF" .. id, "Time frame", "", frame); indicator.parameters:setFlag("TF" .. id, core.FLAG_PERIODS); indicator.parameters:addString("Pair" .. id, "Pair", "", "EUR/USD"); indicator.parameters:setFlag("Pair" .. id, core.FLAG_INSTRUMENTS); indicator.parameters:addDouble("GAMMA1"..id, "1. Gamma", "", 0.22 ); indicator.parameters:addDouble("GAMMA2"..id, "2. Gamma", "", 0.35 ); indicator.parameters:addDouble("GAMMA3"..id, "3. Gamma", "", 0.44 ); end function Init() indicator:name("MTF_Laguerre_RSI"); indicator:description(""); indicator:requiredSource(core.Bar); indicator:type(core.Indicator); indicator.parameters:addGroup("Selector"); indicator.parameters:addBoolean("First" , "Use First Indicator", "", true); indicator.parameters:addBoolean("Second" , "Use Second Indicator", "", true); indicator.parameters:addBoolean("Third" , "Use Third Indicator", "", true); indicator.parameters:addString("Type", "Number/Arrow", "" , "Number"); indicator.parameters:addStringAlternative("Type", "Number", "" , "Number"); indicator.parameters:addStringAlternative("Type", "Arrow", "" , "Arrow"); indicator.parameters:addGroup("Calculation"); indicator.parameters:addBoolean("Chart" , "Use Chart Price Source", "", true); AddParam(1, "m1", false); AddParam(2, "m5", false); AddParam(3, "m15", false); AddParam(4, "m30", false); AddParam(5, "H1", true); AddParam(6, "H2", false); AddParam(7, "H3", false); AddParam(8, "H4", false); AddParam(9, "H6", false); AddParam(10, "H8", true); AddParam(11, "D1", true); AddParam(12, "W1", true); AddParam(13, "M1", true); indicator.parameters:addGroup("Style"); indicator.parameters:addColor("UP", "Color for Up Trend", "", core.rgb(0, 255, 0)); indicator.parameters:addColor("DN", "Color for Down Trend", "", core.rgb(255, 0, 0)); indicator.parameters:addColor("NO", "Color for Unclear Trend", "", core.rgb(255, 128, 0)); indicator.parameters:addColor("Label", "Label Color", "", core.rgb(0, 0, 0)); indicator.parameters:addDouble("Size", "As % of Cell", "", 90); indicator.parameters:addDouble("HSize", "Horizontal indicator size as % of screen", "", 50, 50, 100); end -- Indicator instance initialization routine -- Processes indicator parameters and creates output streams -- TODO: Refine the first period calculation for each of the output streams. -- TODO: Calculate all constants, create instances all subsequent indicators and load all required libraries -- Parameters block local UP, DN, NO; local source = nil; local TF={}; local Pair={}; local L={}; local host; local offset; local weekoffset; local SourceData={}; local loading={}; local Size; local HSize; local USE={}; local Count=13; local Number; local Chart ; local Label; local GAMMA1={}; local GAMMA2={}; local GAMMA3={}; local Indicator1={}; local Indicator2={}; local Indicator3={}; local Type; local Third, Second, First; -- Routine function Prepare(nameOnly) Chart=instance.parameters.Chart; Type=instance.parameters.Type; source = instance.source; UP=instance.parameters.UP; DN=instance.parameters.DN; NO=instance.parameters.NO; Label=instance.parameters.Label; Shift=instance.parameters.Shift; Size=instance.parameters.Size; HSize=instance.parameters.HSize; Third=instance.parameters.Third; Second=instance.parameters.Second; First=instance.parameters.First; host = core.host; offset = host:execute("getTradingDayOffset"); weekoffset = host:execute("getTradingWeekOffset"); local i; local name = profile:id() .. "(" .. source:name() ; name = name .. ")"; instance:name(name); if (nameOnly) then return; end assert(core.indicators:findIndicator("LAGUERRE_RSI") ~= nil, "Please, download and install LAGUERRE_RSI.LUA indicator"); Number=0; for i = 1, Count, 1 do USE[i]=instance.parameters:getBoolean("USE" .. i); if USE[i] then Number=Number+1; GAMMA1[Number]=instance.parameters:getDouble ("GAMMA1"..i); GAMMA2[Number]=instance.parameters:getDouble ("GAMMA2"..i); GAMMA3[Number]=instance.parameters:getDouble ("GAMMA3"..i); if Chart then Pair[Number]=source:name(); else Pair[Number]= instance.parameters:getString("Pair" .. i); end TF[Number]= instance.parameters:getString("TF" .. i); L[Number] = TF[Number] .. ", ".. Pair[Number]; --name = name ..", " .."(" .. TF[Number] .. ", ".. Pair[Number] ..")"; end end for i = 1, Number, 1 do local Test1 = core.indicators:create("LAGUERRE_RSI", source.close , GAMMA1[i]); local Test2 = core.indicators:create("LAGUERRE_RSI", source.close , GAMMA2[i]); local Test3 = core.indicators:create("LAGUERRE_RSI", source.close , GAMMA3[i]); first= math.max(Test1.DATA:first() , Test2.DATA:first(),Test3.DATA:first())*3 ; SourceData[i] = core.host:execute("getSyncHistory", Pair[i], TF[i], source:isBid(), math.min(300,first) , 200+i, 100+i); Indicator1[i] = core.indicators:create("LAGUERRE_RSI", SourceData[i].close,GAMMA1[i] ); Indicator2[i] = core.indicators:create("LAGUERRE_RSI", SourceData[i].close,GAMMA2[i] ); Indicator3[i] = core.indicators:create("LAGUERRE_RSI", SourceData[i].close,GAMMA3[i] ); loading[i]= true; end core.host:execute ("setTimer", 1, 1); instance:ownerDrawn(true); end function ReleaseInstance() core.host:execute ("killTimer", 1); end function Initialization(id,period) local Candle; Candle = core.getcandle(TF[id], source:date(period), offset, weekoffset); if loading[id] or SourceData[id]:size() == 0 then return false ; end if period < source:first() then return false; end local p = core.findDate(SourceData[id], Candle, false); -- candle is not found if p < 0 then return false; else return p; end end -- Indicator calculation routine -- TODO: Add your code for calculation output values function Update(period) end function Draw(stage, context) if stage ~= 2 then return; end local Flag = false; for j = 1, Number, 1 do if loading[j] then Flag=true; end end local Symbol="\149"; if Flag then return; end local xCell =( (context:right () -context:left ())/100 )* (HSize/Number); local yCell = (context:bottom () -context:top ())/15; for i = 1, Number, 1 do InternalSwift=0; context:createFont (11, "Wingdings", (xCell/10)*(Size/100)*2, yCell*(Size/100), 0); context:createFont (2, "Arial", (xCell/10)*(Size/100), yCell*(Size/100), 0); width, height = context:measureText (2, tostring(TF[i]), 0) context:drawText (2, tostring(TF[i]), Label, -1, context:right ()-(i)*xCell , context:top ()+yCell, context:right ()-(i-1)*xCell + width, context:top ()+yCell + height, 0); if First and Indicator1[i].DATA:hasData(Indicator1[i].DATA:size()-1) and Indicator1[i].DATA:hasData(Indicator1[i].DATA:size()-2) then InternalSwift=InternalSwift+1; local Color; if Indicator1[i].DATA[Indicator1[i].DATA:size()-1] > Indicator1[i].DATA[Indicator1[i].DATA:size()-2] then Color=UP; Symbol="\241"; elseif Indicator1[i].DATA[Indicator1[i].DATA:size()-1] < Indicator1[i].DATA[Indicator1[i].DATA:size()-2] then Color=DN; Symbol="\242"; else Symbol="\243"; Color=NO; end width, height = context:measureText (11,Symbol, 0) context:drawText (11, Symbol, Color, -1, context:right ()-(i)*xCell , context:top ()+yCell*2, context:right ()-(i-1)*xCell + width, context:top ()+yCell*2 + height, 0); if Type == "Number" then local Value= string.format("%." .. 2 .. "f", Indicator1[i].DATA[Indicator1[i].DATA:size()-1] ); width, height = context:measureText (2, Value, 0) context:drawText (2, Value, Label, -1, context:right ()-(i)*xCell , context:top ()+yCell*3, context:right ()-(i-1)*xCell + width, context:top ()+yCell*3 + height, 0); else if Indicator1[i].DATA[Indicator1[i].DATA:size()-1] > 0.5 then Color= UP; Symbol= "\241"; else Color= DN; Symbol= "\242"; end if Indicator1[i].DATA[Indicator1[i].DATA:size()-1] > 0.85 then Symbol= "\198"; elseif Indicator1[i].DATA[Indicator1[i].DATA:size()-1] < 0.15 then Symbol= "\196"; end width, height = context:measureText (11, Symbol, 0) context:drawText (11, Symbol, Label, -1, context:right ()-(i)*xCell , context:top ()+yCell*3, context:right ()-(i-1)*xCell + width, context:top ()+yCell*3 + height, 0); end end if Second and Indicator2[i].DATA:hasData(Indicator2[i].DATA:size()-1) and Indicator2[i].DATA:hasData(Indicator2[i].DATA:size()-2) then InternalSwift=InternalSwift+1; local Color; if Indicator2[i].DATA[Indicator2[i].DATA:size()-1] > Indicator2[i].DATA[Indicator2[i].DATA:size()-2] then Color=UP; Symbol="\241"; elseif Indicator2[i].DATA[Indicator2[i].DATA:size()-1] < Indicator2[i].DATA[Indicator2[i].DATA:size()-2] then Color=DN; Symbol="\242"; else Symbol="\243"; Color=NO; end width, height = context:measureText (11,Symbol, 0) context:drawText (11, Symbol, Color, -1, context:right ()-(i)*xCell , context:top ()+yCell*(2+(InternalSwift-1)*3), context:right ()-(i-1)*xCell + width, context:top ()+yCell*(2+(InternalSwift-1)*3) + height, 0); if Type == "Number" then local Value= string.format("%." .. 2 .. "f", Indicator2[i].DATA[Indicator2[i].DATA:size()-1] ); width, height = context:measureText (2, Value, 0) context:drawText (2, Value, Label, -1, context:right ()-(i)*xCell , context:top ()+yCell*(3+(InternalSwift-1)*3), context:right ()-(i-1)*xCell + width, context:top ()+yCell*(3+(InternalSwift-1)*3) + height, 0); else if Indicator2[i].DATA[Indicator2[i].DATA:size()-1] > 0.5 then Color= UP; Symbol= "\241"; else Color= DN; Symbol= "\242"; end if Indicator2[i].DATA[Indicator2[i].DATA:size()-1] > 0.85 then Symbol= "\198"; elseif Indicator2[i].DATA[Indicator2[i].DATA:size()-1] < 0.15 then Symbol= "\196"; end width, height = context:measureText (11, Symbol, 0) context:drawText (11, Symbol, Label, -1, context:right ()-(i)*xCell , context:top ()+yCell*(3+(InternalSwift-1)*3), context:right ()-(i-1)*xCell + width, context:top ()+yCell*(3+(InternalSwift-1)*3) + height, 0); end end if Third and Indicator3[i].DATA:hasData(Indicator3[i].DATA:size()-1) and Indicator3[i].DATA:hasData(Indicator3[i].DATA:size()-2) then InternalSwift=InternalSwift+1; local Color; if Indicator3[i].DATA[Indicator3[i].DATA:size()-1] > Indicator3[i].DATA[Indicator3[i].DATA:size()-2] then Color=UP; Symbol="\241"; elseif Indicator3[i].DATA[Indicator3[i].DATA:size()-1] < Indicator3[i].DATA[Indicator3[i].DATA:size()-2] then Color=DN; Symbol="\242"; else Symbol="\243"; Color=NO; end width, height = context:measureText (11,Symbol, 0) context:drawText (11, Symbol, Color, -1, context:right ()-(i)*xCell , context:top ()+yCell*(2+ (InternalSwift-1)*3), context:right ()-(i-1)*xCell + width, context:top ()+yCell*(2+ (InternalSwift-1)*3) + height, 0); if Type == "Number" then local Value= string.format("%." .. 2 .. "f", Indicator3[i].DATA[Indicator3[i].DATA:size()-1] ); width, height = context:measureText (2, Value, 0) context:drawText (2, Value, Label, -1, context:right ()-(i)*xCell , context:top ()+yCell*(3+(InternalSwift-1)*3), context:right ()-(i-1)*xCell + width, context:top ()+yCell*(3+(InternalSwift-1)*3) + height, 0); else if Indicator3[i].DATA[Indicator3[i].DATA:size()-1] > 0.5 then Color= UP; Symbol= "\241"; else Color= DN; Symbol= "\242"; end if Indicator3[i].DATA[Indicator3[i].DATA:size()-1] > 0.85 then Symbol= "\198"; elseif Indicator3[i].DATA[Indicator3[i].DATA:size()-1] < 0.15 then Symbol= "\196"; end width, height = context:measureText (11, Symbol, 0) context:drawText (11, Symbol, Label, -1, context:right ()-(i)*xCell , context:top ()+yCell*(3+(InternalSwift-1)*3), context:right ()-(i-1)*xCell + width, context:top ()+yCell*(3+(InternalSwift-1)*3) + height, 0); end end if not Chart then width, height = context:measureText (2, Pair[i], 0) context:drawText (2, Pair[i], Label, -1, context:right ()-(i)*xCell , context:top ()+yCell*(4+(InternalSwift-1)*3), context:right ()-(i-1)*xCell + width, context:top ()+yCell*(4+(InternalSwift-1)*3) + height, 0); end end end -- the function is called when the async operation is finished function AsyncOperationFinished(cookie) local j; local Flag = false; local Count=0; local ID=0; for j = 1, Number, 1 do if cookie == (100+j) then loading[j] = true; elseif cookie == (200+j) then loading[j] = false; end if loading[j] then Count=Count+1; Flag=true; end end if cookie== 1 and not Flag then for j = 1, Number, 1 do if First then Indicator1[j]:update(core.UpdateLast); end if Second then Indicator2[j]:update(core.UpdateLast); end if Third then Indicator3[j]:update(core.UpdateLast); end end end if Flag then core.host:execute ("setStatus", " Loading ".. (Number-Count) .."/" .. Number); else core.host:execute ("setStatus", " Loaded ".. (Number-Count) .."/" .. Number); instance:updateFrom(0); end return core.ASYNC_REDRAW ; end