ohlcv-indicators 2.1.4 → 2.1.6

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.
@@ -0,0 +1,160 @@
1
+
2
+ import {FasterEMA, FasterSMA, FasterBollingerBands} from 'trading-signals';
3
+ import { classifyBoll } from '../utilities/classification.js'
4
+
5
+ const indicatorClasses = {ema: FasterEMA, sma: FasterSMA}
6
+
7
+ export const movingAverages = (main, index, indicatorName, size, {target, diff}) => {
8
+
9
+ const {verticalOhlcv, instances, priceBased, lastIndexReplace} = main
10
+ let suffix = (typeof target === 'string' && verticalOhlcv.hasOwnProperty(target) && target !== 'close') ? `_${target}` : ''
11
+ const keyName = `${indicatorName}_${size}${suffix}`
12
+ const diffKeyName = `${indicatorName}_${size}_diff${suffix}`
13
+
14
+ if(index === 0)
15
+ {
16
+ const {nullArray} = main
17
+
18
+ if(!verticalOhlcv.hasOwnProperty(target))
19
+ {
20
+ throw new Error(`Target property ${target} not found in verticalOhlcv for ${indicatorName}.`)
21
+ }
22
+
23
+ instances[keyName] = {
24
+ maInstance: new indicatorClasses[indicatorName](size)
25
+ }
26
+
27
+ verticalOhlcv[keyName] = [...nullArray]
28
+
29
+ if(diff !== null)
30
+ {
31
+ instances[keyName].diffInstance = new FasterBollingerBands(diff.size, diff.stdDev)
32
+
33
+ const lagDiffArr = []
34
+
35
+ for(const targetKey of diff.targets)
36
+ {
37
+ verticalOhlcv[`${diffKeyName}_${targetKey}`] = [...nullArray]
38
+
39
+ if(diff.lag > 0)
40
+ {
41
+ lagDiffArr.push(`${diffKeyName}_${targetKey}`)
42
+ }
43
+ }
44
+
45
+ if(diff.lag > 0)
46
+ {
47
+ console.log(lagDiffArr, diff.lag)
48
+ main.lag(lagDiffArr, diff.lag)
49
+ }
50
+ }
51
+
52
+ priceBased.push(keyName)
53
+ }
54
+
55
+ const value = verticalOhlcv[target][index]
56
+ const {maInstance, diffInstance} = instances[keyName]
57
+ maInstance.update(value, lastIndexReplace)
58
+
59
+ let currMa
60
+
61
+ try{
62
+ currMa = maInstance.getResult()
63
+ } catch(err)
64
+ {
65
+ //do nothing
66
+ }
67
+
68
+ if(currMa)
69
+ {
70
+ main.pushToMain({index, key: keyName, value: currMa})
71
+
72
+ if(diff === null)
73
+ {
74
+ return true
75
+ }
76
+
77
+ for(const targetKey of diff.targets)
78
+ {
79
+
80
+ const diffValue = (target === targetKey) ? value - currMa : verticalOhlcv[targetKey][index]
81
+
82
+ diffInstance.update(Math.abs(diffValue), lastIndexReplace)
83
+
84
+ let diffBoll
85
+
86
+ try {
87
+ diffBoll = diffInstance.getResult()
88
+ } catch(err)
89
+ {
90
+ diffBoll = null
91
+ }
92
+
93
+ main.pushToMain({index, key: `${diffKeyName}_${targetKey}`, value: classifyBoll(diffValue, diffBoll, diff.scale)})
94
+
95
+ }
96
+
97
+
98
+
99
+ }
100
+
101
+ }
102
+
103
+
104
+
105
+ export const getMovingAveragesParams = (indicatorName, size, options, validMagnitudeValues) => {
106
+ if (!options || typeof options !== 'object') {
107
+ throw new Error(`"options" must be an object in ${indicatorName}. eg: {target, height, range}`);
108
+ }
109
+
110
+ let { target = 'close', diff = null } = options;
111
+
112
+ if(typeof target !== 'string')
113
+ {
114
+ throw new Error(`"target" must be a valid keyName ${indicatorName}.`);
115
+ }
116
+
117
+ if (typeof size !== 'number' || size <= 0) {
118
+ throw new Error(`"size" must be a positive number in ${indicatorName}.`);
119
+ }
120
+
121
+ //diff can be null, true, false or an object with optional {stdDev, scale, targets, and size}
122
+ const optionArgs = { target, diff: null };
123
+
124
+ if (diff !== null && (typeof diff === 'object' || (typeof diff === 'boolean' && diff === true))) {
125
+
126
+ diff = (diff === true) ? ({}) : diff
127
+
128
+ const {
129
+ stdDev = 2,
130
+ scale = 0.05,
131
+ targets = ['close'],
132
+ size: diffSize = size,
133
+ lag = 0
134
+ } = diff;
135
+
136
+ if (typeof stdDev !== 'number' || stdDev <= 0) {
137
+ throw new Error(`"diff.stdDev" must be a number greater than 0 in ${indicatorName}.`);
138
+ }
139
+
140
+ if (typeof scale !== 'number' || !validMagnitudeValues.includes(scale)) {
141
+ throw new Error(`"diff.scale" must be a number between 0.01 and 1 in ${indicatorName}.`);
142
+ }
143
+
144
+ if (typeof diffSize !== 'number' || !Number.isInteger(diffSize) || diffSize <= 0) {
145
+ throw new Error(`"diff.size" must be an integer greater than or equal to size in ${indicatorName}.`);
146
+ }
147
+
148
+ if (!Array.isArray(targets)) {
149
+ throw new Error(`"diff.targest" must be an array of keyNames with at least 1 item in ${indicatorName}.`);
150
+ }
151
+
152
+ if (typeof lag !== 'number' || !Number.isInteger(lag) || lag < 0) {
153
+ throw new Error(`"diff.lag" must be an integer greater than 0 in ${indicatorName}.`);
154
+ }
155
+
156
+ optionArgs.diff = { stdDev, scale, size: diffSize, targets, lag };
157
+ }
158
+
159
+ return optionArgs;
160
+ }
@@ -1,6 +1,7 @@
1
1
  import {FasterSMA} from 'trading-signals';
