Hello, I would like to color the candles according to the direction of 20 period SMA, if increasing: blue, if decreasing: orange. I tried this code but it doesn’t plot anything.
const predef = require(“./tools/predef”);
const SMA = require(“./tools/SMA”);
class simpleMovingAverage1 {
init() {
this.sma = SMA(this.props.period);
}
map(d, i, history) {
const MySMA = this.sma(d.close());
for (let i = inputs.period; i < inputs.input.length; i++) {
const c1 = MySMA[i] > MySMA[i-1] ;
const c2 = MySMA[i] < MySMA[i-1] ;
}
return {
MySMA: MySMA, //this.sma(d.value());
candlestick: {
//color: color,
color: (d.close() > MySMA && c1) ? "blue" : (d.close() < MySMA && c2) ? "orange" : undefined //'white'
},
};
}
}
module.exports = {
name: “sma1”,
description: “KK Simple Moving Average1”,
calculator: simpleMovingAverage1,
params: {
period: predef.paramSpecs.period(20)
},
tags: [“01 Indicator”],
plots: {
MySMA: { title: “MySMA” },
},
//schemeStyles: predef.styles.solidLine(“#8cecff”)
schemeStyles: {
dark: {
MySMA: predef.styles.plot(“#8cecff”),
lineStyle: 3,
}
}
};