Skip to content

Commit efcd1ed

Browse files
committed
allow setting source for "hma"
1 parent 9c31f4d commit efcd1ed

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/utils/indicators.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function executeTulindIndicator(source, indicator, tulindOptions) {
133133

134134
module.exports = {
135135
// indicators which source is Candles
136-
sourceCandle: ['cci', 'pivot_points_high_low', 'obv', 'ao', 'mfi', 'stoch', 'vwma', 'atr', 'adx', 'volume_profile', 'volume_by_price', 'ichimoku_cloud', 'zigzag', 'wicked', 'heikin_ashi', 'psar'],
136+
sourceCandle: ['cci', 'pivot_points_high_low', 'obv', 'ao', 'mfi', 'stoch', 'vwma', 'atr', 'adx', 'volume_profile', 'volume_by_price', 'ichimoku_cloud', 'zigzag', 'wicked', 'heikin_ashi', 'psar', 'hma'],
137137

138138
bb: (source, indicator) =>
139139
executeTulindIndicator(source, indicator, {
@@ -148,10 +148,17 @@ module.exports = {
148148
sma: (...args) => executeTulindIndicator(...args, { options: { length: 14 } }),
149149
ema: (...args) => executeTulindIndicator(...args, { options: { length: 14 } }),
150150
rsi: (...args) => executeTulindIndicator(...args, { options: { length: 14 } }),
151-
hma: (...args) => executeTulindIndicator(...args, { options: { length: 9 } }),
152151
roc: (...args) => executeTulindIndicator(...args, { options: { length: 6 } }),
153152
atr: (...args) => executeTulindIndicator(...args, { sources: ['high', 'low', 'close'], options: { length: 14 } }),
154153

154+
hma: (source, indicator) => {
155+
let candleSource = (indicator.options && indicator.options.source) || 'close'
156+
157+
return executeTulindIndicator(source, indicator, {
158+
sources: [candleSource],
159+
options: { length: 9 }
160+
})},
161+
155162
cci: (...args) =>
156163
executeTulindIndicator(...args, {
157164
sources: ['high', 'low', 'close'],

test/utils/technical_analysis.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ describe('#technical_analysis for candles', () => {
118118
},
119119
{
120120
indicator: 'hma',
121-
key: 'hma'
121+
key: 'hma',
122+
options: {
123+
length: 9,
124+
source: 'low'
125+
}
122126
},
123127
{
124128
indicator: 'vwma',

0 commit comments

Comments
 (0)