HLC Price Line

ToSdrew777

New member
Hello,

Will someone please help me. I am still new to this and keep messing up. Everyday I would just like a line on my charts for the following 9 levels:

1) The PREVIOUS days high/low/close
2) The PREVIOUS weeks high/low/close
3) The PREVIOUS months high/low/close

I am tired of constantly manually drawing these out. If it is simple for you to script I will be very grateful.

Kind Regards,
Andrew
 
Hello,

Will someone please help me. I am still new to this and keep messing up. Everyday I would just like a line on my charts for the following 9 levels:

1) The PREVIOUS days high/low/close
2) The PREVIOUS weeks high/low/close
3) The PREVIOUS months high/low/close

I am tired of constantly manually drawing these out. If it is simple for you to script I will be very grateful.

Kind Regards,
Andrew
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

here is a study that draws 3 lines ( H L C ), for each time period. ( DY WK MO )

the day lines are drawn on the current day, at the previous day levels.
the week lines are drawn on the current week, at the previous week levels.
the month lines are drawn on the current month, at the previous month levels.

can choose the period offset. default is 1, which reads data from 1 period ago (previous). if 0 is used then price levels from the current time periods will be used.

can pick a different color (0-9) for the 3 time period lines and a legend label.

i used inputs for setting the period times, because i don't like using constants and it made it easier to copy the code from section to section. so it is possible to change the period times, but i didn't test others.

there is a built in study called dailyopen , that was a starting point.
at the end are 2 lists of color names.

Ruby:
# prevlevels_hlc01

# 1) The PREVIOUS days high/low/close
# 2) The PREVIOUS weeks high/low/close
# 3) The PREVIOUS months high/low/close

def na = double.nan;
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;

input data_from_x_periods_ago = 1;
def dfx = data_from_x_periods_ago ;

input daycolor = 2;
input weekcolor = 4;
input monthcolor = 9;

addlabel(1, " [ data from " + dfx + " periods ago ] ", color.yellow);

# --------------------------------------------
# day
input aggday = AggregationPeriod.DAY;

def prevDayH = high(period = aggday)[dfx];
plot pDayH = if istoday then prevDayH else na;
pDayH.SetDefaultColor(getcolor(daycolor));
pDayH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def prevDayL = low(period = aggday)[dfx];
plot pDayL = if istoday then prevDayL else na;
pDayL.SetDefaultColor(getcolor(daycolor));
pDayL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def prevDayC = close(period = aggdAY)[dfx];
plot pDayC = if istoday then prevDayC else na;
pDayC.SetDefaultColor(getcolor(daycolor));
pDayC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

addlabel( 1, "Day", getcolor(daycolor));

# --------------------------------------------
# week
input aggweek = AggregationPeriod.week;

def prevweekH = high(period = aggweek)[dfx];
plot pweekH = if isweek then prevweekH else na;
pweekH.SetDefaultColor(getcolor(weekcolor));
pweekH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def prevweekL = low(period = aggweek)[dfx];
plot pweekL = if isweek then prevweekL else na;
pweekL.SetDefaultColor(getcolor(weekcolor));
pweekL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def prevweekC = close(period = aggweek)[dfx];
plot pweekC = if isweek then prevweekC else na;
pweekC.SetDefaultColor(getcolor(weekcolor));
pweekC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

addlabel( 1, "Week", getcolor(weekcolor));

# --------------------------------------------
# month
input aggmonth = AggregationPeriod.month;

def prevmonthH = high(period = aggmonth)[dfx];
plot pmonthH = if ismonth then prevmonthH else na;
pmonthH.SetDefaultColor(getcolor(monthcolor));
pmonthH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def prevmonthL = low(period = aggmonth)[dfx];
plot pmonthL = if ismonth then prevmonthL else na;
pmonthL.SetDefaultColor(getcolor(monthcolor));
pmonthL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def prevmonthC = close(period = aggmonth)[dfx];
plot pmonthC = if ismonth then prevmonthC else na;
pmonthC.SetDefaultColor(getcolor(monthcolor));
pmonthC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

addlabel( 1, "Month", getcolor(monthcolor));
# --------------------------------------------

# lists of colors

#    GetColor(1)
#  0=magenta, 1=cyan, 2=pink, 3=gray, 4=org
#  5=red, 6=green, 7=drk gry, 8=yellow, 9=white
#  https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/GetColor

