hi ppl trying to make a custom indicator, but like most having issues i cant get in on my indictor tab for some reason. any pointer or videos will be appericated.
i just took the existing Cvd on tradovate and had chat gpt to add 4 ema’s
here is the code if any one want to help
const predef = require(“./tools/predef”);
const meta = require(“./tools/meta”);
class cumulativeDeltaHistogram {
init() {
this.delta;
this.last = 0;
this.sessionLast = 0;
this.line;
this.cumulativeDelta;
this.ema10;
this.ema20;
this.ema50;
this.ema200;
}
map(d, index, history) {
// Delta
let delta = d.offerVolume() - d.bidVolume();
if (this.props.resetSession){
// Session cumulative delta
let sessionCumulativeDelta = this.sessionLast + delta;
this.sessionLast = sessionCumulativeDelta;
const timestamp = d.timestamp();
const currentTime = timestamp.getHours()*60 + timestamp.getMinutes();
const sessionStartTime = this.props.sessionStartHour * 60 + this.props.sessionStartMinute;
if (history.prior()) {
const priorTimestamp = history.prior().timestamp();
const priorTime = priorTimestamp.getHours()*60 + priorTimestamp.getMinutes();
if (priorTime < sessionStartTime && currentTime >= sessionStartTime) {
sessionCumulativeDelta = delta;
this.sessionLast = sessionCumulativeDelta;
}
}
this.cumulativeDelta = sessionCumulativeDelta;
}else{
// Cumulative Delta
let fullCumulativeDelta = this.last + delta;
this.last = fullCumulativeDelta;
this.cumulativeDelta = fullCumulativeDelta;
}
const deltaColor = { color: this.cumulativeDelta > 0 ? "green" : "red" };
// Show lines if true
if (this.props.showLine) {
this.line = this.cumulativeDelta;
}
// EMA calculations
const alpha10 = 2 / (10 + 1);
const alpha20 = 2 / (20 + 1);
const alpha50 = 2 / (50 + 1);
const alpha200 = 2 / (200 + 1);
if (index === 0) {
this.ema10 = this.cumulativeDelta;
this.ema20 = this.cumulativeDelta;
this.ema50 = this.cumulativeDelta;
this.ema200 = this.cumulativeDelta;
} else {
this.ema10 = alpha10 * this.cumulativeDelta + (1 - alpha10) * this.ema10;
this.ema20 = alpha20 * this.cumulativeDelta + (1 - alpha20) * this.ema20;
this.ema50 = alpha50 * this.cumulativeDelta + (1 - alpha50) * this.ema50;
this.ema200 = alpha200 * this.cumulativeDelta + (1 - alpha200) * this.ema200;
}
return {
line: this.line,
value: this.cumulativeDelta,
ema10: this.ema10,
ema20: this.ema20,
ema50: this.ema50,
ema200: this.ema200,
style: { value: deltaColor }
};
}
}
module.exports = {
name: “cumulativeDeltaHistogram”,
description: “Cumulative Delta Histogram”,
calculator: cumulativeDeltaHistogram,
params: {
resetSession: predef.paramSpecs.bool(true),
sessionStartHour: predef.paramSpecs.percent(18, 1, 0, 23),
sessionStartMinute: predef.paramSpecs.percent(0, 1, 0, 59),
showLine: predef.paramSpecs.bool(true),
},
inputType: meta.InputType.BARS,
areaChoice: meta.AreaChoice.NEW,
tags: [predef.tags.Volumes],
plots: {
value: {title: ‘Cum Δ’},
line: {title: ‘Line’, displayOnly: true},
ema10: {title: ‘EMA 10’, color: ‘green’},
ema20: {title: ‘EMA 20’, color: ‘blue’},
ema50: {title: ‘EMA 50’, color: ‘orange’},
ema200: {title: ‘EMA 200’, color: ‘red’},
},
plotter: [
predef.plotters.histogram,
predef.plotters.singleline(“line”),
predef.plotters.ma(“ema10”),
predef.plotters.ma(“ema20”),
predef.plotters.ma(“ema50”),
predef.plotters.ma(“ema200”)
],
schemeStyles: {
dark: {
line: {color: “ACE5EE”, lineStyle: 1}
}
}
};
thanks for your time.