--+------------------------------------------------------------------+ --| Copyright © 2016, Gehtsoft USA LLC | --| http://fxcodebase.com | --| Support our efforts by donating | --| Paypal: https://goo.gl/9Rj74e | --+------------------------------------------------------------------+ --| Developed by : Mario Jemic | --| mario.jemic@gmail.com | --| BitCoin : 15VCJTLaz12Amr7adHSBtL9v8XomURo9RF | --+------------------------------------------------------------------+ function Init() indicator:name("BubbleSort"); indicator:description(""); indicator:requiredSource(core.Bar); indicator:type(core.Indicator); indicator.parameters:addGroup("Calculation"); indicator.parameters:addInteger("Input1", "1.", "", 1); indicator.parameters:addInteger("Input2", "2.", "", 56); indicator.parameters:addInteger("Input3", "3.", "", 100); indicator.parameters:addInteger("Input4", "4.", "", 66); indicator.parameters:addInteger("Input5", "5.", "", 0); end local InputData={}; function Prepare() source = instance.source; InputData[1]={}; InputData[1][1]=instance.parameters.Input1; InputData[1][2]=instance.parameters.Input2; InputData[1][3]=instance.parameters.Input3; InputData[1][4]=instance.parameters.Input4; InputData[1][5]=instance.parameters.Input5; local name = profile:id(); instance:name(name); Key= BubbleSort(InputData,1,1, 5 ); core.host:execute ("setStatus", InputData[1][Key[1]].. " + " .. InputData[1][Key[2]].. " + " .. InputData[1][Key[3]].. " + " .. InputData[1][Key[4]].. " + " .. InputData[1][Key[5]]); end function BubbleSort(Data, index,raw, columns) local Key={}; local Temp; local Sort=true; for i=1, columns, 1 do Key[i]=i; end while Sort do Sort=false; for i = 2, columns , 1 do if Data[index][Key[i]] < Data[index][Key[i-1]] then Sort=true; Temp= Key[i]; Key[i]=Key[i-1]; Key[i-1]=Temp; end end end return Key; end function Update(period, mode) end