@showr/indicators
Version:
Technical indicators for Trading made with Showr
19 lines (18 loc) • 650 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const getAverageGain = (array, period) => {
const datasetLength = array.length;
const requiredLength = period + 1;
if (datasetLength < requiredLength) {
return undefined;
}
let averageGain = 0;
for (let i = datasetLength - 2; i > datasetLength - requiredLength; i--) {
const currentValue = array[i];
const previousValue = array[i - 1];
const difference = currentValue - previousValue;
averageGain += difference > 0 ? difference : 0;
}
return averageGain / period;
};
exports.default = getAverageGain;