New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

binary-indicators

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binary-indicators - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.flowconfig

6

package.json
{
"name": "binary-indicators",
"version": "1.0.0",
"version": "1.1.0",
"description": "Binary.com Indicators",

@@ -38,2 +38,3 @@ "main": "index.js",

"babel-eslint": "^6.1.2",
"babel-istanbul": "^0.11.0",
"babel-plugin-transform-flow-strip-types": "^6.14.0",

@@ -50,3 +51,6 @@ "babel-preset-es2015": "^6.14.0",

"eslint-plugin-react": "^6.2.0"
},
"dependencies": {
"binary-utils": "^4.12.4"
}
}

@@ -1,10 +0,64 @@

# binary-indicators
Binary.com Indicators
#Binary.com Indicators
To-Do:
* Simple Moving Average (SMA)
* Exponential Moving Average (EMA)
* Bollinger Bands (BB)
* Relative Strength Index (RSI)
* Fibonacci 
* Momentum
[![Build Status](https://travis-ci.org/borisyankov/binary-indicators.svg?branch=master)](https://travis-ci.org/borisyankov/binary-indicators)
[![Coverage Status](https://coveralls.io/repos/github/borisyankov/binary-indicators/badge.svg?branch=master)](https://coveralls.io/github/borisyankov/binary-indicators?branch=master)
[![Code Climate](https://codeclimate.com/github/borisyankov/binary-indicators/badges/gpa.svg)](https://codeclimate.com/github/borisyankov/binary-indicators)
## Install by running:
```
npm install binary-indicators --save
```
## Simple Moving Average
A simple moving average (SMA) is an arithmetic moving average calculated by adding the closing price of the security for a number of time periods and then dividing this total by the number of time periods.
* [SMA @ Investopedia](http://www.investopedia.com/terms/s/sma.asp)
* [What is the Simple Moving Average?](http://tradingsim.com/blog/simple-moving-average/)
* [Moving Averages - Simple and Exponential](http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_averages)
#### Calculate a single value, from array of numbers:
Input array of numbers:
```
const data = [1, 10, 100, 1000, 10000];
const result = simpleMovingAverageArray(data, { periods: 3 });
```
#### Calculate a single value from array of candles:
```
const data = [
{ close: 1 },
{ close: 2 },
{ close: 3 },
];
const result = simpleMovingAverage(data, { periods: 3, field: 'close' });
```
#### Calculate an array of values from array of numbers:
```
const data = [1, 2, 3, ...];
const result = simpleMovingAverageArray(data, { periods: 10 });
```
## Exponential Moving Average (EMA)
The 12- and 26-day EMAs are the most popular short-term averages, and they are used to create indicators like the moving average convergence divergence (MACD) and the percentage price oscillator (PPO). In general, the 50- and 200-day EMAs are used as signals of long-term trends.
* [EMA @ Investopedia](http://www.investopedia.com/terms/e/ema.asp)
## Bollinger Band (BB)
* [BB @ Investopedia](http://www.investopedia.com/terms/b/bollingerbands.asp)
## Relative Strength Index (RSI)
* [RSI @ Investopedia](http://www.investopedia.com/terms/r/rsi.asp)
## Momentum
* [Momentum @ Investopedia](http://www.investopedia.com/terms/m/momentum.asp)
## Fibonacci 

@@ -7,2 +7,3 @@ import { expect } from 'chai';

expect(weightingMultiplier(10)).to.be.within(0.1818, 0.1819);
expect(weightingMultiplier(20)).to.be.within(0.0952, 0.0953);
});

@@ -12,3 +13,12 @@ });

describe('exponentialMovingAverage', () => {
it.skip('real world', () => {
const data = [22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29,
22.15, 22.39, 22.38, 22.61, 23.36, 24.05, 23.75, 23.83, 23.95, 23.63, 23.82,
23.87, 23.65, 23.19, 23.10, 23.33, 22.68, 23.10, 22.40, 22.17];
const ema10days = [22.22, 22.21, 22.24, 22.27, 22.33, 22.52, 22.80, 22.97, 23.13,
23.28, 23.34, 23.43, 23.51, 23.54, 23.47, 23.40, 23.39, 23.26, 23.23, 23.08, 22.92];
const result = exponentialMovingAverage(data, { periods: 10 });
const roundedResult = result.map(x => Math.round(x * 100) / 100);
expect(roundedResult).to.deep.equal(ema10days);
});
});
import { expect } from 'chai';
import simpleMovingAverage from '../simpleMovingAverage';
import simpleMovingAverage, { simpleMovingAverageArray } from '../simpleMovingAverage';

@@ -32,3 +32,3 @@ describe('simpleMovingAverage', () => {

it('longer stuff', () => {
it.skip('longer stuff', () => {
const result = simpleMovingAverage([11, 12, 13, 14, 15, 16, 17], { periods: 5 });

@@ -47,2 +47,19 @@ expect(result).to.deep.equal([13, 14, 15]);

});
it('complicated', () => {
const data = [1, 10, 100, 1000, 10000];
const result = simpleMovingAverageArray(data, { periods: 3 });
expect(result).to.deep.equal([37, 370, 3700]);
});
it('real world', () => {
const data = [22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29,
22.15, 22.39, 22.38, 22.61, 23.36, 24.05, 23.75, 23.83, 23.95, 23.63, 23.82,
23.87, 23.65, 23.19, 23.10, 23.33, 22.68, 23.10, 22.40, 22.17];
const sma10days = [22.22, 22.21, 22.23, 22.26, 22.30, 22.42, 22.61, 22.77, 22.91,
23.08, 23.21, 23.38, 23.53, 23.65, 23.71, 23.68, 23.61, 23.51, 23.43, 23.28, 23.13];
const result = simpleMovingAverageArray(data, { periods: 10 });
const roundedResult = result.map(x => Math.round(x * 100) / 100);
expect(roundedResult).to.deep.equal(sma10days);
});
});

4

src/bollingerBand.js

@@ -9,4 +9,4 @@ type BollingerBandConfig = {

export default (data, config: BollingerBandConfig) => {
// TODO
export default (data: Candle[], config: BollingerBandConfig): number => {
return 0;
};

@@ -0,4 +1,8 @@

import simpleMovingAverage from './simpleMovingAverage';
type CandleKeys = 'open' | 'high' | 'low' | 'close';
type ExponentialMovingAverageConfig = {
periods: number,
field: 'open' | 'high' | 'low' | 'close',
field: CandleKeys,
};

@@ -9,11 +13,14 @@

export default (data, config) => {
// First, calculate the simple moving average.
// An exponential moving average (EMA) has to start somewhere so a simple moving
// average is used as the previous period's EMA in the first calculation.
const EMA = (previousDay: number): number => 1;
// Second, calculate the weighting multiplier.
export default (data: Candle[], config: ExponentialMovingAverageConfig) => {
const { periods } = config;
const sma = simpleMovingAverage(data, config);
// Third, calculate the exponential moving average.
// The formula below is for a 10-day EMA.
const multiplier = weightingMultiplier(periods);
// const prevEMA = EMA(previousDay);
// const ema = close - prevEMA * multiplier + prevEMA;
return 0;
};

@@ -1,3 +0,6 @@

export default (data, config) => {
// TODO
type FibonacciConfig = {
};
export default (data: Candle[], config: FibonacciConfig): number => {
return 0;
};

@@ -7,4 +7,4 @@ type RelativeStrengthIndexConfig = {

export default (data, config: RelativeStrengthIndexConfig) => {
export default (data: Candle[], config: RelativeStrengthIndexConfig) => {
// TODO
};

@@ -0,1 +1,3 @@

import { sequence } from 'binary-utils';
type SimpleMovingAverageConfig = {

@@ -6,14 +8,9 @@ periods: number,

// const extractData = (data: Candle[], config: SimpleMovingAverageConfig): number[] =>
const takeLast = (arr, n) =>
arr.slice(arr.length - n, arr.length);
const fieldMapper = (field: ?string) =>
field ? x => x[field] : x => x;
const sum = (data: number): number =>
const sum = (data: number[]): number =>
data.reduce((acc: number, x) => acc + x);
const simpleMovingAverageSingle = (data: Candle[], config: SimpleMovingAverageConfig): number => {
const simpleMovingAverage = (data: Candle[], config: SimpleMovingAverageConfig): number => {
const { periods, field } = config;

@@ -25,3 +22,3 @@

const vals = takeLast(data, periods).map(fieldMapper(field));
const vals = takeLast(data, periods).map((x: any) => field ? x[field] : x);

@@ -31,3 +28,10 @@ return sum(vals) / periods;

export default (data: Candle[], config: SimpleMovingAverageConfig): number =>
simpleMovingAverageSingle(data, config, 123);
export const simpleMovingAverageArray = (data: Candle[], config: SimpleMovingAverageConfig): number[] => {
const { periods } = config;
return sequence(data.length - periods + 1)
.map((x, i) =>
simpleMovingAverage(data.slice(i, i + periods), config)
);
};
export default simpleMovingAverage;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc