# 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