-- More information about this indicator can be found at: -- http://fxcodebase.com/code/viewtopic.php?f=28&t=61403 --+------------------------------------------------------------------------------------------------+ --| Copyright © 2021, Gehtsoft USA LLC | --| http://fxcodebase.com | --+------------------------------------------------------------------------------------------------+ --| Support our efforts by donating | --| Paypal: https://goo.gl/9Rj74e | --+------------------------------------------------------------------------------------------------+ --| Developed by : Mario Jemic | --| mario.jemic@gmail.com | --| https://AppliedMachineLearning.systems | --| Patreon : https://goo.gl/GdXWeN | --+------------------------------------------------------------------------------------------------+ --+------------------------------------------------------------------------------------------------+ --|BitCoin Address : 15VCJTLaz12Amr7adHSBtL9v8XomURo9RF | --|Ethereum Address : 0x8C110cD61538fb6d7A2B47858F0c0AaBd663068D | --|Cardano/ADA : addr1v868jza77crzdc87khzpppecmhmrg224qyumud6utqf6f4s99fvqv | --|Dogecoin Address : DNDTFfmVa2Gjts5YvSKEYaiih6cums2L6C | --|Binance(ERC20 & BSC only) : 0xe84751063de8ade7c5fbff5e73f6502f02af4e2c | | --+------------------------------------------------------------------------------------------------+ -- 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 Init() indicator:name("Multi Stream Loading Template"); indicator:description("Multi Stream Loading Template"); indicator:requiredSource(core.Bar); indicator:type(core.Indicator); Add(1, "Chart"); Add(2, "W1"); Add(3, "M1"); end function Add(id, TF) indicator.parameters:addGroup(id .. ". Time Frame"); indicator.parameters:addBoolean("On"..id, "Use Time Frame", "", true); indicator.parameters:addString("TF"..id, "Time frame", "", TF); local iTF={"Chart", "m1", "m5", "m15", "m30", "H1", "H2", "H3", "H4", "H6", "H8", "D1","W1", "M1"}; for i= 1, 14, 1 do indicator.parameters:addStringAlternative("TF"..id, iTF[i], iTF[i] , iTF[i]); end indicator.parameters:addInteger("Period"..id, "Period", "Period", 20); end local dayoffset,weekoffset; local Source ={}; local TF={}; local first; local source = nil; local loading={}; local p={}; local Number ; local Period={}; local Indicator={} -- Routine function Prepare(nameOnly) local name = profile:id() .. "(" .. instance.source:name() .. ")"; instance:name(name); if (nameOnly) then return; end source = instance.source; dayoffset = core.host:execute("getTradingDayOffset"); weekoffset = core.host:execute("getTradingWeekOffset"); Number=0; local i; for i = 1, 3, 1 do if instance.parameters:getBoolean ("On"..i) then Number=Number+1; Period[Number]= instance.parameters:getInteger ("Period"..i); TF[Number]= instance.parameters:getString("TF" .. i); if TF[Number]=="Chart" then TF[Number]=source:barSize(); end Test = core.indicators:create("MVA", source.close ,Period[Number] ); first= Test.DATA:first() ; Source[Number] = core.host:execute("getSyncHistory",source:instrument(), TF[Number], source:isBid(), first, 200+i, 100+i); Indicator[Number]= core.indicators:create("MVA", Source [Number].close ,Period[Number] ); loading[Number]=true; end end end -- Indicator calculation routine -- TODO: Add your code for calculation output values function Update(period, mode) local Flag=false; for i= 1, Number, 1 do p[i]= Initialization(period,i) if loading[i] or p[i]== false then Flag=true; else Indicator[i]:update(mode); end end if Flag then return; end end function Initialization(period,id) local Candle; Candle = core.getcandle(source:barSize(), source:date(period), dayoffset, weekoffset); if loading[id] or Source[id]:size() == 0 then return false; end if period < source:first() then return false; end local P = core.findDate(Source [id], Candle, false); -- candle is not found if P < 0 then return false; else return P; end end -- the function is called when the async operation is finished function AsyncOperationFinished(cookie) local j; local Flag = false; local Count=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 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