#    color.black
#  CYAN, BLACK, BLUE, DARK_GRAY, DARK_GREEN, DARK_ORANGE, DARK_RED
#  GRAY, GREEN, LIGHT_GRAY, LIGHT_GREEN, LIGHT_ORANGE, LIGHT_RED, LIME
#  MAGENTA, ORANGE, PINK, PLUM, RED, VIOLET, WHITE, YELLOW
#  https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/Color

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/GetColor
https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/Color

523BYIc.jpg
 
here is a study that draws 3 lines ( H L C ), for each time period. ( DY WK MO )

the day lines are drawn on the current day, at the previous day levels.
the week lines are drawn on the current week, at the previous week levels.
the month lines are drawn on the current month, at the previous month levels.

can choose the period offset. default is 1, which reads data from 1 period ago (previous). if 0 is used then price levels from the current time periods will be used.

can pick a different color (0-9) for the 3 time period lines and a legend label.

i used inputs for setting the period times, because i don't like using constants and it made it easier to copy the code from section to section. so it is possible to change the period times, but i didn't test others.

there is a built in study called dailyopen , that was a starting point.
at the end are 2 lists of color names.

Ruby:
# prevlevels_hlc01

# 1) The PREVIOUS days high/low/close
# 2) The PREVIOUS weeks high/low/close
# 3) The PREVIOUS months high/low/close

def na = double.nan;
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;

input data_from_x_periods_ago = 1;
def dfx = data_from_x_periods_ago ;

input daycolor = 2;
input weekcolor = 4;
input monthcolor = 9;

addlabel(1, " [ data from " + dfx + " periods ago ] ", color.yellow);

# --------------------------------------------
# day
input aggday = AggregationPeriod.DAY;

def prevDayH = high(period = aggday)[dfx];
plot pDayH = if istoday then prevDayH else na;
pDayH.SetDefaultColor(getcolor(daycolor));
pDayH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def prevDayL = low(period = aggday)[dfx];
plot pDayL = if istoday then prevDayL else na;
pDayL.SetDefaultColor(getcolor(daycolor));
pDayL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def prevDayC = close(period = aggdAY)[dfx];
plot pDayC = if istoday then prevDayC else na;
pDayC.SetDefaultColor(getcolor(daycolor));
pDayC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

addlabel( 1, "Day", getcolor(daycolor));

# --------------------------------------------
# week
input aggweek = AggregationPeriod.week;

def prevweekH = high(period = aggweek)[dfx];
plot pweekH = if isweek then prevweekH else na;
pweekH.SetDefaultColor(getcolor(weekcolor));
pweekH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def prevweekL = low(period = aggweek)[dfx];
plot pweekL = if isweek then prevweekL else na;
pweekL.SetDefaultColor(getcolor(weekcolor));
pweekL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def prevweekC = close(period = aggweek)[dfx];
plot pweekC = if isweek then prevweekC else na;
pweekC.SetDefaultColor(getcolor(weekcolor));
pweekC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

addlabel( 1, "Week", getcolor(weekcolor));

# --------------------------------------------
# month
input aggmonth = AggregationPeriod.month;

def prevmonthH = high(period = aggmonth)[dfx];
plot pmonthH = if ismonth then prevmonthH else na;
pmonthH.SetDefaultColor(getcolor(monthcolor));
pmonthH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def prevmonthL = low(period = aggmonth)[dfx];
plot pmonthL = if ismonth then prevmonthL else na;
pmonthL.SetDefaultColor(getcolor(monthcolor));
pmonthL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def prevmonthC = close(period = aggmonth)[dfx];
plot pmonthC = if ismonth then prevmonthC else na;
pmonthC.SetDefaultColor(getcolor(monthcolor));
pmonthC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

addlabel( 1, "Month", getcolor(monthcolor));
# --------------------------------------------

# lists of colors

#    GetColor(1)
#  0=magenta, 1=cyan, 2=pink, 3=gray, 4=org
#  5=red, 6=green, 7=drk gry, 8=yellow, 9=white
#  https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/GetColor

#    color.black
#  CYAN, BLACK, BLUE, DARK_GRAY, DARK_GREEN, DARK_ORANGE, DARK_RED
#  GRAY, GREEN, LIGHT_GRAY, LIGHT_GREEN, LIGHT_ORANGE, LIGHT_RED, LIME
#  MAGENTA, ORANGE, PINK, PLUM, RED, VIOLET, WHITE, YELLOW
#  https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/Color

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/GetColor
https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/Color

523BYIc.jpg
thank you - excellent!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
277 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