52-week Highs/Lows For ThinkOrSwim

@XeoNoX To scan for a new 52 week low...Does anything else need to be updated in your script?

Code:
##Percent Away From High by XeoNoX via https://usethinkscript.com/
##  Change Percent_value to desired percent
##  Example 3.0 means 3%   1.5 means 1.5%
##  NOTE: 252 is standard agregration for days in a regular trading year according to thinkscript
##  If you want 6 Months change the "PERIOD" to 126 and for a month change to 30, Week change to 7.
##  Be sure to set the Agregation to Day
##
def Percent_value = 50;
def number_of_days = 252;

def price = close;
def choice = High;
def hi = high;
def lo = low;
plot scan = price <= lowest(lo,number_of_days )* ((100 - percent_value) /100);
#End of Script
 

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

you almost had it right, you need to add a negative for the percent value. here is the correct code for scanning for the LOWEST (period) low, in this case this example below scans for stocks within 10% of the 252 day (52 week) low

Code:
##Percent Away From Low by XeoNoX via https://usethinkscript.com/
##  Change Percent_value to desired percent
##  Example -3.0 means 3%   -1.5 means 1.5% away from the (number_of_day/period) low
##  NOTE: 252 is standard agregration for days in a regular trading year according to thinkscript
##  If you want 6 Months change the "PERIOD" to 126 and for a month change to 30, Week change to 7.
##  Be sure to set the Agregation to Day
##
def Percent_value = -10;
def number_of_days = 252;

def price = close;
def choice = High;
def hi = high;
def lo = low;
plot scan = price <= lowest(lo,number_of_days )* ((100 - percent_value) /100);
#End of Script
 
Thank you for correcting this...As you can tell I am not a coder but trying as much as I can to figure things out on my own...This scan will come in very handy.
Your welcome.... Keep trying and playing with it and asking questions, its how i learned, i didnt mean to learn it, it just happened as i started coming up with ideas and a bunch of trial and error and research. i still have much to learn.
 
@sivakumar777 That's not the correct way to do it. You can't add a watchlist column via the Scan tab.

Watch the second half of the video below if you need help with adding custom watchlist columns.

 
p7oQ3yr.png


Hope i posted the image right, Im trying to find stocks 5% BELOW the 52wk high....using this finds me stocks above AND below... any help
 
I was more looking to catch things before the break of a new high, like 10day or 1month high, so i prefer a scan
@Nikola @vro3 what @BenTen gave would work as a scan with a change of a few words.

Further, the picture in the 1st post returned just what it was supposed to.

Try the built in High, Higher or Highest as you've built in 1st post.

Read the manual. Keep trying. Look in the tutorials section, I know the OneNote has some direction also. Good luck.
 
I'm looking to create a scan that has multiple filters. One of the filters, I'd like to create is to identify if the stock is within 5 % of the 52 week high. I have this code which identifies if it equals the 52 week high, but not sure how to do the math for the %.

Code:
plot scan;
scan = close == highest(high,52);
 
@Greezee price 5% within 52 week high

Appreciation Goes a long way, remember to hit the like button if you found this post useful

Code:
def price = close;
input period = 252;

input choice1 = 5.0;

def hi = high;


def  scan = price >= highest(hi,period)* ((100 - choice1) /100);
 
The following code will create two labels that display the 52 week high and low on any time frame. Please note: you must have at least 2 Days of data. In other words, this works on 2D:1M not 1D:1M. It works on 5D:5M, 5D:15M, 10D:30M, 20D:1H, 180D:4H, 1Y:1D and 3Y:1W. Again, to use this on the 1 min chart you need to create a custom time frame of at least 2D:1M for it to work.

RFlpggy.png


Code:
#CODE BELOW
AddLabel(1, "52Week HIGH = " + Highest(high(period = AggregationPeriod.Week),52), Color.green);
AddLabel(1, "52Week LOW = " + Lowest(low(period = AggregationPeriod.Week),52), Color.red);
#END CODE
 
Hi @XeoNoX. First off, thanks for posting. Much appreciated.

I am getting results that don't seem to match the % off the 52 high. For example, I am running a scan on January 18, 2021 using the code set at 5% off the high of the past 252 days (code below) and I am getting results where the difference between the closing price of the ticker and the 52 week high are significantly greater than 5%. Am I doing something wrong? In this instance, I am looking for tickers that are 5% below their high of the past year.

Thanks for your help!

CODE AS ENTERED IN THINKSKIPT:

Code:
##Percent Away From High by XeoNoX via [URL]https://usethinkscript.com/[/URL]
##  Change Percent_value to desired percent
##  Example 3.0 means 3%   1.5 means 1.5%
##  NOTE: 252 is standard agregration for days in a regular trading year according to thinkscript
##  If you want 6 Months change the "PERIOD" to 126 and for a month change to 30, Week change to 7.
##  Be sure to set the Agregation to Day
##
def Percent_value = 5;
def number_of_days = 252;

def price = close;
def choice = High;
def hi = high;
def lo = low;
plot scan = price <= highest(hi,number_of_days )* ((100 - percent_value) /100);
#End of Script
 
You're right, its not working right. Formula is not correct.
change to
Code:
plot  scan = price >= highest(hi,number_of_days )* ((100 - percent_value) /100);

so that it says:
Code:
##Percent Away From High by XeoNoX via https://usethinkscript.com/
## Change Percent_value to desired percent
## Example 3.0 means 3% 1.5 means 1.5%
## NOTE: 252 is standard agregration for days in a regular trading year according to thinkscript
## If you want 6 Months change the "PERIOD" to 126 and for a month change to 30, Week change to 7.
## Be sure to set the Agregation to Day
##
def price = close;
input number_of_days = 252;
input percent_value = 3.0;

def hi = high;
def lo = low;

plot scan = price >= highest(hi,number_of_days )* ((100 - percent_value) /100);

or

You can use the built in scanner under PRICE PERFORMANCE >NEAR HIGHS LOWS

aPtBkQm.png
 
Last edited:
Thread starter Similar threads Forum Replies Date
inthefutures New Intraday Highs and Lows For ThinkOrSwim Indicators 0

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
528 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