Range Bar Predictor
CompletedHi Guys,
I use range bars a lot for my intra day trading. In Ninja I have an indicator that predicts where the current range bar will finish based on the current price either higher or lower. Once the bar touches the max range of the bar say 6 ticks, then the predictor changes to a "locked" color of red with the max price high and low printed above and below the indicator on the chart.
Does anyone have something similar or can someone code it up fairly quickly?
Thanks in advance!
-
Also see below code from Trade Station in Easy Language from Robert:
// Range Bar Countdown
[LegacyColorValue = false];
inputs: TextHalfColor(cyan), TextFinishColor(yellow), decimal(2);
vars:
rangevalue(0),
rangecount(0),
rangeleft(0),
rangehi(0),
rangelo(0),
rangeopen(0),
str(" "),
ID(-1),
ID1(-1),
ID2(-1),
Textcolor(yellow);
If barnumber = 2 then rangevalue = range[1];
rangecount = H - L;
rangeleft = rangevalue - rangecount;
rangehi = l + rangevalue;
rangelo = h - rangevalue;
rangeopen = o;
//str = "RR: "+numtostr(rangeleft,decimal);
//if rangecount < .5*rangevalue then TextColor = TextHalfColor;
//if rangecount > .5*rangevalue then TextColor = TextFinishColor;
ID = text_new(date,calctime(time,(barinterval*10)),close,str);
text_SetColor(ID,TextColor);
If Barstatus(1) <> 1 then
If ID > 0 then Text_Delete(ID);
ID1 = text_new(date,calctime(time,(barinterval*10)),rangehi,numtostr(rangehi,decimal));
text_SetColor(ID1,TextColor);
If Barstatus(1) <> 1 then
If ID1 > 0 then Text_Delete(ID1);
ID2 = text_new(date, -
Alrighty, took an initial crack at this one. It should automatically pick up the range based on the high and low, and when the bar has reached its maximum range, the plot should disappear.

After installing `Tiki Range Forecast` using Code Explorer, you should find it located in the `Channels` menu.
Be sure that either the `Range` or `Momentum Range` chart type is enabled and the chart is fully refreshed or funny things may happen!
Please let me know of any issues. Cheers!
-
I have modified the code of this to produce two lines that will only appear on the final bar. I noticed that the dots still appear for historical bars. The length and color of the horizontal line can be adjusted and does determine the correct price to produce a next candle depending on if the chart is Range or Momentum Range.
const predef = require("./tools/predef");
const meta = require("./tools/meta");
const p = require("./tools/plotting");class rangeForecast {
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 isMomentumRange = d.open() == prior.close();
const upper = isMomentumRange ? high + rangeDiff : high + rangeDiff + this.tickSize;
const lower = isMomentumRange ? low - rangeDiff : low - rangeDiff - this.tickSize;
return {
upper,
lower,
upperColor: this.props.upperColor,
lowerColor: this.props.lowerColor,
rangeDiff,
offset: this.props.offset
};
}
return {};
}
}function rangePlotter(canvas, indicatorInstance, history) {
for(let i = history.data.length - 1; i < history.data.length; ++i) {
const item = history.get(i);
if(i > item.offset && (item.rangeDiff > 0 || i == (history.data.length - 1))) {
const item1 = history.get(i - item.offset);
const x = p.x.get(item);
const x1 = p.x.get(item1);
canvas.drawLine(
p.offset(x1, item.upper),
p.offset(x, item.upper),
{
color: item.rangeDiff > 0 ? item.upperColor : "#00000000",
width: 1,
opacity: 1
});
canvas.drawLine(
p.offset(x1, item.lower),
p.offset(x, item.lower),
{
color: item.rangeDiff > 0 ? item.lowerColor : "#00000000",
width: 1,
opacity: 1
});
}
}
}module.exports = {
name: "rangeForecast",
description: "Range Forecast",
calculator: rangeForecast,
params: {
upperColor: predef.paramSpecs.color('forestgreen'),
lowerColor: predef.paramSpecs.color('firebrick'),
offset: predef.paramSpecs.period(8),
},
inputType: meta.InputType.BARS,
plots: { },
plotter: [
predef.plotters.custom(rangePlotter)
],
tags: ['My Indicators'],
schemeStyles: {}
}; -
Hi Cameron,
I like your version much better but every time i click on a different tab in my workspace and leave the chart with the indicator on it, when I click back, the indicator is gone. It still shows in my indicator list for that chart but its not actually on the chart. Any ideas?
Please sign in to leave a comment.


Comments
10 comments