Need help plotting horizontal lines as ranges

cappermac

New member
Need help to plot horizontal lines. Would like to consider these as current day range. Here are the conditions:

1. (Previous Day ATR / 2) + Previous Day Close = High Line
2. (Previous Day ATR / 2) - Previous Day Close = Low Line
 
Solution
Need help to plot horizontal lines. Would like to consider these as current day range. Here are the conditions:

1. (Previous Day ATR / 2) + Previous Day Close = High Line
2. (Previous Day ATR / 2) - Previous Day Close = Low Line

As displayed, this study shows the hline, lline and optional closeline plots. It is defaulted to showonly on the lastday (current).

Screenshot 2023-12-07 084015.png
Code:
input showtodayonly = yes;
input lookback = 1;
input hide_closeline = no;
input length = 14;
input averageType = AverageType.WILDERS;
input agg = AggregationPeriod.DAY;

def atr = MovingAverage(averageType, TrueRange(high(period = agg)[lookback], close(period = agg)[lookback], low(period = agg)[lookback]), length);
def pclose = close(period = agg)[lookback];

plot closeline = if...
Need help to plot horizontal lines. Would like to consider these as current day range. Here are the conditions:

1. (Previous Day ATR / 2) + Previous Day Close = High Line
2. (Previous Day ATR / 2) - Previous Day Close = Low Line

As displayed, this study shows the hline, lline and optional closeline plots. It is defaulted to showonly on the lastday (current).

Screenshot 2023-12-07 084015.png
Code:
input showtodayonly = yes;
input lookback = 1;
input hide_closeline = no;
input length = 14;
input averageType = AverageType.WILDERS;
input agg = AggregationPeriod.DAY;

def atr = MovingAverage(averageType, TrueRange(high(period = agg)[lookback], close(period = agg)[lookback], low(period = agg)[lookback]), length);
def pclose = close(period = agg)[lookback];

plot closeline = if showtodayonly and GetDay() != GetLastDay() then Double.NaN
             else pclose;
plot hline = if showtodayonly and GetDay() != GetLastDay() then Double.NaN
             else pclose + (atr / 2);
plot lline = if showtodayonly and GetDay() != GetLastDay() then Double.NaN
             else pclose - (atr / 2);

hline.SetPaintingStrategy(PaintingStrategy.DASHES);
lline.SetPaintingStrategy(PaintingStrategy.DASHES);
closeline.setpaintingStrategy(paintingStrategy.HORIZONTAL);

hline.setdefaultColor(color.green);
lline.setdefaultColor(color.red);
closeline.setdefaultColor(color.white);

closeline.sethiding(hide_closeline);

#
 
Solution
Hello again @SleepyZ. Is there a way to automatically plot horizontal lines within this range on the bodies and/or wicks of 4-hour candles (or any defined timeframe) today? Ideally, I would like to view these 4-hour horizontal lines on a 3-minute chart, but if it's only possible on a 4-hour chart, that's okay too.

Thank you.
 
Hello again @SleepyZ. Is there a way to automatically plot horizontal lines within this range on the bodies and/or wicks of 4-hour candles (or any defined timeframe) today? Ideally, I would like to view these 4-hour horizontal lines on a 3-minute chart, but if it's only possible on a 4-hour chart, that's okay too.

Thank you.

Here is the part of the above code that was modified to change the agg and a mode switch between Wicks/Body.
Code:
input agg = AggregationPeriod.DAY;

input mode = {default Wicks, Body};
def h;
def l;
switch (mode) {
case Wicks:
    h = high(period = agg)[lookback];
    l = low(period = agg)[lookback];
case Body:
    h = Max(close(period = agg)[lookback], open(period = agg)[lookback]);
    l = Min(close(period = agg)[lookback], open(period = agg)[lookback]);
}

def atr = MovingAverage(averageType, TrueRange(h, close(period = agg)[lookback], l), length);

The following full code is displayed on a 3m chart, 4hour agg with Body mode.
Screenshot 2024-01-03 124421.png

Code:
input showtodayonly = yes;
input lookback = 1;
input hide_closeline = no;
input length = 14;
input averageType = AverageType.WILDERS;
input agg = AggregationPeriod.FOUR_HOURS;

input mode = {default Wicks, Body};
def h;
def l;
switch (mode) {
case Wicks:
    h = high(period = agg)[lookback];
    l = low(period = agg)[lookback];
case Body:
    h = Max(close(period = agg)[lookback], open(period = agg)[lookback]);
    l = Min(close(period = agg)[lookback], open(period = agg)[lookback]);
}

def atr = MovingAverage(averageType, TrueRange(h, close(period = agg)[lookback], l), length);
def pclose = close(period = agg)[lookback];

plot closeline = if showtodayonly and GetDay() != GetLastDay() then Double.NaN
             else pclose;
plot hline = if showtodayonly and GetDay() != GetLastDay() then Double.NaN
             else pclose + (atr / 2);
plot lline = if showtodayonly and GetDay() != GetLastDay() then Double.NaN
             else pclose - (atr / 2);

hline.SetPaintingStrategy(PaintingStrategy.DASHES);
lline.SetPaintingStrategy(PaintingStrategy.DASHES);
closeline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

hline.SetDefaultColor(Color.GREEN);
lline.SetDefaultColor(Color.RED);
closeline.SetDefaultColor(Color.WHITE);

closeline.SetHiding(hide_closeline);

#
 

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