Is there any way of having the option to have bars ( open, high, low & close) instead of the line chart on the RSI. I am trying to figure out where or what to input on the code but have no idea
const predef = require("./tools/predef");
const meta = require("./tools/meta");
const MMA = require("./tools/MMA");
const SMA = require("./tools/SMA");
const p = require("./tools/plotting");
class relativeStrengthIndex {
init() {
this.lossAverage = MMA(this.props.rsiLength);
this.gainAverage = MMA(this.props.rsiLength);
this.rsiSmooth = SMA(this.props.smoothLength);
this.emaPrev = 50;
}
// v 01.23.2019
map(d, i, history) {
const difference = i > 0 ? d.value() - history.prior().value() : 0;
const averageGain = this.gainAverage(Math.max(difference, 0));
const averageLoss = this.lossAverage(Math.max(-difference, 0));
let rsi = null;
let ema = 50;
let alpha = 2.0 / (this.props.emaLength + 1);
if (i >= this.props.rsiLength) {
let rsi1 = 100 - (100 / (1 + (averageGain / averageLoss)));
rsi = this.props.useCumulativeRSI ? this.rsiSmooth(rsi1) : rsi1;
if(i > 1) {
ema = alpha * rsi + (1 - alpha) * this.emaPrev;
}
}
this.emaPrev = ema;
return {
rsi,
ema,
middle: 50,
overbought: this.props.overbought,
oversold: this.props.oversold,
hist: this.props.useHist,
};
}
filter(d) {
return predef.filters.isNumber(d.rsi);
}
}
function rsiPlotter(canvas, indicatorInstance, history) {
for(let i=0; i<history.data.length; ++i) {
const item = history.get(i);
if(item.hist) {
if (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
});
}
} else {
break;
}
}
}
module.exports = {
name: “rsi2”,
description: “Relative Strength Index - Histogram”,
calculator: relativeStrengthIndex,
params: {
rsiLength: predef.paramSpecs.period(2),
emaLength: predef.paramSpecs.period(8),
smoothLength: predef.paramSpecs.period(3),
useCumulativeRSI: {
type: “boolean”,
def: false,
},
useHist: {
type: “boolean”,
def: false,
},
overbought: predef.paramSpecs.period(95),
oversold: predef.paramSpecs.period(5)
},
plots: {
rsi: { title: “RSI” },
ema: { title: “EMA” },
middle: { displayOnly: true },
overbought: { displayOnly: true },
oversold: { displayOnly: true }
},
plotter: [
predef.plotters.custom(rsiPlotter),
predef.plotters.singleline(“rsi”),
predef.plotters.singleline(“ema”),
predef.plotters.singleline(“middle”),
predef.plotters.singleline(“overbought”),
predef.plotters.singleline(“oversold”)
],
tags: [predef.tags.Oscillators],
areaChoice: meta.AreaChoice.NEW,
schemeStyles: {
dark: {
rsi: predef.styles.plot("#eeeeee"),
ema: predef.styles.plot("#2258B2"),
middle: predef.styles.plot({ color: “#7E838C”, lineStyle: 3 }),
overbought: predef.styles.plot({ color: “#5DC74F”, lineStyle: 3 }),
oversold: predef.styles.plot({ color: “#E52545”, lineStyle: 3 })
}
}
};