Trading Indicators and strategies

Hi all, my bot has been trading for a while now on Binance using simple moving averages. I would like to upgrade my strategies with a MACD but this indicator is quite difficult to code. Anyone already have this running or have any suggestions how I could learn to code this? @ivan @filip? Thanks in advance.

You could probably use this, if you have node.

Thanks Filip, I’ll try!

1 Like

Hi Filip,

Sorry to disturb you with some noobs questions.
I’ve tried the link you gave me but I was having troubles using Babel to convert the import code so I used this instead https://www.npmjs.com/package/ta-lib.macd

Looks a lot more usable but still having troubles pulling out the macd and signalLine when I import the module. What should I add to this code to pull out these values?

Thanks in advance.

This is the code:

var ema = require(‘ta-lib.ema’)

var macd = (values, fastPeriod = 12, slowPeriod = 26, signalPeriod = 9)=> {
if (Number.isFinite(fastPeriod) && Number.isFinite(slowPeriod) && fastPeriod > slowPeriod) throw new Error(‘SlowPeriod should be greater than fastPeriod!’)

var macd = [],
slowEMA = [],
fastEMA = [],
signalLine = [],
histogram = []

fastEMA = ema(values, fastPeriod)
slowEMA = ema(values, slowPeriod)

for (var i = 0; i < slowEMA.length; i++) {
macd.push(fastEMA[i] - slowEMA[i])
}

signalLine = ema(macd, signalPeriod)

for (var j = 0; j < macd.length; j++) {
histogram.push(macd[j] - signalLine[j])
}

return {macd, signalLine, histogram}
}

module.exports = macd