Hello Traders, I’m trying to add a 5-period EMA to the CCI indicator and couldn’t make the EMA appear on the chart. Any help please? Thanks!
const predef = require(“./tools/predef”);
const meta = require(“./tools/meta”);
const SMA = require(“./tools/SMA”);
const EMA = require(“./tools/EMA”);
const typicalPrice = require(“./tools/typicalPrice”);
class commodityChannelIndex3 {
init() {
this.sma = new SMA(this.props.period);
this.ema = new EMA(this.props.periodSig);
}
map(d, i, history) {
const tp = typicalPrice(d);
this.sma.push(tp);
let cci;
if (i >= this.props.period) {
cci = (tp - this.sma.avg()) / (0.015 * this.sma.meanDeviation());
}
const cciSig = this.ema(cci);
const color = (cci>cciSig) ? "lime" : (cci<cciSig) ? "red" : "yellow" ;
return {
cci:cci,
cciSig:cciSig,
candlestick: {
color
}
};
}
filter(d) {
return predef.filters.isNumber(d.cci);
}
}
module.exports = {
name: “cci3”,
description: “KK Commodity Channel Index3”,
calculator: commodityChannelIndex3,
params: {
period: predef.paramSpecs.period(21),
periodSig: predef.paramSpecs.period(5)
},
inputType: meta.InputType.BARS,
areaChoice: meta.AreaChoice.NEW,
tags: [“01 Indicator”],
plots: {
cci: { title: “CCI”},
cciSig: { title: “CCISig”},
},
schemeStyles: {
dark: {
cci: {color: “red”, lineStyle: 1 },
cciSig: {color: “cyan”, lineStyle: 3 },
}
}
};