Previous Day High Low Rectangle For ThinkOrSwim

Ajordan930

New member
Plus
Here is a slight modification that draws a rectangle automatically of the previous days high and lows showing that range. Also currently plots dotted line for today's high/low/open. Also has labels that will show green if above, red if below, and yellow if in-between.

https://tos.mx/!kuZiUvIn

1746382511583.png


Code:
# Previous Day + Today High/Low/Open with Cloud

declare hide_on_daily;

input show_labels = yes;
input length = 1;
input showOnlyLastPeriod = yes;
input ShowBubbles = yes;
input locate_bubbles_at = {default Expansion, Time};
input locate_bubbles_at_time = 800;
input BarsFromExpansion = 8;
input ShowPricesInBubbles = yes;
input showPrevDayCloud = yes;
input cloudTransparency = 60; # 0 is solid, 100 is invisible


def na = Double.NaN;
def aggregationPeriod = AggregationPeriod.DAY;
def displace = -1;
def timeopen = SecondsFromTime(locate_bubbles_at_time) == 0;
def isExpansion = locate_bubbles_at == locate_bubbles_at.Expansion and IsNaN(close);
def firstExpansionBar = if !IsNaN(close[-1]) and isExpansion then 1 else if isExpansion then firstExpansionBar[1] + 1 else 0;
def BubbleLocation = if locate_bubbles_at == locate_bubbles_at.Time then timeopen else isExpansion and firstExpansionBar == BarsFromExpansion;

#----- Previous Day High/Low/Close -----#
plot PD_High;
plot PD_Low;
plot PD_Close;

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
PD_High = na;
PD_Low = na;
PD_Close = na;
} else {
PD_High = Highest(high(period = aggregationPeriod)[-displace], length);
PD_Low = Lowest(low(period = aggregationPeriod)[-displace], length);
PD_Close = close(period = aggregationPeriod)[-displace];
}

#----- Today's High/Low/Open -----#
def today = GetDay() == GetLastDay();
def newDay = GetDay() != GetDay()[1];
def intradayHigh = if newDay then high else if high > intradayHigh[1] then high else intradayHigh[1];
def intradayLow = if newDay then low else if low < intradayLow[1] then low else intradayLow[1];
def intradayOpen = if newDay then open else intradayOpen[1];

plot Today_High = if today then intradayHigh else na;
plot Today_Low = if today then intradayLow else na;
plot Today_Open = if today then intradayOpen else na;

# Clouds
AddCloud(
if showPrevDayCloud and !IsNaN(close) then PD_High else na,
if showPrevDayCloud and !IsNaN(close) then PD_Low else na,
Color.LIGHT_GRAY,
Color.LIGHT_GRAY
);

# Line styles and colors
PD_High.SetDefaultColor(Color.DARK_ORANGE);
PD_High.SetStyle(Curve.LONG_DASH);
PD_High.SetLineWeight(1);
PD_High.HideTitle();

PD_Low.SetDefaultColor(Color.DARK_ORANGE);
PD_Low.SetStyle(Curve.LONG_DASH);
PD_Low.SetLineWeight(1);
PD_Low.HideTitle();

PD_Close.SetDefaultColor(Color.WHITE);
PD_Close.SetStyle(Curve.LONG_DASH);
PD_Close.SetLineWeight(1);
PD_Close.AssignValueColor(if close > PD_Close then Color.GREEN else Color.RED);
PD_Close.HideTitle();

Today_High.SetDefaultColor(Color.CYAN);
Today_High.SetStyle(Curve.SHORT_DASH);
Today_High.SetLineWeight(1);
Today_High.HideTitle();

Today_Low.SetDefaultColor(Color.CYAN);
Today_Low.SetStyle(Curve.SHORT_DASH);
Today_Low.SetLineWeight(1);
Today_Low.HideTitle();

Today_Open.SetDefaultColor(Color.CYAN);
Today_Open.SetStyle(Curve.SHORT_DASH);
Today_Open.SetLineWeight(1);
Today_Open.HideTitle();

# Chart Bubbles
DefineGlobalColor("PD_High", CreateColor(255, 204, 153));
DefineGlobalColor("PD_Low", CreateColor(255, 204, 153));
DefineGlobalColor("PD_Close", Color.WHITE);
DefineGlobalColor("Today_High", Color.CYAN);
DefineGlobalColor("Today_Low", Color.CYAN);
DefineGlobalColor("Today_Open", Color.CYAN);

AddChartBubble(ShowBubbles and BubbleLocation, PD_High, "PDH: " + (if ShowPricesInBubbles then AsText(PD_High) else ""), GlobalColor("PD_High"));
AddChartBubble(ShowBubbles and BubbleLocation, PD_Low, "PDL: " + (if ShowPricesInBubbles then AsText(PD_Low) else ""), GlobalColor("PD_Low"), no);
AddChartBubble(ShowBubbles and BubbleLocation, PD_Close, "PDC: " + (if ShowPricesInBubbles then AsText(PD_Close) else ""), GlobalColor("PD_Close"));
AddChartBubble(ShowBubbles and BubbleLocation, Today_High, "HOD: " + (if ShowPricesInBubbles then AsText(Today_High) else ""), GlobalColor("Today_High"));
AddChartBubble(ShowBubbles and BubbleLocation, Today_Low, "LOD: " + (if ShowPricesInBubbles then AsText(Today_Low) else ""), GlobalColor("Today_Low"), no);
AddChartBubble(ShowBubbles and BubbleLocation, Today_Open, "TODAY OPEN: " + (if ShowPricesInBubbles then AsText(Today_Open) else ""), GlobalColor("Today_Open"));

# Labels
def abovePrevHigh = close > PD_High;
def belowPrevLow = close < PD_Low;
def withinPrevRange = close <= PD_High and close >= PD_Low;

AddLabel(show_labels and abovePrevHigh, "PDH", Color.GREEN);
AddLabel(show_labels and belowPrevLow, "PDL", Color.RED);
AddLabel(show_labels and withinPrevRange, "INSIDE PDH/PDL", Color.YELLOW);
AddLabel(show_labels, "PDC", if close > PD_Close then Color.GREEN else Color.RED);
#AddLabel(show_labels, "HOD", Color.CYAN);
#AddLabel(show_labels, "LOD", Color.CYAN);
#AddLabel(show_labels, "Open", Color.CYAN);
 

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