Display Previous High/Low In ThinkOrSwim

grapetux

Member
Hey there, looking for help in tweaking this simple previous high / low indicator.

My goal is to have the previous week's high and low displayed as bubbles on the right hand side.. currently it displays the current week's
high and lows in addition to plotting two new high/low lines, both of which I don't need.

Any help is greatly appreciated, cheers
-N

\\
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot DailyHigh;
plot DailyLow;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
} else {
DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


7bNSjHD.png
 
Hey there, looking for help in tweaking this simple previous high / low indicator.

My goal is to have the previous week's high and low displayed as bubbles on the right hand side.. currently it displays the current week's
high and lows in addition to plotting two new high/low lines, both of which I don't need.

Any help is greatly appreciated, cheers
-N

\\
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot DailyHigh;
plot DailyLow;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
} else {
DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

This will show the previous week high/low. Inputs were added to show_lines, show_bubbles, and move bubbles @bubble_displace.

Screenshot-2022-11-05-174710.png
Ruby:
input show_lines   = yes;
input show_bubbles = yes;

input aggregationPeriod = AggregationPeriod.WEEK;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;

plot DailyHigh;
plot DailyLow;

def DH = if IsNaN(close(period = aggregationPeriod)[-1])
then DH[1]
else Highest(high(period = aggregationPeriod)[-displace], length);
def DL = if IsNaN(close(period = aggregationPeriod)[-1])
then DL[1]
else Lowest(low(period = aggregationPeriod)[-displace], length);

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DailyHigh = Double.NaN;
    DailyLow  = Double.NaN;
} else {
    DailyHigh = DH;
    DailyLow  = DL;
}

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyHigh.SetHiding(!show_lines);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetHiding(!show_lines);

def bn = BarNumber();
input bubble_displace = 3;

AddChartBubble(show_bubbles and bn == HighestAll(bn - bubble_displace), DailyHigh, DailyHigh, Color.GREEN);
AddChartBubble(show_bubbles and bn == HighestAll(bn - bubble_displace), DailyLow, DailyLow, Color.RED);
 
Last edited:
This will show the previous week high/low. Inputs were added to show_lines, show_bubbles, and move bubbles @bubble_displace.
Hey SleepyZ, thanks a lot this looks great. I was trying to get a simple mid line to plot but unsuccessful

I was trying --- (Dailyhigh-dailylow) + dailylow; but getting no results,

thanks for all your help.
N
 
Hey SleepyZ, thanks a lot this looks great. I was trying to get a simple mid line to plot but unsuccessful

I was trying --- (Dailyhigh-dailylow) + dailylow; but getting no results,

thanks for all your help.
N
--just needed to divide (daillyhigh-dailylow)/2 ! figured out
 
Hi,

Please can someone help me with the code that draws horizontal line at high and low of the previous day(no extended hours)?
 
i could find one for previous week and month high low . all i found week low high ...
in lepelle key levels ..it shows previous day high low , 2 days high low , previous week high low , previous month high low
 
This should work

Code:
plot high1M = high(period = AggregationPeriod.MONTH)[1];
high1M.SetDefaultColor(Color.CYAN);

plot low1M = low(period = AggregationPeriod.MONTH)[1];
low1M.SetDefaultColor(Color.CYAN);
 
Code:
# Calculate the previous week's high and low
def prevWeekHigh = high(period = AggregationPeriod.WEEK)[1];
def prevWeekLow = low(period = AggregationPeriod.WEEK)[1];


# Add labels for the previous week's high and low
AddLabel(yes, "PrevWeek High: " + AsText(prevWeekHigh), Color.gray);
AddLabel(yes, "PrevWeek Low: " + AsText(prevWeekLow), Color.gray);
 
This will show the previous week high/low. Inputs were added to show_lines, show_bubbles, and move bubbles @bubble_displace.
hi, is it just me or is this showing the week before the previous week? so its showing the lines from 2 weeks ago. please see the attached picture. thanks

Code:
# Calculate the previous week's high and low
def prevWeekHigh = high(period = AggregationPeriod.WEEK)[1];
def prevWeekLow = low(period = AggregationPeriod.WEEK)[1];


# Add labels for the previous week's high and low
AddLabel(yes, "PrevWeek High: " + AsText(prevWeekHigh), Color.gray);
AddLabel(yes, "PrevWeek Low: " + AsText(prevWeekLow), Color.gray);
do you know how to plot these with optional horizontal lines and bubbles? thanks
 

Attachments

  • Untitled.png
    Untitled.png
    82 KB · Views: 64

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