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?
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.
Syntax for this function is as follows: AVERAGE(value1, [value2, ...]) Here, value1 is the first value to consider in the average calculation.
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.
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With