Help with relative range?

Headhunter20

New member
I think I have the position of the current price relative to the high and low of different time frames (Monthly, weekly, and daily)
I would love for someone to take a look at this and help with being able to plot the relative range for the current price position relative to the current candle of a monthly and a weekly chart instead of the highest and lowest of that time frame (maybe a 6month1month chart, a 6month1week chart and of course the 6month1day chart) Any help would be greatly appreciated.
**************************************************

# Monthly Relative Range (MRR)
input price3 = close;
def MonthlyHigh = Highest(high, 21);
def monthlyLow = lowest(low, 21);
def MRR = Round((price3 – monthlyLow) / (MonthlyHigh – monthlyLow) * 100);
AddLabelForReferencing(yes, Concat(MRR, " % MRR"), if MRR > 75 then Color.DARK_GREEN else if MRR < 50 then Color.RED else Color.ORANGE);
def Z = MRR;

#Weekly Relative Range (WRR)
input price2 = close;
def weeklyHigh = Highest(high, 5);
def weeklyLow = Lowest(low, 5);
def WRR = Round((price2 – weeklyLow) / (weeklyHigh – weeklyLow) * 100);
AddLabelForReferencing(yes, Concat(WRR, " % WRR"), if WRR > 75 then Color.DARK_GREEN else if WRR < 50 then Color.RED else Color.ORANGE);
def x = WRR;

#Daily Relative Range (DRR)
input price = close;
def DRR = Round((price2 – low) / (high – low) * 100);
AddLabelForReferencing(yes, Concat(DRR, " % DRR"), if DRR > 75 then Color.DARK_GREEN else if DRR < 25 then Color.DARK_RED else Color.orange);
def y = DRR;
 
Solution
I think I have the position of the current price relative to the high and low of different time frames (Monthly, weekly, and daily)
I would love for someone to take a look at this and help with being able to plot the relative range for the current price position relative to the current candle of a monthly and a weekly chart instead of the highest and lowest of that time frame (maybe a 6month1month chart, a 6month1week chart and of course the 6month1day chart) Any help would be greatly appreciated.
**************************************************

i wasn't quite sure what you were asking for. this is what popped into my head.

MTF columns
show 3 colored columns, after the last bar, that represent the price ranges of 3...
I think I have the position of the current price relative to the high and low of different time frames (Monthly, weekly, and daily)
I would love for someone to take a look at this and help with being able to plot the relative range for the current price position relative to the current candle of a monthly and a weekly chart instead of the highest and lowest of that time frame (maybe a 6month1month chart, a 6month1week chart and of course the 6month1day chart) Any help would be greatly appreciated.
**************************************************

i wasn't quite sure what you were asking for. this is what popped into my head.

MTF columns
show 3 colored columns, after the last bar, that represent the price ranges of 3 time periods, day, week, month.

draw horizontal lines for the highest and lowest prices during the time periods.

3 labels show the % ratio of close in each range.

use a chart setting with enough days, otherwise the month or week columns won't be displayed.
light blue labels will appear, warning the user of the situation.
this uses 2nd aggregation for finding the highs and lows.
i used a 30day 15min chart for testing.


Ruby:
# relative_range_mtf_00d

# show a colored column of MTF price ranges (high to low)
#   a column for each time, day, week, month , red over green
# uses 2nd aggregation, so current month, current week.
#   not back 30 days, not back 1 week.
# horz lines for the price levels of each time frame

# https://usethinkscript.com/threads/help-with-relative-range.10482/
#---------------------------------------

def na = double.nan;
def cls2 = if isnan(close) then cls2[1] else close;

def istoday = if GetLastDay() == GetDay() then 1 else 0;
def isweek = if GetLastweek() == Getweek() then 1 else 0;
def ismonth = if GetLastmonth() == Getmonth() then 1 else 0;

# colored column placements, bars after last bar
input day_offset = 3;
input week_offset = 5;
input month_offset = 7;
def day_x = (!isnan(close[day_offset]) and isnan(close[day_offset-1]));
def wk_x = (!isnan(close[week_offset]) and isnan(close[week_offset-1]));
def mo_x = (!isnan(close[month_offset]) and isnan(close[month_offset-1]));
# these have valid numbers

# --------------------------------------
# day
def hi_day = high(period = AggregationPeriod.day);
def lo_day = low(period = AggregationPeriod.day);
def rr_day = Round((close – lo_day) / (hi_day – lo_day) * 100,1);

def dhi = if day_x then hi_day[day_offset] else na;
def dlo = if day_x then lo_day[day_offset] else na;
#def dopn = dhi;
def dcls = close[day_offset];
# column top half / bottom half
AddChart(high = dhi, low = dcls, open = dhi, close = dcls, type = ChartType.CANDLE, growcolor = color.red);
AddChart(high = dcls, low = dlo, open = dcls, close = dlo, type = ChartType.CANDLE, growcolor = color.green);

