I got the Error: Cannot read property length of undefined
and dont quite understand the problem.
From the other posts of stackoverflow I figured out that the function cannot determinate the length of the parsed Object.
What I am doing is the following:
I do import historical data of e.g. google stock price with =Index(GOOGLEFINANCE("NASDAQ:GOOG";"price";HEUTE()-60;HEUTE());;2)
into my spreadsheet.
Then I calculate the 21 simple moving average from the data with =average(A128:A148)
.
Now I compare the stockprice and the 21 SMA to determinate if the Stockprice is above or under the 21 SMA. So far so good.
Last I try to write a function that counts the days above the 21 SMA starting from the latest Value.
function daysabove(input){
var output = 0;
for (var i = input.length-1;i>= 0;i--){
if (input[i][0]=="over" ){
if (input[i+1][0]=="under"){
output++;
break;
}
else {
output++;
}
} `
else {
output--;
}
}
return output;}
On the spreadsheet i call that function with =daysabove(C129:C148)
. C129 to C148 containing either above or under.
Edit: I even tried to run the function on a range that contain manually written "above" & "under" so that there is no connection to google finance. Still doesnt work.
So getting back to the question: The length or the object should be defined. Whats wrong here?
property[0] from undefined
and in the scripteditor it isproperty length of undefined
. So thats not the same error ? - user8603220