stock-indicators/example/simple.js
2025-03-31 11:20:04 +02:00

24 lines
714 B
JavaScript
Executable File

'use strict';
import Indicator from '../index.js';
let run = async () => {
try {
let lwma = new Indicator.LWMA({ periods: 4 });
let bb = new Indicator.BB({ periods: 4 });
let data = [25.5, 26.75, 27.0, 26.5, 27.25];
lwma.setValues(data);
bb.setValues(data);
let lwmaCollection = await lwma.calculate();
let bbCollection = await bb.calculate();
for (let i = 0, len = lwmaCollection.length; i < len; i++) {
console.log(`Price: ${lwmaCollection[i].price}, LWMA: ${lwmaCollection[i].lwma}, BB Upper: ${bbCollection[i].upper}`);
}
}
catch (err) {
console.log(err.message);
}
};
run();