quant-zero
Version:
Node-Quant is a powerful Node.js package for developing and testing quantitative trading strategies in cryptocurrency markets, offering tools for backtesting and performance analysis.
33 lines (27 loc) • 720 B
text/typescript
import { Indicator } from '@/lib/Indicator'
import { parseIntoRows } from '@/utils/parseOHLCV'
import ta from 'technicalindicators'
export class ATR extends Indicator {
public period: number = 14
constructor(key: string, options: ATROptions) {
super({
name: 'ATR',
key: key,
description: 'Average True Range.',
})
if(options.period) this.period = options.period
}
generate(): number[] {
const { highs, lows, closes } = parseIntoRows(this.data)
const atr = ta.ATR.calculate({
period: this.period,
high: highs,
low: lows,
close: closes,
})
return atr
}
}
export interface ATROptions {
period?: number
}