linting
This commit is contained in:
parent
597c6efc9b
commit
8b5e06954a
26 changed files with 532 additions and 186 deletions
|
|
@ -9,7 +9,9 @@ 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 +27,9 @@ 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 +50,9 @@ 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 +147,9 @@ 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 +174,9 @@ 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 +203,9 @@ 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 +230,9 @@ 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 +258,9 @@ 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 +276,9 @@ 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 +298,9 @@ 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 +337,9 @@ 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 +363,9 @@ 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 +391,9 @@ 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 +432,9 @@ 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 +495,9 @@ 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 +535,9 @@ 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 +604,9 @@ 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 +641,9 @@ 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