{"ScriptPreparationCode":"const close = [\r\n 2.212, 2.211, 2.22, 2.21, 2.222, 2.219, 2.22, 2.225, 2.231, 2.224, 2.222,\r\n 2.218, 2.217, 2.201, 2.197, 2.2, 2.21, 2.202, 2.204, 2.202, 2.199, 2.2,\r\n 2.197, 2.198, 2.197, 2.196, 2.194, 2.193, 2.188, 2.189, 2.191, 2.193, 2.177,\r\n 2.179, 2.181, 2.18, 2.184, 2.176, 2.177, 2.169, 2.171, 2.168, 2.171, 2.171,\r\n 2.165, 2.17, 2.17, 2.17, 2.171, 2.174, 2.169, 2.167, 2.161, 2.16, 2.159,\r\n 2.161, 2.157, 2.154, 2.153, 2.152, 2.153, 2.156, 2.153, 2.149, 2.144, 2.146,\r\n 2.145, 2.146, 2.144, 2.137, 2.133, 2.131, 2.122, 2.126, 2.123, 2.124, 2.116,\r\n]\r\nfunction sma_DOC(source, window) {\r\n let result = []\r\n\r\n if (source.length \u003C window) {\r\n return result\r\n }\r\n\r\n let sum = 0\r\n for (let index = 0; index \u003C window; \u002B\u002Bindex) {\r\n sum \u002B= source[index]\r\n }\r\n result.push(sum / window)\r\n\r\n let steps = source.length - window - 1\r\n for (let index = 0; index \u003C steps; \u002B\u002Bindex) {\r\n sum -= source[index]\r\n sum \u002B= source[index \u002B window]\r\n result.push(sum / window)\r\n }\r\n return result\r\n}\r\nfunction sma(source, period) {\r\n let size = source.length - 1\r\n\r\n let output = []\r\n\r\n let scale = 1.0 / period\r\n\r\n if (period \u003C 1) return \u0022Invalid Options\u0022\r\n\r\n if (size \u003C= period - 1) return \u0022Out of range\u0022\r\n\r\n let sum = 0\r\n\r\n for (let index = 0; index \u003C period; \u002B\u002Bindex) {\r\n sum \u002B= source[index]\r\n }\r\n // output.push(sum * scale)\r\n output[output.length] = sum * scale\r\n\r\n for (let index = period; index \u003C size; \u002B\u002Bindex) {\r\n sum \u002B= source[index]\r\n sum -= source[index - period]\r\n\r\n // output.push(sum * scale)\r\n output[output.length] = sum * scale\r\n }\r\n\r\n return output\r\n}","TestCases":[{"Name":"doc","Code":"sma_DOC(close, 10)","IsDeferred":false},{"Name":"new","Code":"sma(close, 10)","IsDeferred":false}]}