TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published


A javascript technical indicators written in javascript.


Node.js versions >= 6.4

npm install --save technicalindicators
const SMA = require('technicalindicators').SMA;

Node.js versions < 6.4

npm install --save babel-polyfill
npm install --save technicalindicators
const SMA = require('technicalindicators/dist/browser').SMA;


Make sure you have the following in your config file.

module.exports = {
  resolve: {
    mainFields: ["module", "main"]


For browser install using bower or npm, but it is necessary to include the babel-polyfill otherwise you will get an error. For example see index.html

npm install --save technicalindicators
npm install --save babel-polyfill
bower install --save technicalindicators
<script src="node_modules/babel-polyfill/browser.js"></script>
<script src="bower_components/technicalindicators/browser.js"></script>

All indicators will be available in window object. So you can just use

sma({period : 5, values : [1,2,3,4,5,6,7,8,9], reversedInput : true});


SMA.calculate({period : 5, values : [1,2,3,4,5,6,7,8,9]});

Available Indicators

  1. Accumulation Distribution Line (ADL).
  2. Average Directional Index (ADX).
  3. Average True Range (ATR).
  4. Awesome Oscillator (AO).
  5. Bollinger Bands (BB).
  6. Commodity Channel Index (CCI).
  7. Force Index (FI).
  8. Know Sure Thing (KST).
  9. Moneyflow Index (MFI).
  10. Moving Average Convergence Divergence (MACD).
  11. On Balance Volume (OBV).
  12. Parabolic Stop and Reverse (PSAR).
  13. Rate of Change (ROC).
  14. Relative Strength Index (RSI).
  15. Simple Moving Average (SMA).
  16. Stochastic Oscillator (KD).
  17. Stochastic RSI (StochRSI).
  18. Triple Exponentially Smoothed Average (TRIX).
  19. Typical Price.
  20. Volume Weighted Average Price (VWAP).
  21. Exponential Moving Average (EMA).
  22. Weighted Moving Average (WMA).
  23. Wilder’s Smoothing (Smoothed Moving Average, WEMA).
  24. WilliamsR (W%R).

Pattern Detection

  1. Pattern Detection

Finds pattern in the given set of data, patterns include, DB, DT, HS, IHS, TU, TD

  const hasHeadAndShoulder = require('technicalindicators').hasHeadAndShoulder;
  hasHeadAndShoulder({values : closes})
  isTrendingUp({values : closes})

When running in browser the file model.bin present in dist/model.bin in the respository should be accessible on your server at the location at /dist/model.bin. The model is trained using 400 count of values, so try to provide values close to 400 for a reliable prediction of DB, DT, HS, IHS TD(Trending Down) and TU(Trending up) works fine even with lower values.

Chart Types

  1. Renko (renko)
  2. Heikin-Ashi (HA)

CandleStick Pattern

  1. Abandoned Baby.
  2. Bearish Engulfing Pattern.
  3. Bullish Engulfiing Pattern.
  4. Dark Cloud Cover.
  5. Downside Tasuki Gap.
  6. Doji.
  7. DragonFly Doji.
  8. GraveStone Doji.
  9. BullishHarami.
  10. Bearish Harami Cross.
  11. Bullish Harami Cross.
  12. Bullish Marubozu.
  13. Bearish Marubozu.
  14. Evening Doji Star.
  15. Evening Star.
  16. Bearish Harami.
  17. Piercing Line.
  18. Bullish Spinning Top.
  19. Bearish Spinning Top.
  20. Morning Doji Star.
  21. Morning Star.
  22. Three Black Crows.
  23. Three White Soldiers.


Search for all bullish or bearish using

var twoDayBullishInput = {
  open: [23.25,15.36],
  high: [25.10,30.87],
  close: [21.44,27.89],
  low: [20.82,14.93],
var bullish = require('technicalindicators').bullish;
bullish(twoDayBullishInput) //true


There are three ways you can use to get the indicator results.


Every indicator has a static method calculate which can be used to calculate the indicator without creating an object.

const sma = require('technicalindicators').sma;
var prices = [1,2,3,4,5,6,7,8,9,10,12,13,15];
var period = 10;
sma({period : period, values : prices})


const SMA = require('technicalindicators').SMA;
var prices = [1,2,3,4,5,6,7,8,9,10,12,13,15];
var period = 10;
SMA.calculate({period : period, values : prices})


nextValue method is used to get the next indicator value.

var sma = new SMA({period : period, values : []});
var results = [];
prices.forEach(price => {
  var result = sma.nextValue(price);


This a merge of calculate and nextValue. The usual use case would be

  1. Initialize indicator with available price value

  2. Get results for initialized values

  3. Use nextValue to get next indicator values for further tick.

    var sma = new SMA({period : period, values : prices});
    sma.getResult(); // [5.5, 6.6, 7.7, 8.9]
    sma.nextValue(16); // 10.1

    Note: Calling nextValue will not update getResult() value.


This uses regular javascript numbers, so there can be rounding errors which are negligible for a technical indicators, you can set precision by using the below config. By default there is no precision set.

const technicalIndicators = require('technicalindicators');
technicalIndicators.setConfig('precision', 10);


Create issues about anything you want to report, change of API's, or request for adding new indicators. You can also create pull request with new indicators.

Environment dependencies

Typescript: Use typescript 2.0.0 other you might get max call stack reached error.

npm install -g typescript@2.0.0

TechnicalIndicators depends on the canvas package, which requires some dependencies to be installed. You can find the instructions to do that here. If you do not install these dependencies, expect to get this error message during the installation of TechnicalIndicators:

> canvas@1.6.6 install /Users/balupton/Projects/trading/technicalindicators/node_modules/canvas
> node-gyp rebuild

./util/ line 31: pkg-config: command not found
gyp: Call to './util/ freetype' returned exit status 0 while in binding.gyp. while trying to load binding.gyp


git clone  # or use your fork
cd technicalindicators
npm run start

Running tests and getting coverage

npm test
npm run cover

Adding new indicators.

  1. Add new indicator.
  2. Add the indicator to the index.js
  3. Add the indicator to the src/index.ts
  4. Run tsc && npm test
  5. Run npm run build so it adds the indicator to the browser.js
  6. Add it to read me, with the link to the tonicdev url containing the sample.
  7. Add indicator it to keywords in package.json and bower.json
  8. Send a pull request.

To build brower and lib run this command :

npm run add-indicator

Verify Documentation

node testdocs.js
open "http://localhost:5444/testdocs.html"

Package Sidebar


npm i slz-indicators

Weekly Downloads






Unpacked Size

8.79 MB

Total Files


Last publish


  • ivoglent