hey can someone help me please? iām having trouble with the Daily Moving Average Indicator
Everything works except the Daily MA indicator iām still getting this error on the power shell:
TypeError: Cannot read property ācloseā of undefined
at D:_WORKING_TEMP__Ivan on Tech_Academy_\Algorithmic Trading_code\indicators.js:64:22
at processTicksAndRejections (node:internal/process/task_queues:94:5)
// DAILY MA (MOVING AVERAGE) BLOCK-START // THIS IS LINE 51
DailyMA:function(cryptoAsset, fiatCurrency, days, callback){
if(days>365){
console.error("Error: Only up to 365 days allowed!")
return
}
// fetching data from CryptoCompare API
CryptoCompareAPI.histoDay(cryptoAsset, fiatCurrency)
.then(data => {
// calculate MA from past hours
data = data.reverse()
var sum = 0;
for(var i = 0; i<days; i++){
sum+=data[i].close;
}
var Days_movingAverage = sum/days;
callback(Days_movingAverage)
})
.catch(console.error); // listen for any errors
}, // DAILY MA (MOVING AVERAGE) BLOCK-END //THIS WOULD BE LINE 70
so exactly, the error is sending me to this line (after reversing de data)
specifically, its refering to ā.closeā
so what to do with this?? I have no clue
sum+=data[i].close;
my best guess is that i need to tell the DailyMA function to fetch the last unix timestamp avaliable (meaning everything exluiding today) ?? but i have no idea on how to exactly do thatā¦ plz helps?
-
toTs
(Number) Last unix timestamp to return data for.
-
limit
(Number | 'none'
) Limit the number of days to lookup. Default is 30. If you set it to the string 'none'
, you will get all available data.
removing the DailyMA indicator makes everything work fine (Iām starting video 25 āscripting gemini buy bitcoin shortcutā so basically everything works fine, just this indicator has been giving me trouble)