52-week Highs/Lows For ThinkOrSwim

I am not sure if this any additional help you all. But, since this site has been helpful to me and I will share a few features I've added. Please see the code below and attached screenshots. I started plotting a line where 52 Wk Hi/Lo and the were displayed improper or not acceptable due to appearance setting "Fit Studies". So, I use bubbles instead to display last close/price. Since I am bullish near 52Wk Hi is one of my fav strategies, I only coded to add "percent near 52 Wk Hi". I hope this helps you. Good luck... cabe1332 :)

#52 Wk High and Low Label
# created by cabe1332 20210115_1730

# Start code

# determine if close greater than 52 wk hi and lo
def Highstate = if close >= Highest(high(period = AggregationPeriod.Week),52) then 1 else 0;
def Lowstate = if close <= Lowest(low(period = AggregationPeriod.Week),52) then 1 else 0;

# change background def if within 10% then green else light.gray
def HighstateRange = if (close >= Highest(high(period = AggregationPeriod.Week),52) * (.8995)) then 1 else 0;

# calculate percentChg diff
def Pctawayhi = Round((close / Highest(high(period = AggregationPeriod.Week),52) - 1) * (-100));

# label for 52 Wk High
AddLabel(yes, " Price " + round(Pctawayhi,0) + "% away from " + "52Wk High: " + Highest(high(period = AggregationPeriod.Week),52) + " ", if Highstaterange then Color.GREEN else Color.light_GRAY);

# label for 52 Wk Low
AddLabel(yes, "52Wk Low: " + Lowest(low(period = AggregationPeriod.Week),52), if Lowstate then Color.Red else Color.light_GRAY);

# instead of the plotting a line, bubble is use to support "Fit Studies" appearance setting
# bubble for current bar
input barsback = 0;
input price = close;

def bn = BarNumber();
def currentBar = HighestAll(if !IsNaN(price) then bn else Double.NaN);

# bubble shows currentBar price (buy or sell), if price within 10% addChartBubble percent value
addChartBubble(bn == currentBar - barsBack, close, if Highstaterange then "Price " + round(close,4) + " | " + round(Pctawayhi,0) + "% near 52Wk High" else "Price " + round(close,4),if price > price[1] then color.light_green else color.light_red);

# end of code

Gm0NFml.png


RgbF91r.png


aOsEYU9.png
Hi @cabe1332 , thanks for sharing. Would you mind sharing the buy/sell and Dist/Accumulation scripts as well? or are they on this site?
 
Hi @cabe1332 , thanks for sharing. Would you mind sharing the buy/sell and Dist/Accumulation scripts as well? or are they on this site?
@binhvesting Yes, I have posted my code on Market Pulse. For the buy/sell signals look for TrendReversal script on this site. I have modified mine to lesser signals and text to meet my requirements. Good luck... cabe1332 :)
 
Anyone have script to scan for new highs and new lows? Basically I only want to know if the last price of a min aggregation was a 52 week high. I'm trying to emulate the E*Trade Pro High Low Ticker or the Charles Schwab High/Low which will repeat symbols if they hit consecutive highs/low; TOS seems to refresh.

I took the default new highly highs/low scanner scripts and combined them like this but this outputs symbols that hit a 52w intraday so it could have happened at any point during the day. I want to know if it JUST hit a 52week high.

Code:
#HiLo Ticker 52W
high==highest(high,252)
low==lowest(low,252)

One solution I tried was scripting a custom column similar to How to COUNT CUMULATIVE or CONSECUTIVE bars on ENTIRE CHART or SPECIFIED TIME by @XeoNoX and then sort by descending in the hopes of keeping the most recent HiLo on the top of the watchlist but it doesnt seem to work as intended and I wasn't able to combine them both into one column (it sorts by one of the other). Here are a couple ways I tried:

Code:
#Hi C Run/1M
#Set Aggregation: 1min
def var = close > open;
def barUpCount = CompoundValue(1, if var then barUpCount[1] + 1 else 0, 0);
AddLabel (yes, " " + barUpCount );

#Low C Run/1M
#Set Aggregation: 1min
def var = close < open;
def barUpCount = CompoundValue(1, if var then barUpCount[1] + 1 else 0, 0);
AddLabel (yes, " " + barUpCount );

