thanks @thecil you have been most comprehensive tutor here at the academy. I already noticed my mistake, nice implementation you have by the way, very respectful of all the conventions (the fact that you start with an underline all of the variables of a function, and you use async) … However, I found a new inconvenient when doing the minutely and daily MA. I cannot get the daily MA to work, I have tried starting from i=1 or finishing when i+1<days , thinking that as the last day is not closed, maybe tha property is still undefined… PLease help, here is the error and the code (I lonly put the daily MA code, since all the others are working fine now)
javier@javier-MACHC-WAX9:~/tradingBot$ node index.js
TypeError: Cannot read property 'close' of undefined
at /home/javier/tradingBot/indicators.js:41:22
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Hourly MA: 32535.032400000007
Minuteley MA: 35501.647
dailyMovingAverage:function (cryptoAsset, fiat, days, callback) {
if(days>169) {
console.error("only up to 169 days allowed");
return;
}
CryptoCompareAPI.histoDay(cryptoAsset, fiat)
.then(data => {
data = data.reverse()
var sum = 0;
for(var i=0; i < days; i++) {
sum+=data[i].close;
}
var movingAverage = sum/days;
callback(movingAverage);
})
.catch(console.error)
},