I would like to add a custom code for the Macd Zero Lag here the code i dont know what i did wrong, if you can help:
const predef = require(“…/tools/predef”);
const meta = require(“…/tools/meta”);
const EMA = require(“…/tools/EMA”);
// Zero Lag EMA Calculation
function zeroLagEMA(values, period) {
let lag = (period - 1) / 2;
let EMA1 = EMA(period)(values);
let EMA2 = EMA(lag)(EMA1);
return EMA1.map((v, i) => 2 * EMA1[i] - EMA2[i]);
}
class movingAverageConvergenceDivergence {
init() {
this.signalEMA = EMA(this.props.signal);
this.zeroLagFastEMA = zeroLagEMA(this.props.fast);
this.zeroLagSlowEMA = zeroLagEMA(this.props.slow);
}
map(d, i) {
const value = d.value();
const fastEMAValue = this.zeroLagFastEMA[i];
const slowEMAValue = this.zeroLagSlowEMA[i];
const macd = fastEMAValue - slowEMAValue;
let signal;
let difference;
if (i >= this.props.slow - 1) {
signal = this.signalEMA(macd);
difference = macd - signal;
}
return {
macd,
signal,
difference,
zero: 0
};
}
filter(d) {
return predef.filters.isNumber(d.difference);
}
}
module.exports = {
name: “macd”,
description: /i18n/ “MACD”,
calculator: movingAverageConvergenceDivergence,
params: {
fast: predef.paramSpecs.period(12),
slow: predef.paramSpecs.period(26),
signal: predef.paramSpecs.period(9)
},
validate(obj) {
if (obj.slow < obj.fast) {
return meta.error(
“slow”,
/i18n/ “Slow period should be larger than fast period”
);
}
},
inputType: meta.InputType.BARS,
plotter: predef.plotters.macd,
plots: {
macd: {},
signal: {},
difference: {},
zero: { displayOnly: true }
},
areaChoice: meta.AreaChoice.NEW,
tags: [predef.tags.Oscillators],
schemeStyles: {
dark: {
macd: predef.styles.plot(“#ffe270”),
signal: predef.styles.plot(“#CC6600”),
difference: predef.styles.plot(“#FF3300”),
zero: predef.styles.plot({
color: “#7E838C”,
lineStyle: 3
})
}
}
};