RsiColorBar

Plots a bar of open, high low and close instead of a line RSI and it is color

class RelativeStrengthIndex {
constructor(props) {
this.props = props;
this.lossAverage = new MMA(this.props.rsiLength);
this.gainAverage = new MMA(this.props.rsiLength);
this.rsiSmooth = new SMA(this.props.smoothLength);
this.emaPrev = 50;
this.secondEmaPrev = 50;
}

map(data, index, history) {
    const difference = index > 0 ? data.value - history[index - 1].value : 0;
    const averageGain = this.gainAverage.calculate(Math.max(difference, 0));
    const averageLoss = this.lossAverage.calculate(Math.max(-difference, 0));

    let rsi = null;
    let ema = 50;
    let secondEma = 50;
    const alpha = 2.0 / (this.props.emaLength + 1);
    const secondAlpha = 2.0 / (this.props.secondEmaLength + 1);

    if (index >= this.props.rsiLength) {
        let rsi1 = 100 - (100 / (1 + (averageGain / averageLoss)));
        rsi = this.props.useCumulativeRSI ? this.rsiSmooth.calculate(rsi1) : rsi1;

        if (index > 1) {
            ema = alpha * rsi + (1 - alpha) * this.emaPrev;
            secondEma = secondAlpha * rsi + (1 - secondAlpha) * this.secondEmaPrev;
        }
    }

    this.emaPrev = ema;
    this.secondEmaPrev = secondEma;

    return {
        rsi,
        ema,
        secondEma,
        middle: 50,
        overbought: this.props.overbought,
        oversold: this.props.oversold,
        hist: this.props.useHist,
    };
}

filter(data) {
    return typeof data.rsi === 'number';
}

}

function rsiPlotter(canvas, indicatorInstance, history) {
history.forEach((item, index) => {
if (item.hist && item.rsi !== undefined) {
const x = p.x.get(item);
const ob = item.overbought;
const os = item.oversold;

        canvas.drawLine(
            p.offset(x, 50),
            p.offset(x, item.rsi),
            {
                color: item.rsi > ob ? "#FF0000DD" : item.rsi < os ? "#00FF00DD" : "#FFFFFF22",
                relativeWidth: 0.5,
                opacity: 1.0,
            }
        );
    }
});

}

module.exports = {
name: “rsi_with_dual_ema”,
description: “Relative Strength Index with Dual EMA”,
calculator: RelativeStrengthIndex,
params: {
rsiLength: 2,
emaLength: 8,
secondEmaLength: 14,
smoothLength: 3,
useCumulativeRSI: false,
useHist: false,
overbought: 95,
oversold: 5,
},
plots: {
rsi: { title: “RSI” },
ema: { title: “EMA” },
secondEma: { title: “Second EMA” },
middle: { displayOnly: true },
overbought: { displayOnly: true },
oversold: { displayOnly: true },
},
plotter: [rsiPlotter],
};