ohlcv-indicators 1.8.2 → 1.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -74,20 +74,19 @@ export default class OHLCV_INDICATORS {
74
74
 
75
75
  getLastValues(){
76
76
 
77
- if(Object.keys(this.indicators).length > 0)
78
- {
79
- this.compute()
80
- }
81
-
82
77
  return this.getData()[this.getData().length -1]
78
+
83
79
  }
84
80
 
85
81
  compute() {
86
82
 
87
- const indicators = this.indicators
83
+
84
+ if(Object.keys(this.indicators).length === 0) return this
85
+
86
+
88
87
  const addColumn = this.addColumn.bind(this)
89
88
 
90
- for(const [key, arr] of Object.entries(indicators))
89
+ for(const [key, arr] of Object.entries( this.indicators))
91
90
  {
92
91
  if(!this.verticalOhlcv.hasOwnProperty(key))
93
92
  {
@@ -193,10 +192,10 @@ export default class OHLCV_INDICATORS {
193
192
  return this
194
193
 
195
194
  }
196
- bollingerBands(size, times)
195
+ bollingerBands(size, times, bollingerBandsStudies)
197
196
  {
198
197
 
199
- const result = bollingerBands(this, size, times)
198
+ const result = bollingerBands(this, size, times, bollingerBandsStudies)
200
199
  Object.assign(this.indicators, result)
201
200
 
202
201
  this.priceBased.push('bollinger_bands_middle', 'bollinger_bands_upper', 'bollinger_bands_lower')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohlcv-indicators",
3
- "version": "1.8.2",
3
+ "version": "1.8.4",
4
4
  "description": "A JavaScript library featuring optimized trading indicators for OHLCV arrays [{open, high, low, close, value}]. This library is optimized for backtesting and trading bot development.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2,30 +2,36 @@
2
2
  import {FasterBollingerBands, FasterSMA} from 'trading-signals';
3
3
  import { classifySize } from '../utilities/classification.js';
4
4
 
5
- export const bollingerBands = (main, size, times) => {
5
+ export const bollingerBands = (main, size, times, bollingerBandsStudies) => {
6
6
 
7
7
  const {verticalOhlcv} = main
8
8
  const {close} = verticalOhlcv
9
9
 
10
- const col = getBollingerBands(close, size, times)
10
+ const col = getBollingerBands(close, size, times, bollingerBandsStudies)
11
11
  return col
12
12
  }
13
13
 
14
- export const getBollingerBands = (data, size = 20, times = 2) => {
14
+ export const getBollingerBands = (data, size = 20, times = 2, bollingerBandsStudies = false) => {
15
15
 
16
16
  const dataLength = data.length
17
17
  const bollinger_bands_upper = Array(dataLength).fill(null)
18
18
  const bollinger_bands_middle = Array(dataLength).fill(null)
19
19
  const bollinger_bands_lower = Array(dataLength).fill(null)
20
- const bollinger_bands_range = Array(dataLength).fill(null)
21
- const bollinger_bands_height = Array(dataLength).fill(null)
22
20
 
23
21
 
24
- const heightInstance = new FasterSMA(size)
25
-
22
+ let bollinger_bands_range
23
+ let bollinger_bands_height
24
+ let heightInstance
26
25
  let range = null
27
26
  let height = null
28
27
 
28
+ if(bollingerBandsStudies)
29
+ {
30
+ bollinger_bands_range = Array(dataLength).fill(null)
31
+ bollinger_bands_height = Array(dataLength).fill(null)
32
+ heightInstance = new FasterSMA(size)
33
+ }
34
+
29
35
  let getRange = (value, upper, lower) => ({
30
36
  range: ((value - lower) / (upper - lower)),
31
37
  height: upper-lower
@@ -52,6 +58,8 @@ export const getBollingerBands = (data, size = 20, times = 2) => {
52
58
  bollinger_bands_middle[x] = obj.middle;
53
59
  bollinger_bands_lower[x] = obj.lower;
54
60
 
61
+ if(bollingerBandsStudies === false) continue
62
+
55
63
  if(hasNull)
56
64
  {
57
65
  bollinger_bands_range[x] = null
@@ -79,6 +87,13 @@ export const getBollingerBands = (data, size = 20, times = 2) => {
79
87
  bollinger_bands_height[x] = classifySize(height, heightMean, 1.5)
80
88
  }
81
89
 
82
- return { bollinger_bands_upper, bollinger_bands_middle, bollinger_bands_lower, bollinger_bands_range, bollinger_bands_height }
90
+ let output = { bollinger_bands_upper, bollinger_bands_middle, bollinger_bands_lower }
91
+
92
+ if(bollingerBandsStudies)
93
+ {
94
+ output = {...output, bollinger_bands_range, bollinger_bands_height}
95
+ }
96
+
97
+ return output
83
98
  }
84
99
 
@@ -202,7 +202,7 @@ export const crossPairs = (main, arr) => {
202
202
  }
203
203
 
204
204
  } else {
205
- console.log(`Missing ohlcv properties for ${fast} or ${slow}`);
205
+ throw Error(`Missing ohlcv properties for ${fast} or ${slow}`);
206
206
  }
207
207
  }
208
208