I have seen other posts on this issue but with no responseâŚ
It seems as if only on moving average is possible because when I have all three I get errors saying â'whateverâMovingAverage is not a functionâ but they work individually⌠Am I right in thinking this or is there something I missing
Here is my code:
------FROM INDEX----------
indicators.hourlyMovingAverage(âBTCâ,âUSDâ,50,function(result){
console.log("HMA: ", result)});
indicators.dailyMovingAverage(âBTCâ,âUSDâ,7,function(result){
console.log("DMA: ", result)});
indicators.minuteMovingAverage(âBTCâ,âUSDâ,60,function(result){
console.log("minMA: ", result)});
-------FROM INDICATORS---------
module.exports = {
hourlyMovingAverage:function (cryptoAsset,fiatCurrency,hours,callback){
//when function in curley brackets -> functionName:functionName
if(hours>169){
console.error(âOnly up to 169 hours allowed!â)
return
}
//1get data from CC (or other)
CryptoCompareAPI.histoHour(cryptoAsset, fiatCurrency)
.then(data => {
data = data.reverse()
var sum = 0;
for(var i = 0;i<hours;i++){
sum+=data[i].close;
}
var hourlyMovingAverage = sum/hours;
callback(hourlyMovingAverage);
})
.catch(console.error)
}};
module.exports = {
dailyMovingAverage:function(cryptoAsset,fiatCurrency,days,callback){
if(days>7){
console.error("Only up to 7 days allowed!")
return
}
CryptoCompareAPI.histoDay(cryptoAsset, fiatCurrency)
.then(data => {
data = data.reverse()
var sum = 0;
for(var j = 0;j<days;j++){
sum+=data[j].close;
}
var dailyMovingAverage = sum/100;
callback(dailyMovingAverage);
})
.catch(console.error)
}}
module.exports = {
minuteMovingAverage:function(cryptoAsset,fiatCurrency,minutes,callback){
if(minutes>10080){
console.error("Only up to 10'080 minutes allowed!")
return
}
CryptoCompareAPI.histoMinute(cryptoAsset, fiatCurrency)
.then(data => {
data = data.reverse()
var sum = 0;
for(var min = 0;min<minutes;min++){
sum+=data[min].close;
}
var minuteMovingAverage=sum/minutes;
callback(minuteMovingAverage);
})
.catch(console.error)
}}