google-apps-script - Google Finance 200天移动平均线在Apps脚本中获得#NA

标签 google-apps-script google-sheets google-finance

我正在使用公式计算Google工作表中的Google财经200天移动平均公式
=平均值(query(sort(GoogleFinance(“GOOG”,“price”,TODAY()-320,TODAY()),1,0),“select Col2 limit 200”)))
然后在谷歌应用程序脚本中我在变量中获取上述单元格值,如下所示
var val = sheet.getRange(“T101”)。getValue();
但是在谷歌脚本中,我得到的变量值为 #NA 。谁能告诉我是什么引起了这个问题?

最佳答案

为了扩展@Ric ky的答案,这里的技巧是达到一个范围,以便可以对它进行平均数学运算。

对于此工作答案:
=AVERAGE(INDEX(GoogleFinance("GOOG","all",WORKDAY(TODAY(),-200),TODAY()),,3))
这是它起作用的原因:
=AVERAGE( INDEX( // used to get 1 value or a range of values from a reference GoogleFinance("GOOG","all",WORKDAY(TODAY(),-200),TODAY()), // returns an expanded array with column headers, used by INDEX as the reference , // bypass INDEX's row argument to return an entire column to be AVERAGE'd 3 // we want the High column with an index of 3; index is 1-based ) )
视觉效果:

enter image description here

关于google-apps-script - Google Finance 200天移动平均线在Apps脚本中获得#NA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44610508/

相关文章:

python - 使用 bs4 搜索特定类

php - 来自 Google Finance API 调用的 JSON 中的前导斜线

javascript - 循环遍历应用程序脚本中的 Switch 语句

reactjs - 提交表单(ReactJS)到 Google Spreadsheet - 更改消息验证

javascript - 如果在特定字符串旁边,则在两个字符之间搜索字符串

javascript - 在谷歌脚本的电子表格中获取所选下拉列表的值

google-apps-script - 所需权限 : https://www. googleapis.com/auth/spreadsheets

python - Google 财经错误 : invalid literal

function - 谷歌脚本: Append new values in column to another sheet

google-apps-script - 愚蠢的脚本错误