Hi Lo Broke Compared Previous Day For ThinkOrSwim

Normie

New member
Looking for someone to input a column scan where a stock is above or below its previous day high/low
 
Found the below script in the thinkScript lounge. Hopefully it's what you're looking for.
Otherwise, read through this thread for more variations of High Low Breakouts:
https://usethinkscript.com/threads/previous-day-high-and-low-breakout-indicator-for-thinkorswim.154/

Code:
#This custom column plots the high or low break compared to the previous day's. Green is a high break. Red is a low break. Pink is a hi and low break with the hi break amt shown.
#Title = Broke, Revision 9/25/13
#Revised:  12:03 PM 9/25/2013

def HiBroke = If (close > high[1] ,1,0);
def LoBroke = If (close  < low[1] ,1,0);
def BothBroke = If (HiBroke && LoBroke, 1,0);
def HiBrokeAmt = If HiBroke then (close - high[1] ) else double.nan;
def LoBrokeAmt = If LoBroke then (low[1] - close) else double.nan;

Addlabel(1,  if HiBroke && !LoBroke then round(HiBrokeAmt,2)
else if !HiBroke && LoBroke then round(LoBrokeAmt,2)
else  if HiBroke && LoBroke then  round(HiBrokeAmt,2)
else 0, color.yellow);

AssignBackgroundColor(if HiBroke then color.Dark_green
else if LoBroke then color.Light_red
else if HiBroke && LoBroke then color.pink
else color.current);
 
Last edited by a moderator:
I'm trying to make a watchlist column display things better....right now it is spitting out this...the red background shows how much the current price is below the previous bar on the daily....the green shows how much it is above the previous days price....the yellow is still an "inside bar" and I made that a calculation of the percentage inside the last bar....so for instance the first yellow "44.9" is 44.9% up the bar...meaning pretty much the current price on the day is sitting around 44.9 percent of the way up the bar....I wanted to change the text to make the yellow when its inside be different as it gets a bit confusing...but also wanted to add "%' next to it...or if there was a better way to display this i would be great too...

so I wanted to change the inside bar values to percentage and perhaps be able to change the colors of the values

r6iEG8Y.png


Code:
def HiBroke = If (close > high[1] ,1,0);
def LoBroke = If (close  < low[1] ,1,0);
def BothBroke = If (HiBroke && LoBroke, 1,0);
def HiBrokeAmt = If HiBroke then (close - high[1] ) else double.nan;
def LoBrokeAmt = If LoBroke then (low[1] - close) else double.nan;
def inside = if (close < high [1] and close > low [1], 1,0);
def toptobottom = high[1] - low [1];
def insidevalue = close - low[1] ;
def insideper  = (round(((insidevalue/toptobottom)*100),1));


Addlabel(1,  if HiBroke && !LoBroke then round(HiBrokeAmt,2)
else if !HiBroke && LoBroke then round(LoBrokeAmt,2)
else  if HiBroke && LoBroke then  round(HiBrokeAmt,2)
else if inside then insideper
else 0, color.YELLOW);

AssignBackgroundColor(if HiBroke then color.Dark_green
else if LoBroke then color.Light_red
else if HiBroke && LoBroke then color.pink
else color.current);
 
@Nicksmo Try the following for the added "%"... It should work... I do concatenation all the time for labels...

Ruby:
Addlabel(1,  if HiBroke && !LoBroke then round(HiBrokeAmt,2) + "%"
else if !HiBroke && LoBroke then round(LoBrokeAmt,2) + "%"
else  if HiBroke && LoBroke then  round(HiBrokeAmt,2) + "%"
else if inside then insideper + "%"
else 0 + "%", color.YELLOW);
 
Hello - Does anyone know if it's possible to convert or add onto this code so that when the monthly high or low is broken ONLY on the day of... it is shown on that day? Currently it will show the breakout (above high or low at all times cause it is the month) but it would be better if it only indicated on the actual day of breakout imo. If anyone knows how to do this that would be helpful and appreciated. I added the code below and a pic of the code in TOS.

________________________________________________________________

#This custom column plots the high or low break compared to the previous day's. Green is a high break. Red is a low break. Pink is a hi and low break with the hi break amt shown.
#Title = Broke, Revision 9/25/13
#Revised: 12:03 PM 9/25/2013

def HiBroke = If (close > high[1] ,1,0);
def LoBroke = If (close < low[1] ,1,0);
def BothBroke = If (HiBroke && LoBroke, 1,0);
def HiBrokeAmt = If HiBroke then (close - high[1] ) else double.nan;
def LoBrokeAmt = If LoBroke then (low[1] - close) else double.nan;

Addlabel(1, if HiBroke && !LoBroke then round(HiBrokeAmt,2)
else if !HiBroke && LoBroke then round(LoBrokeAmt,2)
else if HiBroke && LoBroke then round(HiBrokeAmt,2)
else 0, color.yellow);

AssignBackgroundColor(if HiBroke then color.Dark_green
else if LoBroke then color.Light_red
else if HiBroke && LoBroke then color.pink else color.current);


BOM.JPG
 
Hello - Does anyone know if it's possible to convert or add onto this code so that when the monthly high or low is broken ONLY on the day of... it is shown on that day? Currently it will show the breakout (above high or low at all times cause it is the month) but it would be better if it only indicated on the actual day of breakout imo. If anyone knows how to do this that would be helpful and appreciated. I added the code below and a pic of the code in TOS.

________________________________________________________________

#This custom column plots the high or low break compared to the previous day's. Green is a high break. Red is a low break. Pink is a hi and low break with the hi break amt shown.
#Title = Broke, Revision 9/25/13
#Revised: 12:03 PM 9/25/2013

def HiBroke = If (close > high[1] ,1,0);
def LoBroke = If (close < low[1] ,1,0);
def BothBroke = If (HiBroke && LoBroke, 1,0);
def HiBrokeAmt = If HiBroke then (close - high[1] ) else double.nan;
def LoBrokeAmt = If LoBroke then (low[1] - close) else double.nan;

Addlabel(1, if HiBroke && !LoBroke then round(HiBrokeAmt,2)
else if !HiBroke && LoBroke then round(LoBrokeAmt,2)
else if HiBroke && LoBroke then round(HiBrokeAmt,2)
else 0, color.yellow);

AssignBackgroundColor(if HiBroke then color.Dark_green
else if LoBroke then color.Light_red
else if HiBroke && LoBroke then color.pink else color.current);

no , it is not possible
you are asking to read and retain data during a candle.
you would have to set the timeframe to day , to compare day data.

here is something to experiment with.
set chart to day
it compares the highs, of the current month. if there is a higher high, it draws an arrow.


Code:
def na = double.nan;
def bn = barnumber();
def mo = getmonth();
def lastmo = getlastmonth();
def islastmo = mo == lastmo;

def momax = if bn == 1 or isnan(close) then na
else if (islastmo and !islastmo[1]) then high
else max(high, momax[1]);

input show_higher_line = yes;
plot z2 = if show_higher_line then momax else na;
z2.SetDefaultColor(Color.magenta);

def ishigher = if bn == 1 or isnan(close) then 0
else if (islastmo and !islastmo[1]) then 0
else if momax > momax[1] then 1
else 0;

plot zhi = if ishigher then low*0.998 else na;
zhi.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zhi.SetDefaultColor(Color.cyan);
zhi.setlineweight(3);
zhi.hidebubble();


CL day
AkSEoH5.jpeg
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
313 Online
Create Post

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