BarRange Percentile Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
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.

DeQNpnv.png


Code:
# BarRange Percentile
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/7yipPVGl-CM-BarRange-Percentile/

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;
rangeHigh_scan.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
rangeHigh_scan.SetDefaultColor(Color.CYAN);

plot rangeLow_scan = if arrows and rangeLowPlot then rangeLowPlot else double.nan;
rangeLow_scan.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
rangeLow_scan.SetDefaultColor(Color.MAGENTA);
 

thanos

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);
 

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top