eslint
This commit is contained in:
parent
d85cd58acd
commit
597c6efc9b
91 changed files with 2224 additions and 1400 deletions
|
|
@ -9,7 +9,7 @@ import { OHLCVData } from './index';
|
|||
* Simple Moving Average
|
||||
*/
|
||||
export function sma(values: number[], period: number): number[] {
|
||||
if (period > values.length) return [];
|
||||
if (period > values.length) {return [];}
|
||||
|
||||
const result: number[] = [];
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ export function sma(values: number[], period: number): number[] {
|
|||
* Exponential Moving Average
|
||||
*/
|
||||
export function ema(values: number[], period: number): number[] {
|
||||
if (period > values.length) return [];
|
||||
if (period > values.length) {return [];}
|
||||
|
||||
const result: number[] = [];
|
||||
const multiplier = 2 / (period + 1);
|
||||
|
|
@ -46,7 +46,7 @@ export function ema(values: number[], period: number): number[] {
|
|||
* Relative Strength Index (RSI)
|
||||
*/
|
||||
export function rsi(prices: number[], period: number = 14): number[] {
|
||||
if (period >= prices.length) return [];
|
||||
if (period >= prices.length) {return [];}
|
||||
|
||||
const gains: number[] = [];
|
||||
const losses: number[] = [];
|
||||
|
|
@ -141,7 +141,7 @@ export function bollingerBands(
|
|||
* Average True Range (ATR)
|
||||
*/
|
||||
export function atr(ohlcv: OHLCVData[], period: number = 14): number[] {
|
||||
if (period >= ohlcv.length) return [];
|
||||
if (period >= ohlcv.length) {return [];}
|
||||
|
||||
const trueRanges: number[] = [];
|
||||
|
||||
|
|
@ -166,7 +166,7 @@ export function stochastic(
|
|||
kPeriod: number = 14,
|
||||
dPeriod: number = 3
|
||||
): { k: number[]; d: number[] } {
|
||||
if (kPeriod >= ohlcv.length) return { k: [], d: [] };
|
||||
if (kPeriod >= ohlcv.length) {return { k: [], d: [] };}
|
||||
|
||||
const kValues: number[] = [];
|
||||
|
||||
|
|
@ -193,7 +193,7 @@ export function stochastic(
|
|||
* Williams %R
|
||||
*/
|
||||
export function williamsR(ohlcv: OHLCVData[], period: number = 14): number[] {
|
||||
if (period >= ohlcv.length) return [];
|
||||
if (period >= ohlcv.length) {return [];}
|
||||
|
||||
const result: number[] = [];
|
||||
|
||||
|
|
@ -218,7 +218,7 @@ export function williamsR(ohlcv: OHLCVData[], period: number = 14): number[] {
|
|||
* Commodity Channel Index (CCI)
|
||||
*/
|
||||
export function cci(ohlcv: OHLCVData[], period: number = 20): number[] {
|
||||
if (period >= ohlcv.length) return [];
|
||||
if (period >= ohlcv.length) {return [];}
|
||||
|
||||
const typicalPrices = ohlcv.map(d => (d.high + d.low + d.close) / 3);
|
||||
const smaTP = sma(typicalPrices, period);
|
||||
|
|
@ -244,7 +244,7 @@ export function cci(ohlcv: OHLCVData[], period: number = 20): number[] {
|
|||
* Momentum
|
||||
*/
|
||||
export function momentum(prices: number[], period: number = 10): number[] {
|
||||
if (period >= prices.length) return [];
|
||||
if (period >= prices.length) {return [];}
|
||||
|
||||
const result: number[] = [];
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ export function momentum(prices: number[], period: number = 10): number[] {
|
|||
* Rate of Change (ROC)
|
||||
*/
|
||||
export function roc(prices: number[], period: number = 10): number[] {
|
||||
if (period >= prices.length) return [];
|
||||
if (period >= prices.length) {return [];}
|
||||
|
||||
const result: number[] = [];
|
||||
|
||||
|
|
@ -280,7 +280,7 @@ export function roc(prices: number[], period: number = 10): number[] {
|
|||
* Money Flow Index (MFI)
|
||||
*/
|
||||
export function mfi(ohlcv: OHLCVData[], period: number = 14): number[] {
|
||||
if (period >= ohlcv.length) return [];
|
||||
if (period >= ohlcv.length) {return [];}
|
||||
|
||||
const typicalPrices = ohlcv.map(d => (d.high + d.low + d.close) / 3);
|
||||
const moneyFlows = ohlcv.map((d, i) => typicalPrices[i] * d.volume);
|
||||
|
|
@ -317,7 +317,7 @@ export function mfi(ohlcv: OHLCVData[], period: number = 14): number[] {
|
|||
* On-Balance Volume (OBV)
|
||||
*/
|
||||
export function obv(ohlcv: OHLCVData[]): number[] {
|
||||
if (ohlcv.length === 0) return [];
|
||||
if (ohlcv.length === 0) {return [];}
|
||||
|
||||
const result: number[] = [ohlcv[0].volume];
|
||||
|
||||
|
|
@ -341,7 +341,7 @@ export function obv(ohlcv: OHLCVData[]): number[] {
|
|||
* Accumulation/Distribution Line
|
||||
*/
|
||||
export function accumulationDistribution(ohlcv: OHLCVData[]): number[] {
|
||||
if (ohlcv.length === 0) return [];
|
||||
if (ohlcv.length === 0) {return [];}
|
||||
|
||||
const result: number[] = [];
|
||||
let adLine = 0;
|
||||
|
|
@ -367,7 +367,7 @@ export function accumulationDistribution(ohlcv: OHLCVData[]): number[] {
|
|||
* Chaikin Money Flow (CMF)
|
||||
*/
|
||||
export function chaikinMoneyFlow(ohlcv: OHLCVData[], period: number = 20): number[] {
|
||||
if (period >= ohlcv.length) return [];
|
||||
if (period >= ohlcv.length) {return [];}
|
||||
|
||||
const adValues: number[] = [];
|
||||
|
||||
|
|
@ -406,7 +406,7 @@ export function parabolicSAR(
|
|||
step: number = 0.02,
|
||||
maxStep: number = 0.2
|
||||
): number[] {
|
||||
if (ohlcv.length < 2) return [];
|
||||
if (ohlcv.length < 2) {return [];}
|
||||
|
||||
const result: number[] = [];
|
||||
let trend = 1; // 1 for uptrend, -1 for downtrend
|
||||
|
|
@ -467,7 +467,7 @@ export function parabolicSAR(
|
|||
* Aroon Indicator
|
||||
*/
|
||||
export function aroon(ohlcv: OHLCVData[], period: number = 14): { up: number[]; down: number[] } {
|
||||
if (period >= ohlcv.length) return { up: [], down: [] };
|
||||
if (period >= ohlcv.length) {return { up: [], down: [] };}
|
||||
|
||||
const up: number[] = [];
|
||||
const down: number[] = [];
|
||||
|
|
@ -505,7 +505,7 @@ export function adx(
|
|||
ohlcv: OHLCVData[],
|
||||
period: number = 14
|
||||
): { adx: number[]; plusDI: number[]; minusDI: number[] } {
|
||||
if (period >= ohlcv.length) return { adx: [], plusDI: [], minusDI: [] };
|
||||
if (period >= ohlcv.length) {return { adx: [], plusDI: [], minusDI: [] };}
|
||||
|
||||
const trueRanges: number[] = [];
|
||||
const plusDM: number[] = [];
|
||||
|
|
@ -572,7 +572,7 @@ export function adx(
|
|||
* Volume Weighted Moving Average (VWMA)
|
||||
*/
|
||||
export function vwma(ohlcv: OHLCVData[], period: number = 20): number[] {
|
||||
if (period >= ohlcv.length) return [];
|
||||
if (period >= ohlcv.length) {return [];}
|
||||
|
||||
const result: number[] = [];
|
||||
|
||||
|
|
@ -607,7 +607,7 @@ export function pivotPoints(ohlcv: OHLCVData[]): Array<{
|
|||
support2: number;
|
||||
support3: number;
|
||||
}> {
|
||||
if (ohlcv.length === 0) return [];
|
||||
if (ohlcv.length === 0) {return [];}
|
||||
|
||||
const result: Array<{
|
||||
pivot: number;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue