Close Within x% Of High-Low Range For ThinkOrSwim

Drum Rocker

Member
Looking for help coding a study that will mark a price bar (any time frame) that has a close in the top 10% of it's range, or a close in the bottom 10% of it's range. For marking the bar that meets these conditions I am thinking a green dot above the price bar for a close in the top 10% of it's range and a red dot below the bar that closes in the bottom 10% of it's range. See image below.

The math for a top 10% close is: High - ((High - Low) * .10). Mark bar if close is equal to or greater than this result.
The math for a bottom 10% close is: Low + ((High - Low) * .10). Mark bar if close is equal to or less than this result.

Thanks in advance for any help with this study!


10 percent bars.jpg
 
Last edited by a moderator:
here you go:
IDENTIFY BARS/CANDLES THAT HAVE CLOSED WITHIN XYZ% FROM ITS HIGHER (TOP) and LOWER (BOTTOM) HIGH-LOW RANGE v2.0
Code:
#IDENTIFY BARS/CANDLES THAT HAVE CLOSED WITHIN XYZ% FROM ITS HIGHER (TOP) and LOWER (BOTTOM) HIGH-LOW RANGE) v2.0
#via request By XeoNoX via usethinkscript.com 07/06/2024
#change input candle percent to whatever percent you would like
input CandlePercent = 10;
plot TopPercent= close>High - ((High - Low) * (CandlePercent*.01));
plot BottomPercent = close<Low + ((High - Low) * (CandlePercent*.01));
TopPercent.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
TopPercent.SetDefaultColor(Color.green);
TopPercent.SetLineWeight(2);
BottomPercent.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
BottomPercent.SetDefaultColor(Color.RED);
BottomPercent.SetLineWeight(2);
 
Last edited by a moderator:
here you go:
IDENTIFY BARS/CANDLES THAT HAVE CLOSED WITHIN XYZ% FROM ITS HIGHER (TOP) and LOWER (BOTTOM) HIGH-LOW RANGE v2.0
Code:
#IDENTIFY BARS/CANDLES THAT HAVE CLOSED WITHIN XYZ% FROM ITS HIGH-LOW RANGE) v1.0
#via request By XeoNoX via usethinkscript.com 07/06/2024
input CandlePercent = 10;
plot top10 = close>High - ((High - Low) * (CandlePercent*.01));
plot bottom10 = close<Low + ((High - Low) * (CandlePercent*.01));
top10.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
top10.SetDefaultColor(Color.green);
top10.SetLineWeight(2);
bottom10.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
bottom10.SetDefaultColor(Color.RED);
bottom10.SetLineWeight(2);
Works perfectly. Thank you, @XeoNoX
 
Last edited by a moderator:
HI,

Posted an update on this strategy since I view overnight bars. Thanks to @XeoNoX for the initial code. I set the code up to only look at the first 4 bars on a 30 minute chart from the open and the % at 12%. Took a trade this am and was out by the 5th bar. Perfect. Code below the image:

chart.jpg


Code:
#IDENTIFY BARS/CANDLES THAT HAVE CLOSED WITHIN XYZ% FROM ITS HIGHER (TOP) and LOWER (BOTTOM) HIGH-LOW RANGE) v2.0
#via request By XeoNoX via usethinkscript.com 07/06/2024
#change input candle percent to whatever percent you would like
#@rlohmeyer--Modified for use with overnight charts to signal only on the first 2 hours
def na = double.NaN;
def OpenTime = 0930;
def RthInHours = 1.95;
def RthInSeconds = RthInHours * 60 * 60;
def SecondsTillOpen = SecondsFromTime(OpenTime);
def RTH = SecondsTillOpen >= 0 and SecondsTillOpen <= RthInSeconds;
input CandlePercent = 10;
plot TopPercent= if rth then close>High - ((High - Low) * (CandlePercent*.01)) else na;
plot BottomPercent = if rth then close<Low + ((High - Low) * (CandlePercent*.01)) else na;
TopPercent.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
TopPercent.SetDefaultColor(Color.green);
TopPercent.SetLineWeight(2);
BottomPercent.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
BottomPercent.SetDefaultColor(Color.RED);
BottomPercent.SetLineWeight(2);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
362 Online
Create Post

Similar threads

Similar threads

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.
Back
Top