#New HIGH counter with labels 
def count_CloseUps = if high==highest(high,252)[1] then count_CloseUps[1] +1 else 0;
plot close_going_up = count_CloseUps ;
AddLabel(yes,  “ ” +  Close_going_up ,color.green);

#New LOW counter with labels 
def count_CloseDrops = if low==lowest(low,252)[1] then count_CloseDrops[1] +1 else 0;
plot close_going_down = count_CloseDrops ;
AddLabel(yes,  “ ” +  Close_going_down ,color.red);

Then I thought hey why not compare the DAY highest high to the 52week high but I cant use a secondary aggregation that way. @RobertPayne had a good idea on post #5 here but I couldn't seem to make that work either without TOS having a 52week fundamental. Also checked here but no luck. Ugh my head is spinning... Any help would be appreciated!!!
 
@XeoNoX thanks for the reply. This is one of the treads I checked haha but since it was intraday I didnt try your scan. Just tried it and love it for daily hi/los. I actually use the DailyHighLow (DAY, 1, -1, no) on my charts so this is great thanks! But I'm still looking for a 52W high... Its funny because when I first started this endeavor one workaround I used was the High/Low Graphs and they def help.

etrade's default built in scanner for HIGH/LOW constantly updates, however custom TOS scanners as watchlists only updates the scan once every 3-7 mins.

Yeah that's what people tell me but if I do a consecutive count its pretty quick ahah maybe Im crazy. Not sure if it will work OnDemand but when market opens try this:

Code:
#Consecutive New High Column 
#hint set aggregation to MIN
def count_HighUps = if high==highest(high,1442)[1] then count_HighUps[1] +1 else 0;
plot new_high = count_HighUps ;
AddLabel(yes,  “ ” +  new_high ,color.green);
 
@cygnus_stalker ...you can change the high/low graph to day, week, month, or whatever you want to change it to.
X%within 52week high is what you would want in your case, and use the the high/low graph code for percent away, obviously the closer to 100 means closer to 52 week high.
 
@XeoNoX do I have this right if I want 100% of the HiLo of the day?

Code:
input length = 1;
input BasePeriod = AggregationPeriod.DAY;
def hh = Highest(high(period = BasePeriod)[0], 1);
def ll = Lowest(low(period = BasePeriod)[0], 1);
def mid = (hh + ll) / 2;

def HighLowDegree;
if (hh == ll) {
    HighLowDegree = 0;
} else {
    HighLowDegree = (close - mid) / (hh - mid);
}
plot scan = highlowdegree > 1.00 or  highlowdegree < -1.00 ;

noob question: what is the [0] after BasePeriod defining? I'm assuming the 1 after it is the length of the aggregation. I ask because when I compare it side by side with the built in HighLow Graph (1 Day aggregation) I don't get a 1.0 in your column next to a 100% green/red graph. Maybe I'm confused on what it should be doing. Sorry!

Also tried to color it like this but all I got was black.
Code:
AddLabel(yes, if highlowdegree == 1.0 then " " + highlowdegree else if highlowdegree == -1.0 then " " + highlowdegree else " ");
AssignBackgroundColor (if highlowdegree == 1.0 then color.GREEN else if highlowdegree == -1.0 then color.RED else color.BLACK);

Maybe I'm putting the cart before the horse.
 
to be honest i dont know why they added it, its to not offset the highest high, in other words it counts the current bar highetst high
it won say 100%, you would have to convert, the code as you have it 1.0 would be 100%
 
i had a feeling it was offset. Thanks!

1.0 label is fine. Just assumed I would get a 1.0 on the same symbol I get a 100% green graph on the built in. Just to confirm, 1.0 means the last price was a daily high?
 
image.png


here.. you can use this for the scanner and add it to a watchlist

Price is WITHIN XYZ percent from year high
Code:
declare lower;
#Price is WITHIN XYZ percent from year high by XeoNoX via usethinkscript.com
#Remember to Set to day aggregation
#Price is within X% max of the 1 year high (252 Day High)
#### Change percentvalue to percent % in decimal format
###  Example .02 is 2%  and .025 is 2.5%
def percentvalue = .02;
def yearhigh = Highest(high, 252)*percentvalue;
plot scan = absvalue(close - yearhigh) is less than or equal to yearhigh;