plot zdtop = if istoday then hi_day else na;
plot zdbot = if istoday then lo_day else na;
zdtop.SetStyle(Curve.medium_DASH);
zdbot.SetStyle(Curve.medium_DASH);
zdtop.SetDefaultColor(Color.lime);
zdtop.hidebubble();
zdbot.SetDefaultColor(Color.lime);
zdbot.hidebubble();

# --------------------------------------
# week
def hi_wk = high(period = AggregationPeriod.week);
def lo_wk = low(period = AggregationPeriod.week);
def rr_wk = Round((close – lo_wk) / (hi_wk – lo_wk) * 100,1);

def whi = if wk_x then hi_wk[week_offset] else na;
def wlo = if wk_x then lo_wk[week_offset] else na;
#def dopn = dhi;
def wcls = close[week_offset];
# column top half / bottom half
AddChart(high = whi, low = wcls, open = whi, close = wcls, type = ChartType.CANDLE, growcolor = color.red);
AddChart(high = wcls, low = wlo, open = wcls, close = wlo, type = ChartType.CANDLE, growcolor = color.green);

plot zwtop = if isweek then hi_wk else na;
plot zwbot = if isweek then lo_wk else na;
zwtop.SetStyle(Curve.long_DASH);
zwbot.SetStyle(Curve.long_DASH);
zwtop.SetDefaultColor(Color.light_gray);
zwtop.hidebubble();
zwbot.SetDefaultColor(Color.light_gray);
zwbot.hidebubble();

# --------------------------------------
# month rel rng
def hi_mo = high(period = AggregationPeriod.month);
def lo_mo = low(period = AggregationPeriod.month);
def rr_mo = Round((close – lo_mo) / (hi_mo – lo_mo) * 100,1);

def mhi = if mo_x then hi_mo[month_offset] else na;
def mlo = if mo_x then lo_mo[month_offset] else na;
#def dopn = dhi;
def mcls = close[month_offset];
# column top half / bottom half
AddChart(high = mhi, low = mcls, open = mhi, close = mcls, type = ChartType.CANDLE, growcolor = color.red);
AddChart(high = mcls, low = mlo, open = mcls, close = mlo, type = ChartType.CANDLE, growcolor = color.green);

plot zmtop = if ismonth then hi_mo else na;
plot zmbot = if ismonth then lo_mo else na;
zmtop.SetDefaultColor(Color.magenta);
zmtop.hidebubble();
zmbot.SetDefaultColor(Color.magenta);
zmbot.hidebubble();

# --------------------------------------

def day_err = isnan(hi_day);
def week_err = isnan(hi_wk);
def month_err = isnan(hi_mo);

addlabel(day_err , "    ", color.black);
addlabel(day_err, "DAY - NOT ENOUGH DATA ON CHART FOR CALCULATIONS", color.cyan);
addlabel(week_err, "    ", color.black);
addlabel(week_err, "WEEK - NOT ENOUGH DATA ON CHART FOR CALCULATIONS", color.cyan);
addlabel(month_err, "    ", color.black);
addlabel(month_err, "MONTH - NOT ENOUGH DATA ON CHART FOR CALCULATIONS", color.cyan);

# --------------------------------------

input show_percent_labels = yes;

# --------------------------------------
input test_inputs = 0;

input test_day_labels = no;
addlabel(test_day_labels, "    ", color.black);
addlabel(test_day_labels, "Day hi " + hi_day, color.yellow);
addlabel(test_day_labels, "Day lo " + lo_day, color.yellow);
addlabel(show_percent_labels or test_day_labels, "Day RR " + rr_day + " %", color.yellow);

input test_week_labels = no;
addlabel(test_week_labels, "    ", color.black);
addlabel(test_week_labels, "Wk hi " + hi_wk, color.yellow);
addlabel(test_week_labels, "Wk lo " + lo_wk, color.yellow);
addlabel(show_percent_labels or test_week_labels, "Wk RR " + rr_wk + " %", color.yellow);

input test_month_labels = no;
addlabel(test_month_labels, "    ", color.black);
addlabel(test_month_labels, "Mo hi " + hi_mo, color.yellow);
addlabel(test_month_labels, "Mo lo " + lo_mo, color.yellow);
addlabel(show_percent_labels or test_month_labels, "Mo RR " + rr_mo + " %", color.yellow);

# --------------------------------------
input test1_dots = no;
plot z1 = if test1_dots and day_x then close[day_offset] else na;
z1.SetPaintingStrategy(PaintingStrategy.POINTS);
z1.SetDefaultColor(Color.cyan);
z1.setlineweight(2);
z1.hidebubble();

input test3 = no;
plot zzz1 = if test3 and istoday then hi_day else na;
zzz1.SetPaintingStrategy(PaintingStrategy.POINTS);
zzz1.SetDefaultColor(Color.cyan);

addchartbubble(0, cls2,
 day_x  + " D\n" +
 wk_x + " wk\n" +
 mo_x + " mo"
,( if day_x or wk_x or mo_x then color.yellow else color.gray), no);
#


GLD 30day 15min
mumUHcn.jpg

hal_mtfcol hal_mtfhilo hal_mtf
 
Last edited:
Solution

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