Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google finance 200 day moving average is getting as #NA in Apps Script

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?

like image 511
Syed Mohammed Mehdi Avatar asked Jun 17 '17 23:06

Syed Mohammed Mehdi


People also ask

What does the 200 day moving average mean?

The 200-day moving average is represented as a line on charts and represents the average price over the past 200 days (or 40 weeks). The moving average can give traders a sense regarding whether the trend is up or down, while also identifying potential support or resistance areas.

How does Google Finance calculate moving average?

Syntax for this function is as follows: AVERAGE(value1, [value2, ...]) Here, value1 is the first value to consider in the average calculation.

What do moving averages tell us?

A moving average (MA) is a stock indicator commonly used in technical analysis, used to help smooth out price data by creating a constantly updated average price. A rising moving average indicates that the security is in an uptrend, while a declining moving average indicates a downtrend.

How do I find 200 DMA of a stock?

A 200-day moving average is derived by adding the closing prices of any security over the last 200 days, then dividing by 200. When stocks trade below their 200-day moving average, it signifies a long-term downward trend. Whereas it is above the 200 DMA then reflects a long term upward trend.


1 Answers

To expand on @Ric ky's answer, the trick here is to get to a range so the average math can be performed on it.

For this working answer:

=AVERAGE(INDEX(GoogleFinance("GOOG","all",WORKDAY(TODAY(),-200),TODAY()),,3))

Here's why it works:

=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 ) )

A visual:

enter image description here

like image 193
Ray Shan Avatar answered Oct 22 '22 09:10

Ray Shan