Skip to content

Commit 17e5ec8

Browse files
committed
add "psar" indicator
1 parent 6483092 commit 17e5ec8

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

.idea/crypto-trading-bot.iml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jsLibraryMappings.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/indicators.js

+23-1
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'],
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'],
137137

138138
bb: (source, indicator) =>
139139
executeTulindIndicator(source, indicator, {
@@ -293,6 +293,28 @@ module.exports = {
293293
});
294294
},
295295

296+
psar: function(source, indicator) {
297+
return new Promise(resolve => {
298+
const { options = {} } = indicator;
299+
const { step = 0.02, max = 0.2 } = options;
300+
301+
const input = {
302+
high: [],
303+
low: [],
304+
step: step,
305+
max: max
306+
};
307+
308+
source.forEach(candle => {
309+
input.high.push(candle.high)
310+
input.low.push(candle.low)
311+
})
312+
313+
const { PSAR } = require('technicalindicators');
314+
resolve({ [indicator.key]: new PSAR(input).getResult() });
315+
});
316+
},
317+
296318
heikin_ashi: function(source, indicator) {
297319
return new Promise(resolve => {
298320

test/utils/technical_analysis.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ describe('#technical_analysis for candles', () => {
151151
{
152152
indicator: 'ichimoku_cloud',
153153
key: 'ichimoku_cloud'
154+
},
155+
{
156+
indicator: 'psar',
157+
key: 'psar',
158+
options: {
159+
step: 0.01,
160+
max: 0.011
161+
}
154162
}
155163
]);
156164

@@ -228,6 +236,8 @@ describe('#technical_analysis for candles', () => {
228236

229237
assert.equal(result.adx[0] > 0, true);
230238

239+
assert.equal(result.psar[0], 8144.5);
240+
231241
const volumeByPrice = result.volume_by_price[0][0];
232242

233243
assert.equal(volumeByPrice.low > 0, true);

0 commit comments

Comments
 (0)