Hi, trying to modify master Tiki’s Range Forecast code to plot on the current index only (full code at bottom), so for the upper and lower plots want to replace “if (i > 0) {” with something like If(currentindex){ …
Been through the github and many indicators and assuming there is a way to identify the current bar, but not seeing/understanding how to do this. Starting to understand how to use “prior” and “back” and how to get “i”, but my brain can’t cipher how to get there with these.
FYI, using “If(prior)” it doesn’t plot on prior bars when the chart is initially loaded, but unfortunately it doesn’t repaint them to null when they are complete, so end up with the same issue.
Thank you for any help
Original code:
class tikiRangeForecast {
init() {
this.tickSize = this.contractInfo.tickSize
}
map(d, i, history) {
if (i > 0) {
const prior = history.prior()
const range = prior.high() - prior.low()
const high = d.high()
const low = d.low()
const currentRange = high - low
const rangeDiff = range - currentRange
const upper = high + rangeDiff
const lower = low - rangeDiff
let style
if (currentRange >= range) {
style = {
upper: {
color: 'transparent',
},
lower: {
color: 'transparent'
}
}
}
return {
upper,
lower,
style
};
}
}
}