2
+ import { calcMagnitude } from '../utilities/numberUtilities.js';
2
3
 
3
- export const relativeVolume = (main, index, size = 10) => {
4
+ export const relativeVolume = (main, index, size = 10, {scale}) => {
4
5
 
5
6
  const key = `relative_volume_${size}`
6
7
 
@@ -32,10 +33,22 @@ export const relativeVolume = (main, index, size = 10) => {
32
33
 
33
34
  const {prevRelativeVolumeSma} = main.instances[key]
34
35
 
36
+ let currRelativeVolume = null
37
+
38
+ if(smaValue !== null && prevRelativeVolumeSma !== null)
39
+ {
40
+ currRelativeVolume = value / prevRelativeVolumeSma
41
+
42
+ if(scale)
43
+ {
44
+ currRelativeVolume = calcMagnitude(currRelativeVolume, scale)
45
+ }
46
+ }
47
+
35
48
  main.pushToMain({
36
49
  index,
37
50
  key,
38
- value: (smaValue !== null && prevRelativeVolumeSma !== null) ? value / prevRelativeVolumeSma : null
51
+ value: currRelativeVolume
39
52
  })
40
53
 
41
54
  main.instances[key].prevRelativeVolumeSma = smaValue
@@ -1,47 +1,65 @@
1
1
  import {FasterRSI} from 'trading-signals';
2
2
  import { FasterSMA } from 'trading-signals';
3
+ import { calcMagnitude } from '../utilities/numberUtilities.js';
3
4
 
5
+ const defaultTarget = 'close'
4
6
 
5
- export const rsi = (main, index, size) => {
7
+ export const rsi = (main, index, size, {scale, target}) => {
6
8
 
7
- const value = main.verticalOhlcv.close[index]
9
+ const {verticalOhlcv, instances, lastIndexReplace} = main
10
+ const suffix = (target === defaultTarget) ? '' : `_${target}`
11
+ const rsiKey = `rsi_${size}${suffix}`
12
+ const rsiSmaKey = `rsi_sma_${size}${suffix}`
8
13
 
9
14
  if(index === 0)
10
15
  {
11
- main.crossPairsList.push({fast: `rsi_${size}`, slow: `rsi_sma_${size}`, isDefault: true})
16
+ const {crossPairsList, nullArray} = main
12
17
 
13
- Object.assign(main.instances, {
14
- [`rsi_${size}`]: new FasterRSI(size),
15
- [`rsi_sma_${size}`]: new FasterSMA(size)
18
+ if(!verticalOhlcv.hasOwnProperty(target))
19
+ {
20
+ throw new Error(`Target property ${target} not found in verticalOhlcv for rsi.`)
21
+ }
22
+
23
+ crossPairsList.push({fast: rsiKey, slow: rsiSmaKey, isDefault: true})
24
+
25
+ Object.assign(instances, {
26
+ [rsiKey]: new FasterRSI(size),
27
+ [rsiSmaKey]: new FasterSMA(size)
16
28
  })
17
29
 
18
- Object.assign(main.verticalOhlcv, {
19
- [`rsi_${size}`]: [...main.nullArray],
20
- [`rsi_sma_${size}`]: [...main.nullArray]
30
+ Object.assign(verticalOhlcv, {
31
+ [rsiKey]: [...nullArray],
32
+ [rsiSmaKey]: [...nullArray]
21
33
  })
22
34
  }
23
-
35
+
36
+ const value = verticalOhlcv[target][index]
24
37
  let currentRsi
25
38
  let smoothedRsi
26
39
 
27
- main.instances[`rsi_${size}`].update(value, main.lastIndexReplace)
40
+ instances[rsiKey].update(value, lastIndexReplace)
28
41
 
29
42
  try
30
43
  {
31
- currentRsi = main.instances[`rsi_${size}`].getResult()
44
+ currentRsi = instances[rsiKey].getResult()
32
45
  } catch(err) {
33
46
  currentRsi = null
34
47
  }
35
48
 
36
49
  if(currentRsi)
37
50
  {
38
- main.pushToMain({index, key: `rsi_${size}`, value: currentRsi})
39
- main.instances[`rsi_sma_${size}`].update(currentRsi, main.lastIndexReplace)
51
+ if(scale)
52
+ {
53
+ currentRsi = calcMagnitude(currentRsi, scale)
54
+ }
55
+
56
+ main.pushToMain({index, key: rsiKey, value: currentRsi})
57
+ instances[rsiSmaKey].update(currentRsi, lastIndexReplace)
40
58
  }
41
59
 
42
60
  try
43
61
  {
44
- smoothedRsi = main.instances[`rsi_sma_${size}`].getResult()
62
+ smoothedRsi = instances[rsiSmaKey].getResult()
45
63
  } catch(err)
46
64
  {
47
65
  smoothedRsi = null
@@ -49,7 +67,12 @@ export const rsi = (main, index, size) => {
49
67
 
50
68
  if(smoothedRsi)
51
69
  {
52
- main.pushToMain({index, key: `rsi_sma_${size}`, value: smoothedRsi})
70
+ if(scale)
71
+ {
72
+ smoothedRsi = calcMagnitude(smoothedRsi, scale)
73
+ }
74
+
75
+ main.pushToMain({index, key: rsiSmaKey, value: smoothedRsi})
53
76
  }
54
77
 
55
78
  return true
@@ -1,6 +1,7 @@
1
1
  import { FasterEMA } from 'trading-signals';
2
+ import { calcMagnitude } from '../utilities/numberUtilities.js';
2
3
 
3
- export const volumeOscillator = (main, index, fast, slow) => {
4
+ export const volumeOscillator = (main, index, fast, slow, {scale}) => {
4
5
 
5
6
  const value = main.verticalOhlcv.volume[index]
6
7
  const key = 'volume_oscillator'
@@ -38,12 +39,19 @@ export const volumeOscillator = (main, index, fast, slow) => {
38
39
  slowValue = null;
39
40
  }
40
41
 
41
- if (typeof fastValue === 'number' && typeof slowValue === 'number' && slowValue !== 0) {
42
+ let volumeOscValue = null
42
43
 
43
- main.pushToMain({index, key, value: 100 * (fastValue - slowValue) / slowValue})
44
- } else {
45
- main.pushToMain({index, key, value: null})
44
+ if(typeof fastValue === 'number' && typeof slowValue === 'number' && slowValue !== 0)
45
+ {
46
+ volumeOscValue = 100 * (fastValue - slowValue) / slowValue
47
+
48
+ if(scale)
49
+ {
50
+ volumeOscValue = calcMagnitude(volumeOscValue, scale)
51
+ }
46
52
  }
47
53
 
54
+ main.pushToMain({index, key, value: volumeOscValue})
55
+
48
56
  return true;
49
57
  };
@@ -1,12 +1,9 @@
1
1
  import { FasterSMA, FasterBollingerBands } from 'trading-signals'
2
2
  import { classifyBoll } from '../utilities/classification.js'
3
3
 
4
- const diff = (a, b) => {
5
- const value = a - b
6
- return {value: Math.abs(value), positive: value >= 0}
7
- }
4
+ const diff = (a, b) => a - b
8
5
 
9
- export const candleStudies = (main, index, size, stdDev, lag) => {
6
+ export const candleStudies = (main, index, size, stdDev, {lag, scale}) => {
10
7
 
11
8
  const { verticalOhlcv, instances, lastIndexReplace } = main
12
9
 
@@ -14,16 +11,12 @@ export const candleStudies = (main, index, size, stdDev, lag) => {
14
11
  {
15
12
  const {nullArray} = main
16
13
 
17
- Object.assign(verticalOhlcv, {
18
- candle_gap: [...nullArray],
19
- candle_body: [...nullArray],
20
- candle_top: [...nullArray],
21
- candle_bottom: [...nullArray],
22
- candle_close: [...nullArray],
23
- candle_high: [...nullArray],
24
- candle_low: [...nullArray],
25
- candle_open: [...nullArray],
26
- })
14
+ const candleParts = ['candle_body', 'candle_top', 'candle_bottom']
15
+ const candleGaps = ['candle_gap']
16
+ const candleChanges = ['candle_change_close', 'candle_change_high', 'candle_change_low', 'candle_change_open']
17
+ const keyNames = [...candleParts, ...candleGaps, ...candleChanges]
18
+
19
+ Object.assign(verticalOhlcv, Object.fromEntries(keyNames.map(k => [k, nullArray])))
27
20
 
28
21
  Object.assign(instances, {
29
22
  candleStudies: {
@@ -37,7 +30,6 @@ export const candleStudies = (main, index, size, stdDev, lag) => {
37
30
 
38
31
  if(lag > 0)
39
32
  {
40
- const keyNames = ['candle_body', 'candle_gap', 'candle_close', 'candle_high', 'candle_low', 'candle_open', 'candle_top', 'candle_bottom']
41
33
  main.lag(keyNames, lag)
42
34
  }
43
35
 
@@ -57,11 +49,15 @@ export const candleStudies = (main, index, size, stdDev, lag) => {
57
49
  const currClose = verticalOhlcv.close[index]
58
50
 
59
51
 
60
- //sizes
52
+ //parts
61
53
  const bodySize = diff(currClose, currOpen)
62
54
  const topSize = diff(currHigh, Math.max(currOpen, currClose))
63
55
  const bottomSize = diff(Math.min(currOpen, currClose), currLow)
64
- const gapSize = diff(prevClose, currOpen)
56
+
57
+ //gaps
58
+ const gapOpenClose = diff(prevClose, currOpen)
59
+
60
+ //changes
65
61
  const closeChange = diff(currClose, prevClose)
66
62
  const highChange = diff(currHigh, prevHigh)
67
63
  const lowChange = diff(currLow, prevLow)
@@ -82,11 +78,11 @@ export const candleStudies = (main, index, size, stdDev, lag) => {
82
78
  } = instances.candleStudies
83
79
 
84
80
  // Update instances with current absolute values
85
- bodyInstance.update(bodySize.value, lastIndexReplace)
86
- closeInstance.update(closeChange.value, lastIndexReplace)
87
- highInstance.update(highChange.value, lastIndexReplace)
88
- lowInstance.update(lowChange.value, lastIndexReplace)
89
- openInstance.update(openChange.value, lastIndexReplace)
81
+ bodyInstance.update(Math.abs(bodySize), lastIndexReplace)
82
+ closeInstance.update(Math.abs(closeChange), lastIndexReplace)
83
+ highInstance.update(Math.abs(highChange), lastIndexReplace)
84
+ lowInstance.update(Math.abs(lowChange), lastIndexReplace)
85
+ openInstance.update(Math.abs(openChange), lastIndexReplace)
90
86
 
91
87
  try {
92
88
  bodyBoll = bodyInstance.getResult()
@@ -99,15 +95,20 @@ export const candleStudies = (main, index, size, stdDev, lag) => {
99
95
  }
100
96
 
101
97
 
102
- main.pushToMain({index, key: 'candle_close', value: classifyBoll(closeChange, closeBoll)})
103
- main.pushToMain({index, key: 'candle_high', value: classifyBoll(highChange, highBoll)})
104
- main.pushToMain({index, key: 'candle_low', value: classifyBoll(lowChange, lowBoll)})
105
- main.pushToMain({index, key: 'candle_open', value: classifyBoll(openChange, openBoll)})
106
98
 
107
- main.pushToMain({index, key: 'candle_body', value: classifyBoll(bodySize, bodyBoll)})
108
- main.pushToMain({index, key: 'candle_gap', value: classifyBoll(gapSize, bodyBoll)})
109
- main.pushToMain({index, key: 'candle_top', value: classifyBoll(topSize, bodyBoll)})
110
- main.pushToMain({index, key: 'candle_bottom', value: classifyBoll(bottomSize, bodyBoll)})
99
+ //parts
100
+ main.pushToMain({index, key: 'candle_body', value: classifyBoll(bodySize, bodyBoll, scale)})
101
+ main.pushToMain({index, key: 'candle_top', value: classifyBoll(topSize, bodyBoll, scale)})
102
+ main.pushToMain({index, key: 'candle_bottom', value: classifyBoll(bottomSize, bodyBoll, scale)})
103
+
104
+ //gaps
105
+ main.pushToMain({index, key: 'candle_gap', value: classifyBoll(gapOpenClose, bodyBoll, scale)})
106
+
107
+ //changes
108
+ main.pushToMain({index, key: 'candle_change_close', value: classifyBoll(closeChange, closeBoll, scale)})
109
+ main.pushToMain({index, key: 'candle_change_high', value: classifyBoll(highChange, highBoll, scale)})
110
+ main.pushToMain({index, key: 'candle_change_low', value: classifyBoll(lowChange, lowBoll, scale)})
111
+ main.pushToMain({index, key: 'candle_change_open', value: classifyBoll(openChange, openBoll, scale)})
111
112
 
112
113
  return true
113
114
  }
@@ -1,36 +1,48 @@
1
+ import { calcMagnitude } from "./numberUtilities.js"
2
+
1
3
  /**
2
- * Classifies a given value relative to the Bollinger bands.
4
+ * Classifies a given value relative to provided Bollinger band thresholds.
3
5
  *
4
- * @param {Object} params - Parameters object.
5
- * @param {number} params.value - The value to classify.
6
- * @param {boolean} [params.positive=true] - Flag to determine if the result should be positive.
7
- * @param {Object} bollingerBands - Object containing the Bollinger band thresholds.
6
+ * The function evaluates the input value against the lower, middle, and upper thresholds
7
+ * of the Bollinger bands. If the value is below the lower threshold, it returns 0.
8
+ * If the value exceeds the upper threshold, it returns 1 (or -1 if the value is negative).
9
+ * For values within the bands, it calculates a normalized magnitude between 0 and 1 (or 0 and -1 for negatives)
10
+ * based on the position within the range, rounded to one decimal place.
11
+ * Additionally, if the value is nearly equal to the middle threshold (within a small tolerance),
12
+ * the function returns 0.5 or -0.5 depending on the sign of the value.
13
+ *
14
+ * @param {number} value - The value to classify.
15
+ * @param {Object} bollingerBands - An object containing Bollinger band thresholds.
8
16
  * @param {number} bollingerBands.upper - The upper band threshold.
9
17
  * @param {number} bollingerBands.middle - The middle band value.
10
18
  * @param {number} bollingerBands.lower - The lower band threshold.
11
- * @returns {number|null} The classified value, or null if inputs are invalid.
19
+ * @returns {number|null} The classified value, or null if inputs are invalid or if upper equals lower.
12
20
  */
13
- export const classifyBoll = ({ value, positive = true }, bollingerBands) => {
14
- // Validate that value and bollingerBands are not null/undefined
15
- if (value == null || bollingerBands == null) return null;
16
-
17
- const { upper, middle, lower } = bollingerBands;
18
-
19
-
20
- // Handle values outside the Bollinger bands
21
- if (value < lower) return 0;
22
- if (value > upper) return positive ? 1 : -1;
23
-
24
- // Use a tolerance for floating point comparisons
25
- const epsilon = Number.EPSILON * Math.max(Math.abs(value), Math.abs(middle));
26
- if (Math.abs(value - middle) < epsilon) return positive ? 0.5 : -0.5;
27
-
28
- // Prevent division by zero if upper and lower are equal
29
- if (upper === lower) return null;
30
-
31
- const rangeValue = (value - lower) / (upper - lower);
32
- const magnitude = Math.round(rangeValue * 10) / 10;
33
-
34
- return positive ? magnitude : -magnitude;
35
- };
36
-
21
+
22
+
23
+ export const classifyBoll = (value, bollingerBands, scale = 0.05) => {
24
+ // Validate that value and bollingerBands are not null/undefined
25
+ if (value == null || bollingerBands == null) return null
26
+
27
+ const positive = value >= 0
28
+
29
+ const { upper, middle, lower } = bollingerBands
30
+
31
+ // Handle values outside the Bollinger bands
32
+ if (value < lower) return 0
33
+ if (value > upper) return positive ? 1 : -1
34
+
35
+ // Use a tolerance for floating point comparisons
36
+ const epsilon = Number.EPSILON * Math.max(Math.abs(value), Math.abs(middle))
37
+ if (Math.abs(value - middle) < epsilon) return positive ? 0.5 : -0.5
38
+
39
+ // Prevent division by zero if upper and lower are equal
40
+ if (upper === lower) return null
41
+
42
+ const rangeValue = (value - lower) / (upper - lower)
43
+ let magnitude = calcMagnitude(rangeValue, scale)
44
+
45
+ magnitude = Math.min(Math.max(magnitude, 0), 1)
46
+
47
+ return positive ? magnitude : -magnitude
48
+ }
@@ -1,3 +1,14 @@
1
+
2
+ export const calcMagnitude = (number, magnitudeLevel = 0.1) => {
3
+
4
+ const factor = 1 / magnitudeLevel
5
+
6
+ return Math.round(number * factor) / factor
7
+ }
8
+
9
+ // Helper to clean non-numeric characters (except "-" at the start and decimal point)
10
+ export const cleanNumStr = str => str.replace(/(?!^-)[^0-9.]/g, '');
11
+
1
12
  export const divideByMultiplier = ({row, precisionMultiplier, priceBased}) => {
2
13
  const output = {}
3
14
 
@@ -1,7 +1,6 @@
1
1
  import { validateInputParams } from "./validators.js";
2
2
  import { rsi } from "../oscillators/rsi.js";
3
- import { sma } from "../moving-averages/sma.js";
4
- import { ema } from "../moving-averages/ema.js";
3
+ import { movingAverages } from "../moving-averages/movingAverages.js";
5
4
  import { macd } from "../moving-averages/macd.js";
6
5
  import { relativeVolume } from "../moving-averages/relativeVolume.js";
7
6
  import { donchianChannels } from "../moving-averages/donchianChannel.js";
@@ -13,16 +12,14 @@ import { crossPairs } from "../studies/findCrosses.js";
13
12
  import { dateTime } from "../studies/dateTime.js";
14
13
  import { priceVariations } from "../studies/priceVariations.js";
15
14
 
16
- // Helper to clean non-numeric characters (except "-" at the start and decimal point)
17
- const cleanNumStr = str => str.replace(/(?!^-)[^0-9.]/g, '');
15
+ import { cleanNumStr } from "./numberUtilities.js";
18
16
 
19
17
  // Map indicator keys to their respective functions
20
18
  const indicatorFunctions = {
21
19
  dateTime,
22
20
  priceVariations,
23
21
  rsi,
24
- sma,
25
- ema,
22
+ movingAverages,
26
23
  macd,
27
24
  relativeVolume,
28
25
  donchianChannels,
@@ -1,32 +0,0 @@
1
-
2
- import {FasterEMA} from 'trading-signals'
3
-
4
- export const ema = (main, index, size, target) => {
5
-
6
- const value = main.verticalOhlcv.close[index]
7
-
8
- let prefix = (typeof target === 'string' && main.verticalOhlcv.hasOwnProperty(target) && target !== 'close') ? `${target}_` : ''
9
- const keyName = `${prefix}ema_${size}`
10
-
11
- if(index === 0)
12
- {
13
- main.instances[keyName] = new FasterEMA(size)
14
- main.verticalOhlcv[keyName] = [...main.nullArray]
15
- }
16
-
17
- let currEma
18
- main.instances[keyName].update(value, main.lastIndexReplace)
19
-
20
- try{
21
- currEma = main.instances[keyName].getResult()
22
- } catch(err)
23
- {
24
- currEma = null
25
- }
26
-
27
- if(currEma)
28
- {
29
- main.pushToMain({index, key: keyName, value: currEma})
30
- }
31
-
32
- }
@@ -1,33 +0,0 @@
1
-
2
- import {FasterSMA} from 'trading-signals';
3
-
4
- export const sma = (main, index, size, target) => {
5
-
6
- const value = main.verticalOhlcv.close[index]
7
-
8
- let prefix = (typeof target === 'string' && main.verticalOhlcv.hasOwnProperty(target) && target !== 'close') ? `${target}_` : ''
9
- const keyName = `${prefix}sma_${size}`
10
-
11
-
12
- if(index === 0)
13
- {
14
- main.instances[keyName] = new FasterSMA(size)
15
- main.verticalOhlcv[keyName] = [...main.nullArray]
16
- }
17
-
18
- let currSma
19
- main.instances[keyName].update(value, main.lastIndexReplace)
20
-
21
- try{
22
- currSma = main.instances[keyName].getResult()
23
- } catch(err)
24
- {
25
- //do nothing
26
- }
27
-
28
- if(currSma)
29
- {
30
- main.pushToMain({index, key: keyName, value: currSma})
31
- }
32
-
33
- }