BarRange Percentile Indicator for ThinkorSwim



Here is a minimal port of the BarRange Percentile indicator from TradingView. I thought it was very interesting. Paintbars and arrows are being plotted by default. You can easily turn either one off via the indicator's setting—no need to touch the code. The up arrows are there to help you with the scanner and also to help identify the candle in case you don't want the painrbars.

I know a Trader that went 18 months without a losing trade. This Trader averaged trading 700-800 contracts per month in the Futures markets.

The was not his only system but here were his rules.

He looked at the 60 minute bar and calculated the ranges of the bars over the last 3 months. IF the range of the Bar was Greater Than the 99th Percentile, He would Fade that move or take the trade in the opposite direction.

Thought process is If the Price Bar is Greater Than the 99th Percentile then typically the market reverses. This happens a lot of times at news events. If you’ve studied the markets long enough you know if a Nes based event causes a Huge Move, which we define as Greater than the 99th Percentile, the Market typically moves in the opposite direction.

***This is dependent on the Instrument your trading and the time frame your trading. Some Instruments and time frames this signals a continuation move.

I also added in the Low of the Range based on the 99th Percentile. Often times Low Range Bars…especially if they appear at the top of a swing move, or the bottom of a swing move…create a high probability entry once the High or Low of the bar is taken out in the opposite direction of the previous move…The Low Range bars show indecision after a strong move and create great reversal opportunities.

Works on All Time Frames…again depending on the instrument your trading.

On instruments that MOVE or have High Volatility like Crude and Oil you can get great signals on 1 minute bars.

# BarRange Percentile
# Assembled by BenTen at
# Converted from

input paintbars = yes;
input arrows = yes;

input lb = 60;
input ph = 0.99;
input pl = 1.01;

def range = high - low;

def rangeHigh = (highest(range, lb)) * ph;
def rangeHighPlot = range > rangeHigh;
def rangeHighPlot2 = rangeHighPlot * range;
def rangeLow = (lowest(range, lb)[1]) * pl;
def rangeLowPlot = range < rangeLow;
def rangeLowPlot2 = rangeLowPlot;

# 50% Value of Range
def averageRange = (rangeHigh + rangeLow) / 2;

assignPriceColor(if paintbars and rangeHighPlot then Color.Yellow else if paintbars and rangeLowPlot then Color.MAGENTA else if paintbars then Color.WHITE else color.Current);

# Warning: arrows does not suggest the direction of the move. Solely there to help with using the scanner.

plot rangeHigh_scan = if arrows and rangeHighPlot then rangeHighPlot else double.nan;

plot rangeLow_scan = if arrows and rangeLowPlot then rangeLowPlot else double.nan;


New member
Maybe consider a rank caculation on the range using a fold (loop). Then use the AssignPriceColor based on the rank (i.e ==99)

input lookback = 400; # about 3 months worth of 60 min bars
rankHigh = 99;

def range = absValue(open-close);
def rRank = fold x = 1 to lookback + 1 with r = 0 do r + (GetValue(range, x, lookback) < range) ;
def rangeRank = (rRank / lookback) * 100;

AssignPriceColor(if rangeRank > rankHigh then Color.Yellow else Color.current);

Similar threads