I'm calculating Google finance 200 day moving average formula in google sheet using formula
=average(query(sort(GoogleFinance("GOOG","price", TODAY()-320, TODAY()),1,0),"select Col2 limit 200"))
Then in google app script I'm getting the above cell value in variable as below
var val = sheet.getRange("T101").getValue();
but in google script I'm getting that variable value as #NA. Can anyone please advise what is causing the issue?
GoogleFinance()
only executes when the spreadsheet is open. So when your trigger runs unattended, the values will not be set. The sample code in this thread may help to keep refreshing the sheet (using.getValues()
) until all of the #N/A's disappear. It works but does add a small lag. – abielita