and from that watchlist you can then use this for the column (set it to YEAR aggregation)
Price is is XYZ Percent at the YEAR HIGH on a scale of 1 to 100 (lowest yearly price to highest yearly price)
Code:
#Price is is XYZ Percent at the YEAR HIGH
#on a scale of 1 to 100 (lowest yearly price to highest yearly price)
# IMPORTANT set the column (set it to YEAR aggregation)
#by XeoNoX via usethinkscript.com
def priceHigh = high;
def pricelow = low;
def YearHigh = Highest(priceHigh, 1) ;
def YearLow = Lowest(priceLow, 1) ;
def range = Yearhigh-Yearlow;
def closing_value = close - Yearlow;
def percent = (closing_value/range)*100;
plot scan = percent;

remember to hit the THUMBS UP if you found this post useful
 
Last edited:
@XeoNoX UPDATE Ok I think you nailed it on the column and combined with my Yearly HILo Scan I think were pretty close to emulating the ETrade ticker. FYI, your scan doesn't seem to work but no biggie, just wanted to let you know. THANKS SO MUCH FOR YOUR HELP!!

One more request. Any way to script a column counter that tallies consecutive last price highs AFTER it crosses over the yearly high? In other words, once the symbol hits a 52 week high and shows 100 in your column, I'd love to count each time it consecutively goes higher. Since TOW watchlist symbols refresh instead of repeat like the Etrade ticker, a counter will let me see when a symbol is continuing to hit highs after the 52W high crossover.
 
Last edited:
@cygnus_stalker ... the scan works now, you just had to add a # to the comment. but i just added it. you should be able to copy and paste it. let me know how it works for you.
 
The only difference I see is the placement of declare lower (the one I used is below). Also thought # was ignored in the script. Do you mind explaining? I plead ignorance here...sorry.

SCAN - Price is WITHIN XYZ percent from year high
Code:
#Price is WITHIN XYZ percent from year high by XeoNoX via usethinkscript.com
declare lower;
#Remember to Set to day aggregation
#Price is within X% max of the 1 year high (252 Day High)
#### Change percentvalue to decirect % in decimal format
###  Example .02 is 2%  and .025 is 2.5%
def percentvalue = 1.0;
def yearhigh = Highest(high, 252)*percentvalue;
plot scan = absvalue(close - yearhigh) is less than or equal to yearhigh;
 
you dont need it, it just me when i code i like to see it at the bottom of the chart so i can follow/track my variables because plotting on main chart will sometimes adjust the chart scaling.
 
Oh yeah I gotcha. On that note could declare be messing with the scan since its meant for charts?

What'd you mean by:

No... A lower indicator can be dragged to the upper panel, an upper dragged to a lower panel, with certain limitations, and Scans and Custom Watchlist Columns ignore declare upper/lower...
 
@rad14733 thanks! Do you know what XeoNox meant by "the scan works now, you just had to add a # to the comment."

@XeoNoX is there any way to script a column counter that tallies consecutive last price highs AFTER it crosses over the yearly high? In other words, once the symbol hits a 52 week high and shows 100 in your column, I'd love to count each time it consecutively goes higher. Since TOW watchlist symbols refresh instead of repeat like the Etrade ticker, a counter will let me see when a symbol is continuing to hit highs after the 52W high crossover.
 
@rad14733 thanks! Do you know what XeoNox meant by "the scan works now, you just had to add a # to the comment."

@cygnus_stalker I'll let @XeoNoX comment further if I am incorrect but I think he was referring to using a # at the beginning of the declare lower; line of code to comment it out, making it ineffective - which isn't required in Scans or Custom Watchlist Columns, as I stated perviously...
 
@rad14733 thanks! Do you know what XeoNox meant by "the scan works now, you just had to add a # to the comment."

@XeoNoX is there any way to script a column counter that tallies consecutive last price highs AFTER it crosses over the yearly high? In other words, once the symbol hits a 52 week high and shows 100 in your column, I'd love to count each time it consecutively goes higher. Since TOW watchlist symbols refresh instead of repeat like the Etrade ticker, a counter will let me see when a symbol is continuing to hit highs after the 52W high crossover.
yes there is a way to do it, but you didnt define how far back you want to go, When do you want the count to start Current day only or from the entire year or charted screen
 

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

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