Repaints 4 MTF price ranges, simulated candles, after last bar For ThinkOrSwim

Repaints

halcyonguy

Moderator - Expert
VIP
Lifetime
show 4 colored columns, after the last bar, that represent the price ranges of 4 time periods, day, week, month, year.

draw horizontal lines for the highest and lowest levels, for the time periods, day, week, month, year.

there are labels to show at what % , the close is , relative to each period.
(95% means the close is very close to the high)

added Year to my existing study

previous version,
https://usethinkscript.com/threads/help-with-relative-range.10482/#post-92839

Ruby:
# mtf_exp_columns_day_week_month_year

# halcyonguy
# 2022-11
# prev ,  relative_range_mtf_00d_dayweekmonth

# 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/

#Help with relative range?
# Thread starterHeadhunter20  Start date59 minutes ago

#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.
#**************************************************

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

def currentday = if GetLastDay() == GetDay() then 1 else 0;
def currentweek = if GetLastweek() == Getweek() then 1 else 0;
def currentmonth = if GetLastmonth() == Getmonth() then 1 else 0;
def currentyear = if GetLastyear() == Getyear() then 1 else 0;

# colored column placements, bars after last bar
input day_offset = 3;
input week_offset = 5;
input month_offset = 7;
input year_offset = 9;
def dy_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]));
def yr_x = (!isnan(close[year_offset]) and isnan(close[year_offset-1]));


def bub = 1.01;
# rr - relative range
# --------------------------------------
# day
input show_day_lines = yes;
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 dy_x then hi_day[day_offset] else na;
def dlo = if dy_x then lo_day[day_offset] else na;

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 currentday then hi_day else na;
plot zdbot = if currentday 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();

addchartbubble(show_day_lines and dy_x, dhi*bub, "D", color.yellow, yes);

# --------------------------------------
# week 
input show_week_lines = yes;
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 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 currentweek then hi_wk else na;
plot zwbot = if currentweek 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();

addchartbubble(show_week_lines and wk_x, whi*bub, "W", color.yellow, yes);

# --------------------------------------
# month
input show_month_lines = yes;
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 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 currentyear and currentmonth then hi_mo else na;
plot zmbot = if currentyear and currentmonth then lo_mo else na;
zmtop.SetDefaultColor(Color.magenta);
zmtop.hidebubble();
zmbot.SetDefaultColor(Color.magenta);
zmbot.hidebubble();

addchartbubble(show_month_lines and mo_x, mhi*bub, "M", color.yellow, yes);

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

# year
input show_year_lines = yes;
def hi_yr = high(period = AggregationPeriod.year);
def lo_yr = low(period = AggregationPeriod.year);
def rr_yr = Round((close – lo_yr) / (hi_yr – lo_yr) * 100,1);

def yhi = if yr_x then hi_yr[year_offset] else na;
def ylo = if yr_x then lo_yr[year_offset] else na;

def ycls = close[year_offset];
# column top half / bottom half
AddChart(high = yhi, low = ycls, open = yhi, close = ycls, type = ChartType.CANDLE, growcolor = color.red);
AddChart(high = ycls, low = ylo, open = ycls, close = ylo, type = ChartType.CANDLE, growcolor = color.green);

plot zytop = if show_year_lines and currentyear then hi_yr else na;
plot zybot = if show_year_lines and currentyear then lo_yr else na;
zytop.SetDefaultColor(Color.magenta);
zytop.hidebubble();
zybot.SetDefaultColor(Color.magenta);
zybot.hidebubble();

addchartbubble(show_year_lines and yr_x, yhi*bub, "Y", color.yellow, yes);

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

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

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);
addlabel(year_err, "    ", color.black);
addlabel(year_err, "YEAR - NOT ENOUGH DATA ON CHART FOR CALCULATIONS", color.cyan);

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

input show_percent_labels = yes;

# --------------------------------------
input test_inputs = 0;
addlabel(show_percent_labels, " ", color.black);

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 test_year_labels = no;
addlabel(test_year_labels, "  ", color.black);
addlabel(test_year_labels, "Yr hi " + hi_yr, color.yellow);
addlabel(test_year_labels, "Yr lo " + lo_yr, color.yellow);
addlabel(show_percent_labels or test_year_labels, "Yr RR " + rr_yr + " %", color.yellow);
addlabel(show_percent_labels, " ", color.black);

# --------------------------------------
input test1_dots = no;
plot z1 = if test1_dots and dy_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 currentday then hi_day else na;
zzz1.SetPaintingStrategy(PaintingStrategy.POINTS);
zzz1.SetDefaultColor(Color.cyan);

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

TWTR day
ZxVMA8z.jpg

hal_mtf
 
Last edited:

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