@wahack/technicalindicators
v3.1.1
Published
Techincal Indicators written in javascript
Downloads
86
Maintainers
Keywords
Readme
TechnicalIndicators
A javascript technical indicators written in typescript.
A fork base on anandanand84/technicalindicators
Installation
Node.js versions >= 10
npm install --save git+https://github.com/wahack/technicalindicators.git
const SMA = require('technicalindicators').SMA;
Node.js versions < 10
For nodejs version below 10 use 1.x versions of this library.
Webpack
Make sure you have the following in your config file.
module.exports = {
resolve: {
mainFields: ["module", "main"]
}
}
Browser
For browsers install using npm,
For ES6 browsers use
npm install --save technicalindicators
<script src="node_modules/technicalindicators/dist/browser.es6.js"></script>
For ES5 support it is necessary to include the babel-polyfill and respective file browser.js otherwise you will get an error. For example see index.html
npm install --save technicalindicators
npm install --save babel-polyfill
<script src="node_modules/babel-polyfill/browser.js"></script>
<script src="node_modules/technicalindicators/dist/browser.js"></script>
Pattern detection
Pattern detection is removed from version 3.0, if you need pattern detection use v2.0
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});
or
SMA.calculate({period : 5, values : [1,2,3,4,5,6,7,8,9]});
Playground
Playground with code completion
Available Indicators
- Accumulation Distribution Line (ADL).
- Average Directional Index (ADX).
- Average True Range (ATR).
- Awesome Oscillator (AO).
- Bollinger Bands (BB).
- Commodity Channel Index (CCI).
- Force Index (FI).
- Know Sure Thing (KST).
- Moneyflow Index (MFI).
- Moving Average Convergence Divergence (MACD).
- On Balance Volume (OBV).
- Parabolic Stop and Reverse (PSAR).
- Rate of Change (ROC).
- Relative Strength Index (RSI).
- Simple Moving Average (SMA).
- Stochastic Oscillator (KD).
- Stochastic RSI (StochRSI).
- Triple Exponentially Smoothed Average (TRIX).
- Typical Price.
- Volume Weighted Average Price (VWAP).
- Volume Profile (VP).
- Exponential Moving Average (EMA).
- Weighted Moving Average (WMA).
- Wilder’s Smoothing (Smoothed Moving Average, WEMA).
- WilliamsR (W%R).
- Ichimoku Cloud.
Other Utils
Chart Types
CandleStick Pattern
- Abandoned Baby弃婴形态.
- Bearish Engulfing Pattern 看跌吞没.
- Bullish Engulfiing Pattern 看涨吞没.
- Dark Cloud Cover 乌云盖顶.
- Downside Tasuki Gap 下行田村缺口.
- Doji 十字星.
- DragonFly Doji 蜻蜓十字星.
- GraveStone Doji 墓碑十字星.
- BullishHarami 看涨孕线.
- Bearish Harami Cross 看跌孕线十字.
- Bullish Harami Cross 看涨孕线十字.
- Bullish Marubozu 看涨实心.
- Bearish Marubozu 看跌实心.
- Evening Doji Star 黄昏十字星.
- Evening Star 黄昏星.
- Bearish Harami 看跌孕线.
- Piercing Line 刺透线.
- Bullish Spinning Top 看涨纺锤头.
- Bearish Spinning Top 看跌纺锤头.
- Morning Doji Star 早晨十字星.
- Morning Star 早晨之星.
- Three Black Crows 三只乌鸦.
- Three White Soldiers 三只白兵.
- Bullish Hammer 看涨锤子线.
- Bearish Hammer 看跌锤子线.
- Bullish Inverted Hammer 看涨倒锤子线.
- Bearish Inverted Hammer 看跌倒锤子线.
- Hammer Pattern 锤子形态.
- Hammer Pattern (Unconfirmed) 锤子形态(未确认).
- Hanging Man 上吊线.
- Hanging Man (Unconfirmed) 上吊线(未确认).
- Shooting Star 流星线.
- Shooting Star (Unconfirmed) 流星线(未确认).
- Tweezer Top 顶部钳形线.
- Tweezer Bottom 底部钳形线.
or
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
API
There are three ways you can use to get the indicator results.
calculate
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})
or
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
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);
if(result)
results.push(result)
});
getResult
This a merge of calculate and nextValue. The usual use case would be
Initialize indicator with available price value
Get results for initialized values
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.
Precision
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);
Contribute
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 [email protected]
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:
> [email protected] install /Users/balupton/Projects/trading/technicalindicators/node_modules/canvas
> node-gyp rebuild
./util/has_lib.sh: line 31: pkg-config: command not found
gyp: Call to './util/has_lib.sh freetype' returned exit status 0 while in binding.gyp. while trying to load binding.gyp
Setup
git clone [email protected]:wahack/technicalindicators.git # or use your fork
cd technicalindicators
npm run start
Running tests and getting coverage
npm test
npm run cover
Adding new indicators
- Add tests for the indicator and make them pass. (It would be better if a sample of the stockcharts excel is used for the test case.)
- Add the indicator to the
index.js
andsrc/index.ts
- Run build scripts:
npm run build-lib && npm run generateDts && npm run start
- Add it to
README.md
, with the link to the runkit url containing the sample. - Add indicator it to keywords in
package.json
andbower.json
- Send a Pull Request.
Verify Documentation
node testdocs.js
open "http://localhost:5444/testdocs.html"