Macd zero lag

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
})
}
}
};

I have never built an indicator in Tradovate, but I have a few in TradingView…

Here is my guess by glancing over your code

let lag = (period - 1) / 2;

This code will give you fractions that will likely mess up the EMA functions. Try using a round function to see if that solves your issue. Good luck!

1 Like

Thanks Frik,

I’ll try the modification

Shameless plug while I try to get the word out :sweat_smile: we have a Zero Lag EMA at Tikitrade that can be used with all indicators that feature a Moving Average, including MACD.

The Tiki MACD also comes w/ a paint bars feature to help visualize the turning points.

Cheers!

Tiki Dave

1 Like

Hey, I’ve been looking for a zero lag macd for Tradovate but can’t find any. You mention this one above from Tiki MACD…I tried searching for it but it’s no longer there or I just can’t find it.

Does this still exist?

Thanks :blush:

Did you ever get this to work? I’m interested :grin:

Heya @RobW, yes it exists but you’ll need a subscription at https://tikitrade.com to access it as it is part of my premium library. We have a 14 day free trial so you can check it out with no worries - please let me know if it doesn’t meet your needs - cheers!

Hey Dave, I’ll definitely think about it. I don’t that specific indicator in the library but you’re sure it’s possible to have the Macd overlap the RSI and be possible to change the midline points?

I’m not sure how long I’ll be with Tradovate but if I do stick around it will be good to know if this indicator can do exactly what I need it to do.

Many thanks for your reply

Sorry, meant to say “I don’t see that specific indicator…”

Ah, so the RSI can be placed on the MACD chart by configuring the “Add as…” option:

However, here is how it looks currently:

I could provide an option on the RSI to change the midline to 0, then they would align better. Is that what you are looking for?

By the way, everything on these is configurable, i.e. showing/hiding all the plot lines, colors, styling, etc., so you could customize them to stand apart better.

Unfortunately that’s not what I’m looking for. I don’t think Tradovate can do this type of overlaying of the two indicators.

I am code developer. send me an email on timmfain@gmail.com to help you with your requirement.