ThinkOrSwim 52-week Highs/Lows Scanner and Watchlist Column

mo2020

New member
52-week high/low is the highest and lowest price at which a stock has traded during the previous year. It is a technical indicator used by some traders and investors who view the 52-week high or low as an important factor in determining a stock's current value and predicting future price movement.

"Paris: Here's a watchlist you can use for percentage off 52 week high. For 52 week low, you can modify this."

Code:
# Percentage Off 52 Week High Watchlist
# Nick Name NAG®
# 11.02.2015

# This assumes a daily aggregation.  You will need to use
# daily or higher, adjust the 252 length as needed.

Round((close / Highest(high, 252) - 1) * 100)
 
Last edited:

DMacTrades

New member
@DMacTrades post a FULL SCREENSHOT of where you have the code entered
Thanks for taking a look at this. Below is the scan setup and your code in the ThinkScript Editor.

psTCvun.png


CVfPltJ.png
 

XeoNoX

Well-known member
VIP
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:

DMacTrades

New member
Thanks very much @XeoNoX. I really appreciate you looking at it and providing the fix. I will run with that and I will also check out the native TOS scanner.

Update: Works well! Thanks again.
 
Last edited:

DMacTrades

New member
Hey, how did you get the color codes on the right hand side like that?
Hi MourningWood. I used a script provided by @BenTen on page 1 of this thread to add a column to my scanner results that is red when at 52 wk low, green at 52 week high and yellow for in-between (BenTen's script uses gray instead of yellow). I have pasted the script below, but if you click back 1 page you will see the original post. Again, credit to @BenTen

Code:
# HINT: right-click on any watchlist column-->>Customize
# click and drag one of the custom choices to add it to your watchlist column choices
# click on ThinkScript tab and replace the code with this code
# BE SURE to give your new column a name and keep the name short enough it will appear on your watchlist at top of the column (ie new 52wk high)
# REMINDER - you can sort your watchlist by this column by clicking on the column header

#def allows you to teach ThinkScript new "words" that you can reference later in your code
def newHigh = high is equal to highest(HIGH (period = AggregationPeriod.DAY), 252);
def newLow = low is equal to lowest(LOW (period = AggregationPeriod.DAY), 252);

#AddLabel allows you to set conditions such as what words or values will appear when your condition is met.  Yes at the beginning means do show the label ... >=1 or ==1 means when the condition is True then _ and <=0 or ==) would mean then the condition is False then ___
AddLabel(yes, if newHigh >= 1 then "new 52wk high TODAY" else if newLow >= 1 then "new 52wk low TODAY" else " ");

#on a watchlist column AssignBackgroundColor will change the column color when conditions are met.  But AssignBackgroundColor when used in a chart Study or Strategy will change entire chart background
AssignBackgroundColor (if newHigh >= 1 then color.GREEN else if NewLow >= 1 then color.RED else color.YELLOW);

# end custom column code ------------------
 

XeoNoX

Well-known member
VIP
@vamsu A new ATH after a full year? Can you define this? From what you are saying is, the candle from 1 year ago, then see if its at all time highs? that wouldn't be all time highs. I assume you mean stocks that are at a 1 year high or 2 year high but you would have to clarify. If that's what you mean that can be found in the default built in scan in think or swim under <price performance>
 

vamsu

New member
VIP
I meant I want to find stocks which are breaking out to new ATH after 1,2+ years consolidations. For example, recently GM made a new high after 2 yr.

Basically, I want to find stocks which are making new highs after a long consolidation. Thanks for the help!
 

XeoNoX

Well-known member
VIP
you can find quite a few on the forums that fit you the best, then just set it after with the built in TOS scan for price at 12 or 24 month high
 

KELTON98

New member
Hi all, Im brand new at thinkscript so any help is appreciated!
Im looking to create a code to find stocks that are trading within 5% of their 52 week high. Can anyone help?
 

luiscervantes30

Member
VIP
Hi MourningWood. I used a script provided by @BenTen on page 1 of this thread to add a column to my scanner results that is red when at 52 wk low, green at 52 week high and yellow for in-between (BenTen's script uses gray instead of yellow). I have pasted the script below, but if you click back 1 page you will see the original post. Again, credit to @BenTen

Code:
# HINT: right-click on any watchlist column-->>Customize
# click and drag one of the custom choices to add it to your watchlist column choices
# click on ThinkScript tab and replace the code with this code
# BE SURE to give your new column a name and keep the name short enough it will appear on your watchlist at top of the column (ie new 52wk high)
# REMINDER - you can sort your watchlist by this column by clicking on the column header

#def allows you to teach ThinkScript new "words" that you can reference later in your code
def newHigh = high is equal to highest(HIGH (period = AggregationPeriod.DAY), 252);
def newLow = low is equal to lowest(LOW (period = AggregationPeriod.DAY), 252);

#AddLabel allows you to set conditions such as what words or values will appear when your condition is met.  Yes at the beginning means do show the label ... >=1 or ==1 means when the condition is True then _ and <=0 or ==) would mean then the condition is False then ___
AddLabel(yes, if newHigh >= 1 then "new 52wk high TODAY" else if newLow >= 1 then "new 52wk low TODAY" else " ");

#on a watchlist column AssignBackgroundColor will change the column color when conditions are met.  But AssignBackgroundColor when used in a chart Study or Strategy will change entire chart background
AssignBackgroundColor (if newHigh >= 1 then color.GREEN else if NewLow >= 1 then color.RED else color.YELLOW);

# end custom column code ------------------
can you share a link for this I can't seem to get it to work. Thanks
 

MarcVUM

New member
has anyone seen a tos script that draws a line to mark a defined percentage below the chart high bubble? For instance, on SPX the current 52 week high is 3894.56 and if price were to drop 5% the value would be 3699.83. Looking for a script that can draw and update the 5% line as price moves up. Thanks!
 

Similar threads

Top