Access last N bars volume and close

I’m working on a simple Volume Weighted MACD. This will be the same algorithm as in TOS.

To do this, I need to sum the multiple of the last N bars of volume and close.

Specifically, it would look something like this…

let slowMultiple;
for (let j = 0; j < 26; j++)
slowMultiple = slowMultiple + (d.volume[j] * d.value[j]);

and so on. I think I’m not accessing the bar index correctly. Can anyone tell me what I’m doing wrong? I’m more of a server-side guy than js