Skip to content

Commit

Permalink
Added note to the README about canvas dependencies (#60)
Browse files Browse the repository at this point in the history
* Added note to the README about canvas dependencies and add editor config

* move environment dependency section to contribute

also did some consistency and formatting updates

* clean install instructions for node versions

* fix syntax issue in install instructions

* add editorconfig - fix #61
  • Loading branch information
balupton authored and anandanand84 committed Aug 2, 2017
1 parent 7d81187 commit d0a09cd
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 99 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# editorconfig.org
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
indent_style = space
indent_size = 4

[*.mk]
indent_style = tab

[*.md]
indent_style = space
indent_size = 4

[{*.json,*.yml,*.bowerrc,*.babelrc}]
indent_style = space
indent_size = 2
216 changes: 117 additions & 99 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,36 @@

A javascript technical indicators written in javascript.


# Installation

## Nodejs
## Node.js versions >= 6.4

```
npm install --save babel-polyfill
``` bash
npm install --save technicalindicators
```

### node usage above 6.4

```
``` javascript
const SMA = require('technicalindicators').SMA;
```

### node usage below 6.4
## Node.js versions < 6.4

``` bash
npm install --save babel-polyfill
npm install --save technicalindicators
```
require('babel-polyfill);

``` javascript
require('babel-polyfill');
const SMA = require('technicalindicators/dist/browser').SMA;
```

## Webpack

Make sure you have the following in your config file.

```
``` javascript
module.exports = {
resolve: {
mainFields: ["module", "main"]
Expand All @@ -42,90 +46,96 @@ module.exports = {

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](https://github.com/anandanand84/technicalindicators/blob/master/index.html "index.html")

```
``` bash
npm install --save technicalindicators
npm install --save babel-polyfill
bower install --save technicalindicators
```

```
``` html
<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

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

or

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


# Playground

[Playground with code completion](http://anandanand84.github.io/technicalindicators/ "Playground")
[Playground with code completion](http://anandanand84.github.io/technicalindicators/ "Playground")


# Available Indicators

1. [Simple Moving Average (SMA)](https://tonicdev.com/anandaravindan/sma "SMA").
2. [Exponential Moving Average (EMA)](https://tonicdev.com/anandaravindan/ema "EMA").
3. [Weighted Moving Average (WMA)](https://tonicdev.com/anandaravindan/wma "WMA").
4. [Moving Average Convergence Divergence (MACD)](https://tonicdev.com/anandaravindan/macd "MACD").
5. [Bollinger Bands (BB)](https://tonicdev.com/anandaravindan/bb "BB").
6. [Average True Range (ATR)](https://tonicdev.com/anandaravindan/atr "ATR").
7. [Relative Strength Index (RSI)](https://tonicdev.com/anandaravindan/rsi "RSI").
8. [Wilder’s Smoothing (Smoothed Moving Average, WEMA)](https://tonicdev.com/anandaravindan/wema "WEMA").
9. [Rate of Change (ROC)](https://tonicdev.com/anandaravindan/roc "ROC").
10. [Know Sure Thing (KST)](https://tonicdev.com/anandaravindan/kst "KST").
11. [Stochastic Oscillator (KD)](https://tonicdev.com/anandaravindan/stochastic "KD").
12. [WilliamsR (W%R)](https://tonicdev.com/anandaravindan/williamsr "W%R").
13. [Accumulation Distribution Line (ADL)](https://tonicdev.com/anandaravindan/adl "ADL").
14. [On Balance Volume (OBV)](https://tonicdev.com/anandaravindan/obv "OBV").
15. [Triple Exponentially Smoothed Average (TRIX)](https://tonicdev.com/anandaravindan/trix "TRIX").
16. [Average Directional Index (ADX)](https://github.com/anandanand84/technicalindicators/blob/master/test/directionalmovement/ADX.js "ADX").
17. [Commodity Channel Index (CCI)](https://github.com/anandanand84/technicalindicators/blob/master/test/oscillators/CCI.js "CCI").
18. [Volume Weighted Average Price (VWAP)](https://github.com/anandanand84/technicalindicators/blob/master/test/volume/VWAP.js "VWAP").
19. [Force Index (FI)](https://github.com/anandanand84/technicalindicators/blob/master/test/volume/ForceIndex.js "VWAP").
1. [Exponential Moving Average (EMA)](https://tonicdev.com/anandaravindan/ema "EMA").
1. [Weighted Moving Average (WMA)](https://tonicdev.com/anandaravindan/wma "WMA").
1. [Moving Average Convergence Divergence (MACD)](https://tonicdev.com/anandaravindan/macd "MACD").
1. [Bollinger Bands (BB)](https://tonicdev.com/anandaravindan/bb "BB").
1. [Average True Range (ATR)](https://tonicdev.com/anandaravindan/atr "ATR").
1. [Relative Strength Index (RSI)](https://tonicdev.com/anandaravindan/rsi "RSI").
1. [Wilder’s Smoothing (Smoothed Moving Average, WEMA)](https://tonicdev.com/anandaravindan/wema "WEMA").
1. [Rate of Change (ROC)](https://tonicdev.com/anandaravindan/roc "ROC").
1. [Know Sure Thing (KST)](https://tonicdev.com/anandaravindan/kst "KST").
1. [Stochastic Oscillator (KD)](https://tonicdev.com/anandaravindan/stochastic "KD").
1. [WilliamsR (W%R)](https://tonicdev.com/anandaravindan/williamsr "W%R").
1. [Accumulation Distribution Line (ADL)](https://tonicdev.com/anandaravindan/adl "ADL").
1. [On Balance Volume (OBV)](https://tonicdev.com/anandaravindan/obv "OBV").
1. [Triple Exponentially Smoothed Average (TRIX)](https://tonicdev.com/anandaravindan/trix "TRIX").
1. [Average Directional Index (ADX)](https://github.com/anandanand84/technicalindicators/blob/master/test/directionalmovement/ADX.js "ADX").
1. [Commodity Channel Index (CCI)](https://github.com/anandanand84/technicalindicators/blob/master/test/oscillators/CCI.js "CCI").
1. [Volume Weighted Average Price (VWAP)](https://github.com/anandanand84/technicalindicators/blob/master/test/volume/VWAP.js "VWAP").
1. [Force Index (FI)](https://github.com/anandanand84/technicalindicators/blob/master/test/volume/ForceIndex.js "VWAP").


# Chart Types

1. [Renko (renko)](https://github.com/anandanand84/technicalindicators/blob/master/test/chart_types/Renko.js)
2. [Heikin-Ashi (HA)](https://github.com/anandanand84/technicalindicators/blob/master/test/chart_types/HeikinAshi.js)
1. [Heikin-Ashi (HA)](https://github.com/anandanand84/technicalindicators/blob/master/test/chart_types/HeikinAshi.js)


# CandleStick Pattern

1. [Abandoned Baby](https://runkit.com/aarthiaradhana/abandonedbaby).
2. [Bearish Engulfing Pattern](https://runkit.com/aarthiaradhana/bearishengulfingpattern).
3. [Bullish Engulfiing Pattern](https://runkit.com/aarthiaradhana/bullishengulfingpattern).
4. [Dark Cloud Cover](https://runkit.com/aarthiaradhana/darkcloudcover).
5. [Downside Tasuki Gap](https://runkit.com/aarthiaradhana/downsidetasukigap).
6. [Doji](https://runkit.com/aarthiaradhana/doji).
7. [DragonFly Doji](https://runkit.com/aarthiaradhana/dragonflydoji).
8. [GraveStone Doji](https://runkit.com/aarthiaradhana/gravestonedoji).
9. [BullishHarami](https://runkit.com/aarthiaradhana/bullishharami).
10. [Bearish Harami Cross](https://runkit.com/aarthiaradhana/bearishharamicross).
11. [Bullish Harami Cross](https://runkit.com/aarthiaradhana/bullishharamicross).
12. [Bullish Marubozu](https://runkit.com/aarthiaradhana/bullishmarubozu).
13. [Bearish Marubozu](https://runkit.com/aarthiaradhana/bearishmarubozu).
14. [Evening Doji Star](https://runkit.com/aarthiaradhana/eveningdojistar).
15. [Evening Star](https://runkit.com/aarthiaradhana/eveningstar).
16. [Bearish Harami](https://runkit.com/aarthiaradhana/bearishharami).
17. [Piercing Line](https://runkit.com/aarthiaradhana/piercingline).
18. [Bullish Spinning Top](https://runkit.com/aarthiaradhana/bullishspinningtop).
19. [Bearish Spinning Top](https://runkit.com/aarthiaradhana/bearishspinningtop).
20. [Morning Doji Star](https://runkit.com/aarthiaradhana/morningdojistar).
21. [Morning Star](https://runkit.com/aarthiaradhana/morningstar).
22. [Three Black Crows](https://runkit.com/aarthiaradhana/threeblackcrows).
23. [Three White Soldiers](https://runkit.com/aarthiaradhana/threewhitesoldiers).
1. [Bearish Engulfing Pattern](https://runkit.com/aarthiaradhana/bearishengulfingpattern).
1. [Bullish Engulfiing Pattern](https://runkit.com/aarthiaradhana/bullishengulfingpattern).
1. [Dark Cloud Cover](https://runkit.com/aarthiaradhana/darkcloudcover).
1. [Downside Tasuki Gap](https://runkit.com/aarthiaradhana/downsidetasukigap).
1. [Doji](https://runkit.com/aarthiaradhana/doji).
1. [DragonFly Doji](https://runkit.com/aarthiaradhana/dragonflydoji).
1. [GraveStone Doji](https://runkit.com/aarthiaradhana/gravestonedoji).
1. [BullishHarami](https://runkit.com/aarthiaradhana/bullishharami).
1. [Bearish Harami Cross](https://runkit.com/aarthiaradhana/bearishharamicross).
1. [Bullish Harami Cross](https://runkit.com/aarthiaradhana/bullishharamicross).
1. [Bullish Marubozu](https://runkit.com/aarthiaradhana/bullishmarubozu).
1. [Bearish Marubozu](https://runkit.com/aarthiaradhana/bearishmarubozu).
1. [Evening Doji Star](https://runkit.com/aarthiaradhana/eveningdojistar).
1. [Evening Star](https://runkit.com/aarthiaradhana/eveningstar).
1. [Bearish Harami](https://runkit.com/aarthiaradhana/bearishharami).
1. [Piercing Line](https://runkit.com/aarthiaradhana/piercingline).
1. [Bullish Spinning Top](https://runkit.com/aarthiaradhana/bullishspinningtop).
1. [Bearish Spinning Top](https://runkit.com/aarthiaradhana/bearishspinningtop).
1. [Morning Doji Star](https://runkit.com/aarthiaradhana/morningdojistar).
1. [Morning Star](https://runkit.com/aarthiaradhana/morningstar).
1. [Three Black Crows](https://runkit.com/aarthiaradhana/threeblackcrows).
1. [Three White Soldiers](https://runkit.com/aarthiaradhana/threewhitesoldiers).

or

Search for all bullish or bearish using


```js
``` javascript
var twoDayBullishInput = {
open: [23.25,15.36],
high: [25.10,30.87],
Expand All @@ -136,7 +146,6 @@ var twoDayBullishInput = {
var bullish = require('technicalindicators').bullish;

bullish(twoDayBullishInput) //true

```


Expand All @@ -146,16 +155,18 @@ 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.
```javascript
Every indicator has a static method `calculate` which can be used to calculate the indicator without creating an object.

``` javascript
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

```javascript
``` javascript
const SMA = require('technicalindicators').SMA;
var prices = [1,2,3,4,5,6,7,8,9,10,12,13,15];
var period = 10;
Expand All @@ -164,9 +175,9 @@ SMA.calculate({period : period, values : prices})

## nextValue

```nextValue``` method is used to get the next indicator value.
`nextValue` method is used to get the next indicator value.

```javascript
``` javascript
var sma = new SMA({period : period, values : []});
var results = [];
prices.forEach(price => {
Expand All @@ -180,75 +191,82 @@ prices.forEach(price => {

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

1.Initialize indicator with available price value
1. Initialize indicator with available price value

2.Get results for initialized values
1. Get results for initialized values

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

```javascript
var sma = new SMA({period : period, values : prices});
sma.getResult(); // [5.5, 6.6, 7.7, 8.9]
sma.nextValue(16); // 10.1
```
1. Use nextValue to get next indicator values for further tick.

Note: Calling nextValue will not update getResult() value.
``` javascript
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.

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


# Running tests and getting coverage

```
npm test
```

```
npm run cover
```
# 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.
## Adding new indicators.
## Environment dependencies
1. Fork the project, clone it, run
TechnicalIndicators depends on the [`canvas` package](https://npmjs.com/canvas), which requires some dependencies to be installed. You can find the instructions to do that [here](https://github.com/Automattic/node-canvas#installation). If you do not install these dependencies, expect to get this error message during the installation of TechnicalIndicators:
```
npm install
```
> canvas@1.6.6 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
``` bash
git clone git@github.com:anandanand84/technicalindicators.git # or use your fork
cd technicalindicators
npm install
gulp watch-test
```
2. Add tests for the indicator. Make it pass. It would be better if a sample of the stockcharts excel is used for the test case.
3. Add the indicator to the index.js
4. Run ```npm run build``` so it adds the indicator to the browser.js
5. Add it to read me, with the link to the tonicdev url containing the sample.
6. Add indicator it to keywords in package.json and bower.json
7. Send a pull request.
## Running tests and getting coverage
``` bash
npm test
npm run cover
```
# Verify Documentation
## Adding new indicators.
```
node testdocs.js
```
1. Add tests for the indicator. Make it pass. It would be better if a sample of the stockcharts excel is used for the test case.
1. Add the indicator to the index.js
1. Run `npm run build` so it adds the indicator to the browser.js
1. Add it to read me, with the link to the tonicdev url containing the sample.
1. Add indicator it to keywords in package.json and bower.json
1. Send a pull request.
```
http://localhost:5444/testdocs.html
## Verify Documentation
``` bash
node testdocs.js
open "http://localhost:5444/testdocs.html"
```
# Donate
BTC : 12eGmnhPrGuqvLNVnPddTaXm74hX68auTV
BTC: `12eGmnhPrGuqvLNVnPddTaXm74hX68auTV`

0 comments on commit d0a09cd

Please sign in to comment.