GoogleFinance 函数计算谷歌表格中的指数移动平均线

Kur*_*ula 2 google-finance google-sheets moving-average google-apps-script google-sheets-formula

我正在使用 Google Sheets 和 GoogleFinance 函数来获取股票数据。我可以用下面的公式计算简单的移动平均线。我正在尝试为每只股票获取长度为 8,13,21,55 的指数移动平均线。关于指数移动平均线公式的任何建议

=AVERAGE(INDEX(GoogleFinance("MSFT","all",WORKDAY(TODAY(),-8),TODAY()),,3))
Run Code Online (Sandbox Code Playgroud)

编辑: 添加我的谷歌表格经验 在此输入图像描述

may*_*ʎɐɯ 5

我发现这个归功于这个用户“Jonathan K 2806”。

\n\n

试试这个,更简单,可能就足够了:

\n\n
\xe2\x80\x8b\xe2\x80\x8b\xe2\x80\x8b\xe2\x80\x8b/**\n * Calculates the EMA of the range.\n *\n * @param {range} range The range of cells to calculate.\n * @param {number} n The number of trailing samples to give higer weight to, e.g. 30.\n * @return The EMA of the range.\n * @customfunction\n */\nfunction EMA(range, n) {\n  if (!range.reduce) {\n    return range;\n  }\n\n  n = Math.min(n, range.length);\n  var a = 2 / (n + 1);\n\n  return range.reduce(function(accumulator, currentValue, index, array) {\n    return currentValue != "" ? (currentValue * a + accumulator * (1-a)) : accumulator;\n  }, 0);\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

\xe2\x80\x8b 转到工具 -> 脚本编辑器,将其粘贴到此处并点击保存,然后返回到电子表格并在单元格中键入 =EMA($A2:$A100, 10)\xe2\x80\x8b 或者您可以想要使用它。

\n