Previous candle's High and Low

mini

Member
Can someone help to write a script draw a line on previous 4h, 1h, 30m and 15m Candle's High and Low that can show in the lower timeframe chart? Thank you!
 
Can someone help to write a script draw a line on previous 4h, 1h, 30m and 15m Candle's High and Low that can show in the lower timeframe chart? Thank you!

this is an upper study, that draws 8 lines , for previous mtf time periods

Code:
# mtf_prev_levels
#https://usethinkscript.com/threads/previous-candles-high-and-low.16460/
#Previous candle's High and Low

def na = Double.NaN;
def bn = BarNumber();
def lastbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbn) then 1 else 0;
#def lastbar = !isnan(close[0]) and isnan(close[-1]);

input agg1 = AggregationPeriod.FIFTEEN_MIN;
input agg2 = AggregationPeriod.THIRTY_MIN;
input agg3 = AggregationPeriod.HOUR;
input agg4 = AggregationPeriod.FOUR_HOURS;

input mtf_offset = 1;
#def cls1 = highestall(if lastbar then close(period = agg1)[mtf_offset] else 0);
#def cls2 = highestall(if lastbar then close(period = agg2)[mtf_offset] else 0);
#def cls3 = highestall(if lastbar then close(period = agg3)[mtf_offset] else 0);
#def cls4 = highestall(if lastbar then close(period = agg4)[mtf_offset] else 0);

def lo1 = HighestAll(if lastbar then low(period = agg1)[mtf_offset] else 0);
def lo2 = HighestAll(if lastbar then low(period = agg2)[mtf_offset] else 0);
def lo3 = HighestAll(if lastbar then low(period = agg3)[mtf_offset] else 0);
def lo4 = HighestAll(if lastbar then low(period = agg4)[mtf_offset] else 0);

def hi1 = HighestAll(if lastbar then high(period = agg1)[mtf_offset] else 0);
def hi2 = HighestAll(if lastbar then high(period = agg2)[mtf_offset] else 0);
def hi3 = HighestAll(if lastbar then high(period = agg3)[mtf_offset] else 0);
def hi4 = HighestAll(if lastbar then high(period = agg4)[mtf_offset] else 0);

plot zlo1 = lo1;
plot zlo2 = lo2;
plot zlo3 = lo3;
plot zlo4 = lo4;

plot zhi1 = hi1;
plot zhi2 = hi2;
plot zhi3 = hi3;
plot zhi4 = hi4;
#
 
this is an upper study, that draws 8 lines , for previous mtf time periods

Code:
# mtf_prev_levels
#https://usethinkscript.com/threads/previous-candles-high-and-low.16460/
#Previous candle's High and Low

def na = Double.NaN;
def bn = BarNumber();
def lastbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbn) then 1 else 0;
#def lastbar = !isnan(close[0]) and isnan(close[-1]);

input agg1 = AggregationPeriod.FIFTEEN_MIN;
input agg2 = AggregationPeriod.THIRTY_MIN;
input agg3 = AggregationPeriod.HOUR;
input agg4 = AggregationPeriod.FOUR_HOURS;

input mtf_offset = 1;
#def cls1 = highestall(if lastbar then close(period = agg1)[mtf_offset] else 0);
#def cls2 = highestall(if lastbar then close(period = agg2)[mtf_offset] else 0);
#def cls3 = highestall(if lastbar then close(period = agg3)[mtf_offset] else 0);
#def cls4 = highestall(if lastbar then close(period = agg4)[mtf_offset] else 0);

def lo1 = HighestAll(if lastbar then low(period = agg1)[mtf_offset] else 0);
def lo2 = HighestAll(if lastbar then low(period = agg2)[mtf_offset] else 0);
def lo3 = HighestAll(if lastbar then low(period = agg3)[mtf_offset] else 0);
def lo4 = HighestAll(if lastbar then low(period = agg4)[mtf_offset] else 0);

def hi1 = HighestAll(if lastbar then high(period = agg1)[mtf_offset] else 0);
def hi2 = HighestAll(if lastbar then high(period = agg2)[mtf_offset] else 0);
def hi3 = HighestAll(if lastbar then high(period = agg3)[mtf_offset] else 0);
def hi4 = HighestAll(if lastbar then high(period = agg4)[mtf_offset] else 0);

plot zlo1 = lo1;
plot zlo2 = lo2;
plot zlo3 = lo3;
plot zlo4 = lo4;

plot zhi1 = hi1;
plot zhi2 = hi2;
plot zhi3 = hi3;
plot zhi4 = hi4;
#
Thank you so much!
 

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