Node's Pastoral Musicians

    ta.web

    1.15.3 • Public • Published

    Technical Analysis (ta.web)

    ta.web is a react compatible version of ta.js (https://github.com/Bitvested/ta.js). Not all ta.js functions are compatible with this version!

    Installation

    NPM

    Use the package manager npm to install ta.web.

    npm install ta.web --save

    Usage

    import ta from 'ta.web';

    Examples

    Moving Averages

    Indicators

    Oscillators

    Bands

    Statistics

    Random functions

    Chart Types

    Miscellaneous

    Experimental

    Moving Averages

    Simple Moving Average (SMA)

    var data = [1, 2, 3, 4, 5, 6, 10];
    var length = 6; // default = 14
    await ta.sma(data, length);
    // output (array)
    // [3.5, 5]

    Smoothed Moving Average (SMMA)

    var data = [1, 2, 3, 4, 5, 6, 10];
    var length = 5; // default = 14
    await ta.smma(data, length);
    // output (array)
    // [3.4, 4.92]

    Weighted Moving Average (WMA)

    var data = [69, 68, 66, 70, 68];
    var length = 4; // default = 14
    await ta.wma(data, length);
    // output (array)
    // [68.3, 68.2]

    Exponential Moving Average (EMA)

    var data = [1, 2, 3, 4, 5, 6, 10];
    var length = 6; // default = 12
    await ta.ema(data, length);
    // output (array)
    // [3.5, 5.357]

    Hull Moving Average

    var data = [6, 7, 5, 6, 7, 4, 5, 7];
    var length = 6; // default = 14
    await ta.hull(data, length);
    // output (array)
    // [4.76, 5.48]

    Least Squares Moving Average (LSMA)

    var data = [5, 6, 6, 3, 4, 6, 7];
    var length = 6; // default = 25
    await ta.lsma(data, length);
    // output (array)
    // [4.714, 5.761]

    Volume Weighted Moving Average (VWMA)

    var data = [[1, 59], [1.1, 82], [1.21, 27], [1.42, 73], [1.32, 42]]; // [price, volume (quantity)]
    var length = 4; // default = 20
    await ta.vwma(data, length);
    // output (array)
    // [1.185, 1.259]

    Volume Weighted Weighted Moving Average

    var data = [[1,59],[1.1,82],[1.21,27],[1.42,73],[1.32,42]]; // [price, volume]
    var length = 4;
    await ta.vwwma(data, length);
    // output (array)
    // [1.262, 1.316]

    Wilder's Smoothing Moving Average

    var data = [1, 2, 3, 4, 5, 6, 10];
    var length = 6; // default = 14
    await ta.wsma(data, length);
    // output (array)
    // [3.5, 4.58]

    Parabolic Weighted Moving Average

    var data = [17, 26, 23, 29, 20];
    var length = 4; // default = 14
    await ta.pwma(data, length);
    // output (array)
    // [24.09, 25.18]

    Hyperbolic Weighted Moving Average

    var data = [54, 51, 86, 42, 47];
    var length = 4; // default = 14
    await ta.hwma(data, length);
    // output (array)
    // [56.2, 55.0]

    Kaufman Adaptive Moving Average (KAMA)

    var data = [8, 7, 8, 9, 7, 9];
    var length1 = 2; // default = 10
    var length2 = 4; // default = 2
    var length3 = 8; // default = 30
    await ta.kama(data, length1, length2, length3);
    // output (array)
    // [8, 8.64, 8.57, 8.57]

    Custom Weighted Moving Average

    var data = [69,68,66,70,68,69];
    var weights = [1,2,3,5,8];
    await ta.cwma(data, weights);
    // output (array)
    // [68.26315789473684, 68.52631578947368]

    Indicators

    Moving Average Convergence / Divergence (MACD)

    var data = [1, 2, 3, 4, 5, 6, 14];
    var length1 = 3; // default = 12
    var length2 = 6; // default = 26
    await ta.macd(data, length1, length2);
    // output (array)
    // [1.5, 3]

    MACD Signal

    var data = [1, 2, 3, 4, 5, 6, 14, 8, 10, 11];
    var length1 = 3;
    var length2 = 6;
    var signal_length = 3;
    await ta.macd_signal(data, length1, length2, signal_length);
    // output (array)
    // [2.107, 1.838, 1.653]

    MACD Bars

    var data = [1, 2, 3, 4, 5, 6, 14, 8, 10, 11];
    var length1 = 3;
    var length2 = 6;
    var signal_length = 3;
    await ta.macd_bars(data, length1, length2, signal_length);
    // output (array)
    // [-0.286, -0.269, -0.184]

    Relative Strength Index (RSI)

    var data = [1, 2, 3, 4, 5, 6, 7, 5];
    var length = 6; // default = 14
    await ta.rsi(data, length);
    // output (array)
    // [100.0, 100.0, 66.667]

    Wilder's Relative Strength Index

    var data = [1, 2, 3, 4, 5, 6, 7, 5, 6];
    var length = 6; // default = 14
    await ta.wrsi(data, length);
    // output (array)
    // [100, 71.43, 75.61]

    True Strength Index (TSI)

    var data = [1.32, 1.27, 1.42, 1.47, 1.42, 1.45, 1.59];
    var longlength = 3; // default = 25
    var shortlength = 2; // default = 13
    var signallength = 2; // default = 13
    await ta.tsi(data, longlength, shortlength, signallength);
    // output (array)
    // [[0.327, 0.320], [0.579, 0.706]]
    // [strength line, signal line]

    Balance Of Power

    var data = [[4, 5, 4, 5], [5, 6, 5, 6], [6, 8, 5, 6]]; // [open, high, low, close]
    var length = 2; // default = 14
    await ta.bop(data, length);
    // output (array)
    // [1, 0.5]

    Force Index

    var data = [[1.4, 200], [1.5, 240], [1.1, 300], [1.2, 240], [1.5, 400]]; // [close, volume]
    var length = 4; // default = 13
    await ta.fi(data, length);
    // output (array)
    // [0.0075]

    Accumulative Swing Index

    var data = [[7, 6, 4], [9, 7, 5], [9, 8, 6]]; // [high, close, low]
    await ta.asi(data);
    // output (array)
    // [0, -12.5]

    Alligator Indicator

    var data = [8,7,8,9,7,8,9,6,7,8,6,8,10,8,7,9,8,7,9,6,7,9];
    // defaults shown
    var jawlength = 13;
    var teethlength = 8;
    var liplength = 5;
    var jawshift = 8;
    var teethshift = 5;
    var lipshift = 3;
    await ta.alligator(data, jawlength, teethlength, liplength, jawshift, teethshift, lipshift);
    // output (array)
    // [jaw, teeth, lips]

    Williams %R

    var data = [2, 1, 3, 1, 2];
    var length = 4; // default = 14
    await ta.pr(data, length);
    // output (array)
    // [-0, -100, -50]

    Stochastics

    var data = [[3,2,1], [2,2,1], [4,3,1], [2,2,1]]; // [high, close, low]
    var length = 2; // default = 14
    var smoothd = 1; // default = 3
    var smoothk = 1; // default = 3
    await ta.stoch(data, length, smoothd, smoothk);
    // output (array)
    // [[66.667, 66.667], [33.336, 33.336]]
    // [kline, dline]

    Fibonacci Retracement

    var start = 1;
    var end = 2;
    await ta.fib(start, end);
    // output (array)
    // [1, 1.236, 1.382, 1.5, 1.618, 1.786, 2, 2.618, 3.618, 4.618, 5.236]

    Bollinger Bandwidth

    var data = [1, 2, 3, 4, 5, 6];
    var length = 5; // default = 14
    var deviations = 2; // default = 1
    await ta.bandwidth(data, length, deviations);
    // output (array)
    // [1.886, 1.344]

    Ichimoku Cloud

    var data = [[6, 3, 2], [5, 4, 2], [5, 4, 3], [6, 4, 3], [7, 6, 4], [6, 5, 3]]; // [high, close, low]
    var length1 = 9; // default = 9
    var length2 = 26; // default = 26
    var length3 = 52; // default = 52
    var displacement = 26; // default = 26
    await ta.ichimoku(data, length1, length2, length3, displacement);
    // output (array)
    // [conversion line, base line, leading span A, leading span B, lagging span]

    Average True Range (ATR)

    var data = [[3,2,1], [2,2,1], [4,3,1], [2,2,1]]; // [high, close, low]
    var length = 3; // default = 14
    await ta.atr(data, length);
    // output (array)
    // [2, 1.667, 2.111, 1.741]

    Aroon Up

    var data = [5, 4, 5, 2];
    var length = 3; // default = 10
    await ta.aroon.up(data, length);
    // output (array)
    // [100, 50]

    Aroon Down

    var data = [2, 5, 4, 5];
    var length = 3; // default = 10
    await ta.aroon.down(data, length);
    // output (array)
    // [0, 50]

    Money Flow Index

    var data = [[19, 13], [14, 38], [21, 25], [32, 17]]; // [buy volume, sell volume]
    var length = 3; // default = 14
    await ta.mfi(data, length);
    // output (array)
    // [41.54, 45.58]

    Rate Of Change

    var data = [1, 2, 3, 4];
    var length = 3; // default = 14
    await ta.roc(data, length);
    // output (array)
    // [2, 1]

    Coppock Curve

    var data = [3, 4, 5, 3, 4, 5, 6, 4, 7, 5, 4, 7, 5];
    var length1 = 4; // (ROC period 1) default = 11
    var length2 = 6; // (ROC period 2) default = 14
    var length3 = 5; // (WMA smoothing period) default = 10
    await ta.cop(data, length1, length2, length3);
    // output (array)
    // [0.376, 0.237]

    Know Sure Thing

    var data = [8, 6, 7, 6, 8, 9, 7, 5, 6, 7, 6, 8, 6, 7, 6, 8, 9, 9, 8, 6, 4, 6, 5, 6, 7, 8, 9];
    // roc sma #1
    var r1 = 5; // default = 10
    var s1 = 5; // default = 10
    // roc sma #2
    var r2 = 7; // default = 15
    var s2 = 5; // default = 10
    // roc sma #3
    var r3 = 10; // default = 20
    var s3 = 5; // default = 10
    // roc sma #4
    var r4 = 15; // default = 30
    var s4 = 7; // default = 15
    // signal line
    var sig = 4; // default = 9
    await ta.kst(data, r1, r2, r3, r4, s1, s2, s3, s4, sig);
    // output (array)
    // [[-0.68, -0.52], [-0.29, -0.58], [0.35, -0.36]]
    // [kst line, signal line]

    On-Balance Volume

    var data = [[25200, 10], [30000, 10.15], [25600, 10.17], [32000, 10.13]]; // [asset volume, close price]
    await ta.obv(data);
    // output (array)
    // [0, 30000, 55600, 23600]

    Volume-Weighted Average Price

    var data = [[127.21, 89329], [127.17, 16137], [127.16, 23945]]; // [average price, volume (quantity)]
    var length = 2; // default = data.length
    await ta.vwap(data, length);
    // output (array)
    // [127.204, 127.164]

    Fractals

    var data = [[7,6],[8,6],[9,6],[8,5],[7,4],[6,3],[7,4],[8,5]]; // [high, low]
    await ta.fractals(data);
    // output (array, same length as input)
    // [[false, false],[false,false],[true,false],[false,false],[false,false],[false,true],[false,false],[false,false]]
    // [upper fractal, lower fractal]

    Crossover (golden cross)

    var fastdata = [3,4,5,4,3]; // short period gets spliced when longer
    var slowdata = [4,3,2,3,4];
    await ta.cross(fastdata, slowdata);
    // output (array)
    // [{index: 1, cross true}, {index: 4, cross: false}]
    // cross is true when fastdata is greater than the slowdata

    Momentum

    var data = [1, 1.1, 1.2, 1.24, 1.34];
    var length = 4; // default = 10
    var percentage = false; // default = false (true returns percentage)
    await ta.mom(data, length, percentage);
    // output (array)
    // [0.24, 0.24]

    HalfTrend

    // experimental (untested) function (may change in the future), ported from:
    // https://www.tradingview.com/script/U1SJ8ubc-HalfTrend/
    // data = [high, close, low]
    var data = [[100,97,90],[101,98,94],[103,96,92],[106,100,95],[110,101,100],[112,110,105],[110,100,90],[103,100,97],[95,90,85],[94,80,80],[90,82,81],[85,80,70]];
    var atrlen = 6;
    var amplitude = 3;
    var deviation = 2;
    await ta.halftrend(data, atrlen, amplitude, deviation);
    // output (array)
    // [[high, halftrend, low, signal]]

    ZigZag

    // Based on high / low
    var data = [[10,9], [12,10], [14,12], [15,13], [16,15], [11,10], [18,15]]; // [high, low]
    var percentage = 0.25; // default = 0.05
    await ta.zigzag(data, percentage);
    // output (array)
    // [9, 10.75, 12.5, 14.25, 16, 10, 18]
    // Based on close
    var data = [6,7,8,9,10,12,9,8,5,3,3,3,5,7,8,9,11];
    var percentage = 0.05;
    await ta.zigzag(data, percentage);
    // output (array)
    // [6, 7.2, 8.4, 9.6, 10.8, 12.0, 10.5, 9.0, 7.5, 6.0, 4.5, 3.0, 4.6, 6.2, 7.8, 9.4, 11.0]

    Parabolic SAR

    var data = [[82.15,81.29],[81.89,80.64],[83.03,81.31],[83.30,82.65],[83.85,83.07],[83.90,83.11],[83.33,82.49],[84.30,82.3],[84.84,84.15],[85,84.11],[75.9,74.03],[76.58,75.39],[76.98,75.76],[78,77.17],[70.87,70.01]];
    var step = 0.02;
    var max = 0.2;
    await ta.psar(data, step, max);
    // output (array)
    // [81.29,82.15,80.64,80.64,80.7464,80.932616,81.17000672,81.3884061824,81.67956556416,82.0588176964608,85,85,84.7806,84.565588,84.35487624000001]

    SuperTrend

    var data = [[3,2,1], [2,2,1], [4,3,1], [2,2,1]] // [high, close, low]
    var length = 3; // default = 20
    var multiplier = 0.5; // default = 3
    await ta.supertrend(data, length, multiplier);
    // output (array)
    // [[5.56,1.44],[3.37,0.63]]
    // [up, down]

    Elder Ray Index

    var data = [6,5,4,7,8,9,6,8];
    var length = 7;
    await ta.elderray(data, length);
    // output (array)
    // [[2.57,-2.43],[2.29,-2.71]]
    // [bull, bear]

    Historical Volatility

    var data = [7,6,5,7,8,9,7,6,5];
    var length = 8;
    await ta.hv(data, length);
    // output (array)
    // [0.642, 0.682]

    Relative Vigor Index

    // data = [[open,high,low,close]] (requires at least 4 + length values)
    var data = [[4,6,3,3], [3,5,2,2], [2,5,2,4], [4,6,4,5], [5,7,4,4], [4,6,3,4], [4,7,3,5], [5,7,5,6], [6,8,6,6], [6,9,5,6], [6,8,6,7], [7,9,5,6],[6,7,4,5],[5,6,5,6],[6,8,5,5],[5,7,2,6]];
    var length = 8;
    await ta.rvi(data, length);
    // output (array)
    // [0.29,0.21,0.15,0.16,0.09,0.05]

    Relative Vigor Index Signal

    var rvi = [0.29,0.21,0.15,0.16,0.09,0.05]; // requires at least 4 values
    await ta.rvi_signal(rvi);
    // output (array)
    // [0.20,0.15,0.12]

    RSI Divergence

    Experimental function: https://github.com/Bitvested/ta.js/issues/18

    var data = [74,83,66,78,69,70,84,73,74,73,83];
    var rsi_length = 5;
    var rsi_function = ta.wrsi; // default (the tradingview rsi indicator)
    await ta.rsi_divergence(data, rsi_length, rsi_function);
    // output (array)
    // 1 = RSI is in divergence
    // 0 = RSI is not in divergence
    // [0, 0, 1, 0, 1, 0] (better to quantify if needed)

    Universal Divergence

    var data1 = [48,34,43,54,56,64,43];
    var data2 = [76,74,43,55,34,32,45,47];
    await ta.divergence(data1, data2);
    // output (array)
    // 1 = RSI is in divergence
    // 0 = RSI is not in divergence
    // [0, 0, 1, 1, 0, 1] (better to quantify if needed)

    Oscillators

    Alligator Oscillator

    var data = [8,7,8,9,7,8,9,6,7,8,6,8,10,8,7,9,8,7,9,6,7,9];
    // defaults shown
    var jawlength = 13;
    var teethlength = 8;
    var liplength = 5;
    var jawshift = 8;
    var teethshift = 5;
    var lipshift = 3;
    await ta.gator(data, jawlength, teethlength, liplength, jawshift, teethshift, lipshift);
    // output (array)
    // [upper gator, lower gator]

    Chande Momentum Oscillator

    var data = [1, 1.2, 1.3, 1.3, 1.2, 1.4];
    var length = 4; // default = 9
    await ta.mom_osc(data, length);
    // output (array)
    // [0, 3.85]

    Chaikin Oscillator

    var data = [[2,3,4,6],[5,5,5,4],[5,4,3,7],[4,3,3,4],[6,5,4,6],[7,4,3,6]]; // [high, close, low, volume]
    var length1 = 2; // default = 3
    var length2 = 4; // default = 10
    await ta.chaikin_osc(data, length1, length2);
    // output (array)
    // [-1.667, -0.289, -0.736]

    Aroon Oscillator

    var data = [2, 5, 4, 5];
    var length = 3; // default = 25
    await ta.aroon.osc(data, length);
    // output (array)
    // [50, 50]

    Awesome Oscillator

    var data = [[6, 5], [8, 6], [7, 4], [6, 5], [7, 6], [9, 8]]; // [high, low]
    var shortlength = 2; // default = 5
    var longlength = 5; // default = 35
    await ta.ao(data, shortlength, longlength);
    // output (array)
    // [0, 0.9]

    Accelerator Oscillator

    var data = [[6, 5], [8, 6], [7, 4], [6, 5], [7, 6], [9, 8]]; // [high, low]
    var shortlength = 2; // default = 5
    var longlength = 4; // default = 35
    await ta.ac(data, shortlength, longlength);
    // output (array)
    // [-5.875, -6.125, -6.5]

    Fisher Transform

    var data = [8,6,8,9,7,8,9,8,7,8,6,7]; // high + low / 2
    var length = 9;
    await ta.fisher(data, length);
    // output (array)
    // [[-0.318, -0.11], [-0.449, -0.318], [-0.616, -0.449]] // [fisher, trigger]

    Bands

    Bollinger Bands

    var data = [1, 2, 3, 4, 5, 6];
    var length = 5; // default = 14
    var deviations = 2; // default = 1
    await ta.bands(data, length, deviations);
    // output (array)
    // [[5.828, 3, 0.172], [6.828, 4, 1.172]]
    // [upper band, middle band, lower band]

    Keltner Channels

    var data = [[3,2,1], [2,2,1], [4,3,1], [2,2,1], [3,3,1]]; // [high, close, low]
    var length = 5; // default = 14
    var deviations = 1; // default = 1
    await ta.keltner(data, length, deviations);
    // output (array)
    // [[3.93, 2.06, 0.20]]
    // [upper band, middle band, lower band]

    Donchian Channels

    var data = [[6, 2], [5, 2], [5, 3], [6, 3], [7, 4], [6, 3]]; // [high, low]
    var length = 5; // default = 20
    await ta.don(data, length);
    // output (array)
    // [[7, 4.5, 2], [7, 4.5, 2]]
    // [upper band, base line, lower band]

    Fibonacci Bollinger Bands

    // created from: https://tradingview.com/script/qIKR3tbN-Fibonacci-Bollinger-Bands/
    var data = [[1,59],[1.1,82],[1.21,27],[1.42,73],[1.32,42]]; // [price, volume]
    var length = 4; // default = 20
    var deviations = 3; // default = 3
    await ta.fibbands(data, length, deviations);
    // output (array)
    // [[highest band -> fibonacci levels -> lowest band]]

    Envelope

    var data = [6,7,8,7,6,7,8,7,8,7,8,7,8];
    var length = 11, // default = 10
    var percentage = 0.05; // default = 0.005
    await ta.envelope(data, length, percentage);
    // output (array)
    // [[7.541, 7.182, 6.823], [7.636, 7.273, 6.909]]
    // [upper band, base line, lower band]

    Statistics

    Standard Deviation

    var data = [1, 2, 3];
    var length = 3; // default = data.length
    await ta.std(data, length);
    // output (float)
    // 0.81649658092773

    Variance

    var data = [6, 7, 2, 3, 5, 8, 6, 2];
    var length = 7; // default = data.length
    await ta.variance(data, length);
    // output (array)
    // [3.918, 5.061]

    Inverse Normal Distribution

    var data = 0.4732;
    await ta.normsinv(data);
    // output (float)
    // -0.06722824471054376

    Monte Carlo Simulation

    var data = [6, 4, 7, 8, 5, 6];
    var length = 2; // default = 50
    var simulations = 100; // default = 1000
    var percentile = 0.5; // default = undefined (returns all raw simulations)
    await ta.sim(data, length, simulations, percentile);
    // output (array)
    // [6, 4, 7, 8, 5, 6, 5.96, 5.7]

    Percentile

    var data = [[6,4,7], [5,3,6], [7,5,8]];
    var percentile = 0.5;
    await ta.percentile(data, percentile);
    // output (array)
    // [6, 4, 7]

    Correlation

    var data1 = [1, 2, 3, 4, 5, 2];
    var data2 = [1, 3, 2, 4, 6, 3];
    await ta.cor(data1, data2);
    // output (float)
    // 0.8808929232684737

    Percentage Difference

    var newval = 0.75;
    var oldval = 0.5;
    await ta.dif(newval, oldval);
    // output (float)
    // 0.5

    Expected Return

    var data = [0.02, -0.01, 0.03, 0.05, -0.03]; // historical return data
    await ta.er(data);
    // output (float)
    // 0.0119

    Abnormal Return

    var data = [0.02, -0.01, 0.03, 0.05, -0.03]; // historical return data
    var length = 3;
    await ta.ar(data, length);
    // output (array)
    // [0.037, -0.053]

    Kelly Criterion

    var data = [0.01, 0.02, -0.01, -0.03, -0.015, 0.045, 0.005];
    await ta.kelly(data);
    // output (float)
    // 0.1443

    Martingale

    var data = [-1,-1,1,1,-1,-1]; // win or loss (> 0 || < 0)
    var bet = 5;
    var max = 20;
    var multiplier = 2; // default = 2
    await ta.martingale(data, bet, max, multiplier);
    // output (float)
    // 20

    Anti-Martingale

    var data = [1,1,-1,-1,1,1]; // win or loss (> 0 || < 0)
    var bet = 5;
    var max = 20;
    var multiplier = 2; // default = 2
    await ta.antimartingale(data, bet, max, multiplier);
    // output (float)
    // 20

    Permutations

    var data = [10,10,10];
    await ta.permutations(data);
    // output (int)
    // 1000

    Winratio

    var data = [0.01, 0.02, -0.01, -0.03, -0.015, 0.005];
    await ta.winratio(data);
    // output (float)
    // 0.5

    Average Win

    var data = [0.01, 0.02, -0.01, -0.03, -0.015, 0.005];
    await ta.avgwin(data);
    // output (float)
    // 0.012

    Average Loss

    var data = [0.01, 0.02, -0.01, -0.03, -0.015, 0.005];
    await ta.avgloss(data);
    // output (float)
    // -0.018

    Drawdown

    var data = [1, 2, 3, 4, 2, 3];
    await ta.drawdown(data);
    // output (float)
    // -0.5

    Median

    var data = [4, 6, 3, 1, 2, 5];
    var length = 4; // default = data.length
    await ta.median(data, length);
    // output (array)
    // [3, 2, 2]

    Recent High

    var data = [4,5,6,7,8,9,8,7,8,9,10,3,2,1];
    var lookback = 3; // No higher values after 3 periods? resets after each new high
    await ta.recent_high(data, lookback);
    // output (object)
    // {index: 10, value: 10}

    Recent Low

    var data = [1,4,5,6,4,3,2,3,4,3,5,7,8,8,5];
    var lookback = 4; // No lower values after 4 periods? resets after each new low
    await ta.recent_low(data, lookback);
    // output (object)
    // {index: 6, value: 2}

    Median Absolute Deviation

    var data = [3, 7, 5, 4, 3, 8, 9];
    var length = 6; // default = data.length
    await ta.mad(data, length);
    // output (array)
    // [1, 2]

    Average Absolute Deviation

    var data = [4, 6, 8, 6, 8, 9, 10, 11];
    var length = 7; // default = data.length
    await ta.aad(data, length);
    // output (array)
    // [1.673, 1.468]

    Standard Error

    var data = [34, 54, 45, 43, 57, 38, 49];
    var size = 10; // default = data.length
    await ta.se(data, size);
    // output (float)
    // 2.424

    Sum Squared Differences

    var data = [7, 6, 5, 7, 9, 8, 3, 5, 4];
    var length = 7; // default = data.length
    await ta.ssd(data, length);
    // output (array)
    // [4.87, 4.986, 5.372]

    Logarithm

    var data = [5, 14, 18, 28, 68, 103];
    await ta.log(data);
    // output (array)
    // [1.61, 2.64, 2.89, 3.33, 4.22, 4.63]

    Exponent

    var data = [1.6, 2.63, 2.89, 3.33, 4.22, 4.63];
    await ta.exp(data);
    // output (array)
    // [4.95, 13.87, 17.99, 27.94, 68.03, 102.51]

    Normalize

    var data = [5,4,9,4];
    var margin = 0.1; // margin % (default = 0)
    await ta.normalize(data, margin);
    // output (array)
    // [0.22, 0.06, 0.86, 0.06]

    Denormalize

    var data = [5,4,9,4]; // original data || [highest, lowest]
    var norm = [0.22, 0.06, 0.86, 0.06, 0.44]; // normalized data
    var margin = 0.1; // margin % (default = 0)
    await ta.denormalize(data, norm, margin);
    // output (array)
    // [5 ,4, 9, 4, 6.4]

    Normalize Pair

    var pair1 = [10,12,11,13];
    var pair2 = [100,130,100,140];
    await ta.normalize_pair(pair1, pair2);
    // output (array)
    // [[55, 55], [66, 71.5], [60.5, 54.99], [71.5, 76.99]]

    Normalize From

    var data = [8, 12, 10, 11];
    var baseline = 100;
    await ta.normalize_from(data, baseline);
    // output (array)
    // [100, 150, 125, 137.5]

    Standardize

    var data = [6,4,6,8,6];
    await ta.standardize(data);
    // output (array)
    // [0, -1.581, 0, 1.581, 0]

    Z-Score

    var data = [34,54,45,43,57,38,49];
    var length = 5;
    await ta.zscore(data, length);
    // output (array)
    // [1.266, -1.331, 0.408]

    P-Value

    var t_stat = 2;
    var df = 4;
    await ta.pvalue(t_stat, df);
    // output (float)
    // 0.075

    K-means Clustering

    var data = [2, 3, 4, 5, 3, 5, 7, 8, 6, 8, 6, 4, 2, 6];
    var length = 4;
    await ta.kmeans(data, length);
    // output (array)
    // [[ 4, 5, 5, 4 ], [ 7, 6, 6, 6 ], [ 8, 8 ], [ 2, 3, 3, 2 ]]

    Mean Squared Error

    var data1 = [7,8,7,8,6,9];
    var data2 = [6,8,8,9,6,8];
    await ta.mse(data1, data2);
    // output (float)
    // 0.6666666666666666

    Cumulative

    var data = [3,5,7,5,10];
    var length = 4;
    await ta.cum(data, length);
    // output (array)
    // [20, 27]

    Random Functions

    Pseudo Random Number Generator

    var seed = "abcdefg"; // string || number
    var prng = ta.random.prng(seed);
    console.log(prng());
    // output (float)
    // 0.9100735441315919

    Pick Random

    var data = ['a', 'b', 'c'];
    var prng = ta.random.prng('abcdefg');
    ta.random.pick(data, prng); // default number generator = Math.random
    // output (array element)
    // 'c'

    Random Range

    var min = 10;
    var max = 50;
    var prng = ta.random.prng('abcdefg');
    ta.random.range(min, max, prng); // default number generator = Math.random
    // output (int)
    // 46

    Random Float

    var min = 1.4;
    var max = 2.8;
    var prng = ta.random.prng('abcdefg');
    ta.random.float(min, max, prng); // default number generator = Math.random
    // output (float)
    // 2.6741029617842287

    Random Order

    var data = ['a','b','c','d','e'];
    var prng = ta.random.prng('abcdefg');
    ta.random.order(data, prng); // default number generator = Math.random
    // output (array)
    // ['e', 'c', 'b', 'd', 'a'];

    Chart Types

    Heikin Ashi

    var data = [[3, 4, 2, 3], [3, 6, 3, 5], [5, 5, 2, 3]]; // [open, high, low, close]
    await ta.ha(data);
    // output (array)
    // [open, high, low, close]
    // first 7-10 candles are unreliable

    Renko

    var data = [[8, 6], [9, 7], [9, 8]]; // [high, low]
    var bricksize = 3;
    await ta.ren(data, bricksize);
    // output (array)
    // [open, high, low, close]

    Miscellaneous

    Fibonacci Sequence

    ta.fibnumbers;
    // output (array)
    // [0, 1, 1, 2, 3, 5, 8...];

    Times Up

    var data = [5,6,7,8,7,6,5];
    var length = 3;
    await ta.times_up(data, length);
    // output (array)
    // [1, 0, 0, 0]

    Times Down

    var data = [5,6,7,8,7,6,5];
    var length = 3;
    await ta.times_down(data, length);
    // output (array)
    // [0, 0, 0, 1]

    Experimental Functions

    Support Line

    var data = [4,3,2,5,7,6,5,4,7,8,5,4,6,7,5];
    var start = {index: 2, value: 2}; // default = recent_low(data, 25);
    var support = await ta.support(data, start);
    // output (object)
    // support.calculate = function(x) // calculates line at position x from start.index (= 0)
    // support.slope = delta y per x
    // support.lowest = lowest (start) value at x = 0
    // support.index = (start) index of the lowest value
    // to get the line at the current candle / chart period
    var current = await support.calculate(data.length-support.index);

    Resistance Line

    var data = [5,7,5,5,4,6,5,4,6,5,4,3,2,4,3,2,1];
    var start = {index: 1, value: 7}; // default = recent_high(data, 25);
    var resistance = await ta.resistance(data, start);
    // output (object)
    // resistance.calculate = function(x) // calculates line at position x from start.index (= 0)
    // resistance.slope = delta y per x
    // resistance.highest = highest (start) value
    // resistance.index = (start) index of highest value
    // to get the line at the current candle / chart period
    var current = await resistance.calculate(data.length-resistance.index);

    Contributing

    Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

    Please make sure to update tests as appropriate.

    License

    MIT

    Keywords

    none

    Install

    npm i ta.web

    DownloadsWeekly Downloads

    9

    Version

    1.15.3

    License

    MIT

    Unpacked Size

    87.8 kB

    Total Files

    4

    Last publish

    Collaborators

    • vultwo