Create a horizontal drawing, then remove it once price hits it

redart1021

New member
Hi, I use Friday's high/low as the opening range for the next week. Based off the Friday's high/low I create extension lines (ie. a percent times the range above and below). I'm interested in automating it so that once price hits one of these levels they vanish from the charts. This will keep extensions on chart from previous weeks that haven't been hit yet. Does anyone know of a way to do this?
 
Solution
Hi, I use Friday's high/low as the opening range for the next week. Based off the Friday's high/low I create extension lines (ie. a percent times the range above and below). I'm interested in automating it so that once price hits one of these levels they vanish from the charts. This will keep extensions on chart from previous weeks that haven't been hit yet. Does anyone know of a way to do this?

it can be done. there can't be unlimited lines plotted, but several can be drawn.

i came across this post a couple weeks ago, and thought it might be possible.
after many hours of trying, i have this.
the original post didn't mention how many weeks back to look at. i had to copy some sections of code for each day, so i thought 6 days...
While it's true that this is not possible (as stated by @rad14733), there is a workaround.

Step 1: Hover to the price level of your choice > right-click > "Create alert..."

Step 2: In the "Create Alert on Price" screen, configure if you want to get notified for price crossing above or below the particular price.

LKHJclT.png


Step 3: Hit Create.

Step 4: Now, you should see the yellow horizontal alert line on your chart. Once the stock price hits the condition you set in Step 2, the line will disappear.

9yPZjBn.png


I hope that helps.
 
Thank you @BenTen for the detailed reply. I use alerts extensively, however I need it done as a script because I have a large watchlist with automated signals and I need to be able to flip through them quickly
 
Hi, I use Friday's high/low as the opening range for the next week. Based off the Friday's high/low I create extension lines (ie. a percent times the range above and below). I'm interested in automating it so that once price hits one of these levels they vanish from the charts. This will keep extensions on chart from previous weeks that haven't been hit yet. Does anyone know of a way to do this?

it can be done. there can't be unlimited lines plotted, but several can be drawn.

i came across this post a couple weeks ago, and thought it might be possible.
after many hours of trying, i have this.
the original post didn't mention how many weeks back to look at. i had to copy some sections of code for each day, so i thought 6 days would be enough.

# show lines from previous day levels, except if price crosses a level.

# pick a desired day of week, monday, tues,....
# pick how many weeks to look at, 1 to 6
# pick how to show lines if price crosses them: invisible, dashes, solid

# find the high and low for each desired day
# draw lines from high and low levels, from each desired day of the week
# check if price crossess a high or low level, from one of the previous selected days of the week
# change the line if price crosses it, solid, dashed, or invisible
# show bubbles on right side of chart, that identify the lines

on the first bar of the desired days, it runs a loop to check if price crossed a line.

at the end of the code are code samples, some that worked, some that didn't.
some for testing, displaying variables.
it is possible to use an if-then to choose a PaintingStrategy, but when zoomed out, a dash line looks solid, so i didn't use it.
i couldn't get SetStyle(Curve. to work with an if-then, so i ended up using a separate code line for each line.


Ruby:
# fridaylevels_disappear_01

# halcyonguy
# 21-09-10
# show lines from previous day levels, except if price crosses a level.

# pick a desired day of week, monday, tues,....
# pick how many weeks to look at, 1 to 6
# pick how to show lines if price crosses them: invisible, dashes, solid

# find the high and low for each desired day
# check if price crossess a high or low level, from one of the previous selected days of the week
# draw lines from high and low levels, from each desired day of the week
#  change the line if price crosses it, solid, dashed, or invisible
# show bubbles on right side of chart, that identify the lines


# ---------------------------------------------
# original post code request
# draw horizontal lines. remove them if price crosses them
# https://usethinkscript.com/threads/create-a-horizontal-drawing-then-remove-it-once-price-hits-it.5257/
# jan 2021  redart1021
# ----------------------------------------

def bn = BarNumber();
def na = Double.NaN;
def h = high;
def l = low;

def lastbar = HighestAll(If(IsNaN(close), 0, bn));
#addlabel(1, "lastbar " + lastbar, color.cyan);

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

input crossed_line = {"invisible", default "dashes", "solid"};
#hint crossed_line: "choose the type of line to draw when a line is crossed.   invisible, dashes, solid"
def crslin;
if crossed_line == crossed_line."invisible" then {
    crslin = 1;
} else if crossed_line == crossed_line."dashes" then {
    crslin = 2;
} else if crossed_line == crossed_line."solid" then {
    crslin = 3;
} else {
    crslin = 0;
};

# addlabel(1, "crossed line: " +  crossed_line , color.yellow);
# addlabel(1, "crslin " + crslin , color.cyan);
#  crslin = 1  invisible
#  crslin = 2  dashes
#  crslin = 3  solid

# ------------------------------------------
# there are formulas for up to 6 days/sets of lines
def maxdays = 6;
input quantity_of_days = 6; #hint quantity_of_days: "Pick quantity of days to show high/low lines, 1 to 6"
def dayqty = if quantity_of_days < 1 then 1 else if quantity_of_days > maxdays then maxdays else quantity_of_days;
addlabel( (quantity_of_days < 1 or quantity_of_days > maxdays) , " <<<< quantity of days out of range >>>", color.cyan);
# --------------------------------------
input day_of_week = {Monday, Tuesday, Wednesday, Thursday, default Friday, Saturday, Sunday};
#hint day_of_week: "pick a day that the high/low levels come from"

def dow = GetDayOfWeek(GetYYYYMMDD()) ;
# find valid days
def dayen = (dow == (day_of_week + 1)) and !IsNaN(close);
# find first bar of desired day
def firstbar = (dayen and (dayen[1] <> dayen));

# count desired days on chart
def daycnt =
 if (bn == 1 and (dayen and (dayen[1] <> dayen))) then 1
 else if bn == 1 then 0
 else if (dayen and (dayen[1] <> dayen)) then daycnt[1] + 1
 else daycnt[1];

# get qty of desired days on the chart
def daycntmax = HighestAll(daycnt);

# rev the day count, the last day (on the right) is #1
def daycntrev = (daycntmax - daycnt) + 1;
def dayrev_en = (daycntrev <= dayqty);

# ====================================

# get bn of first bar in each desired day
def d1rev_startbn = if bn == 1 then 0 else if (dayrev_en and firstbar and daycntrev == 1) then bn else d1rev_startbn[1];
def d2rev_startbn = if bn == 1 then 0 else if (dayrev_en and firstbar and daycntrev == 2) then bn else d2rev_startbn[1];
def d3rev_startbn = if bn == 1 then 0 else if (dayrev_en and firstbar and daycntrev == 3) then bn else d3rev_startbn[1];
def d4rev_startbn = if bn == 1 then 0 else if (dayrev_en and firstbar and daycntrev == 4) then bn else d4rev_startbn[1];
def d5rev_startbn = if bn == 1 then 0 else if (dayrev_en and firstbar and daycntrev == 5) then bn else d5rev_startbn[1];
def d6rev_startbn = if bn == 1 then 0 else if (dayrev_en and firstbar and daycntrev == 6) then bn else d6rev_startbn[1];

# ==================================================================

# draw vertical line at start of desired days
input show_day_vertical_lines = yes;
AddVerticalLine(show_day_vertical_lines and dayen and firstbar, "DAY " + daycntrev, Color.YELLOW);

# ========================================

# get highest high from each desired day, 1 to 6
def little = 0;
def d1hi = if (daycntrev == 1 and dayrev_en and firstbar) then h
 else if (daycntrev == 1 and dayen and h > d1hi[1]) then h
 else if (daycntrev == 1 and dayen) then d1hi[1]
 else little;
def d1highest = HighestAll(d1hi);

def d2hi = if (daycntrev == 2 and dayrev_en and firstbar) then h
 else if (daycntrev == 2 and dayen and h > d2hi[1]) then h
 else if (daycntrev == 2 and dayen) then d2hi[1]
 else little;
def d2highest = HighestAll(d2hi);

def d3hi = if (daycntrev == 3 and dayrev_en and firstbar) then h
 else if (daycntrev == 3 and dayen and h > d3hi[1]) then h
 else if (daycntrev == 3 and dayen) then d3hi[1]
 else little;
def d3highest = HighestAll(d3hi);

def d4hi = if (daycntrev == 4 and dayrev_en and firstbar) then h
 else if (daycntrev == 4 and dayen and h > d4hi[1]) then h
 else if (daycntrev == 4 and dayen) then d4hi[1]
 else little;
def d4highest = HighestAll(d4hi);

def d5hi = if (daycntrev == 5 and dayrev_en and firstbar) then h
 else if (daycntrev == 5 and dayen and h > d5hi[1]) then h
 else if (daycntrev == 5 and dayen) then d5hi[1]
 else little;
def d5highest = HighestAll(d5hi);

def d6hi = if (daycntrev == 6 and dayrev_en and firstbar) then h
 else if (daycntrev == 6 and dayen and h > d6hi[1]) then h
 else if (daycntrev == 6 and dayen) then d6hi[1]
 else little;
def d6highest = HighestAll(d6hi);

# ========================================

def big = 99999;
# get lowest low from each desired day, 1 to 6
def d1lo = if (daycntrev == 1 and dayrev_en and firstbar) then l
 else if (daycntrev == 1 and dayen and l < d1lo[1]) then l
 else if (daycntrev == 1 and dayen) then d1lo[1]
 else big;
def d1lowest = LowestAll(d1lo);

def d2lo = if (daycntrev == 2 and dayrev_en and firstbar) then l
 else if (daycntrev == 2 and dayen and l < d2lo[1]) then l
 else if (daycntrev == 2 and dayen) then d2lo[1]
 else big;
def d2lowest = LowestAll(d2lo);

def d3lo = if (daycntrev == 3 and dayrev_en and firstbar) then l
 else if (daycntrev == 3 and dayen and l < d3lo[1]) then l
 else if (daycntrev == 3 and dayen) then d3lo[1]
 else big;
def d3lowest = LowestAll(d3lo);

def d4lo = if (daycntrev == 4 and dayrev_en and firstbar) then l
 else if (daycntrev == 4 and dayen and l < d4lo[1]) then l
 else if (daycntrev == 4 and dayen) then d4lo[1]
 else big;
def d4lowest = LowestAll(d4lo);

def d5lo = if (daycntrev == 5 and dayrev_en and firstbar) then l
 else if (daycntrev == 5 and dayen and l < d5lo[1]) then l
 else if (daycntrev == 5 and dayen) then d5lo[1]
 else big;
def d5lowest = LowestAll(d5lo);

def d6lo = if (daycntrev == 6 and dayrev_en and firstbar) then l
 else if (daycntrev == 6 and dayen and l < d6lo[1]) then l
 else if (daycntrev == 6 and dayen) then d6lo[1]
 else big;
def d6lowest = LowestAll(d6lo);

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

# find the 1st bar of 6 desired days, starting from the right (rev cnt)
def rev1start = (dayen and firstbar and daycntrev == 1);
def rev2start = (dayen and firstbar and daycntrev == 2);
def rev3start = (dayen and firstbar and daycntrev == 3);
def rev4start = (dayen and firstbar and daycntrev == 4);
def rev5start = (dayen and firstbar and daycntrev == 5);
def rev6start = (dayen and firstbar and daycntrev == 6);

# ---------------------------------
# hi lines,  count how many times price crosses up over a level
#  if line is a high, price starts below it. so don't need to check if it crosses down below the line
#   if the 1st bar on a desired day, run fold, to check if price crosses up over a hi line
#  opposite for lo line.
#    i don't know why i didn't use crosses, i guess i prefer < >...
#    44 has no meaning,  just random variable names..
# -------------------------
# script to count how many times price crosses a high line
script hixcnt {
  input lastbar = 0;
  input bn = 0;
  input rstart = 0;
  input hix = 0;
# if the 1st bar on a desired day, check if prev low crosses over #2 hi, to current high
def dhix;
if rstart then {
  dhix = fold i44 = 1 to (lastbar - bn + 1)
  with p44
  do p44 + (if (GetValue(low, -i44 + 1) < GetValue(hix, -i44)) and (GetValue(high, -i44) > GetValue(hix, -i44)) then 1 else 0);
} else {
    dhix = if bn == 1 then 0 else dhix[1];
};
# qty of line crossings
plot cnthi = dhix;
};

# -----------------------------
# script to count how many times price crosses a low line
script loxcnt {
  input lastbar = 0;
  input bn = 0;
  input rstart = 0;
  input lox = 0;
# if the 1st bar on a desired day, check if prev low crosses over #2 hi, to current high
def dlox;
if rstart then {
  dlox = fold k44 = 1 to (lastbar - bn + 1)
  with q44
  do q44 + (if (GetValue(high, -k44 + 1) > GetValue(lox, -k44)) and (GetValue(low, -k44) < GetValue(lox, -k44)) then 1 else 0);
} else {
    dlox = if bn == 1 then 0 else dlox[1];
};
# qty of line crossings
plot cntlo = dlox;
};

# ------------------------------------
# ref the scripts, count qty of crossings, of lines, for each day
def d1hixsub = hixcnt(lastbar, bn, rev1start, d1highest);
def d2hixsub = hixcnt(lastbar, bn, rev2start, d2highest);
def d3hixsub = hixcnt(lastbar, bn, rev3start, d3highest);
def d4hixsub = hixcnt(lastbar, bn, rev4start, d4highest);
def d5hixsub = hixcnt(lastbar, bn, rev5start, d5highest);
def d6hixsub = hixcnt(lastbar, bn, rev6start, d6highest);
# --------------
def d1loxsub = loxcnt(lastbar, bn, rev1start, d1lowest);
def d2loxsub = loxcnt(lastbar, bn, rev2start, d2lowest);
def d3loxsub = loxcnt(lastbar, bn, rev3start, d3lowest);
def d4loxsub = loxcnt(lastbar, bn, rev4start, d4lowest);
def d5loxsub = loxcnt(lastbar, bn, rev5start, d5lowest);
def d6loxsub = loxcnt(lastbar, bn, rev6start, d6lowest);

# ---------------------------------
# def dayrev_en = (daycntrev <= dayqty);
# plot lines
# day1 hi
plot z1hi = if (daycntrev <= 1 and dayqty >= 1 and dayrev_en and (d1hixsub == 0 or crslin == 3)) then d1highest else na;
plot z1hix = if (daycntrev <= 1 and dayqty >= 1 and dayrev_en and d1hixsub > 0 and crslin == 2) then d1highest else na;
z1hi.SetDefaultColor(Color.LIGHT_GREEN);
z1hi.SetStyle(Curve.FIRM);
z1hi.HideBubble();
z1hix.SetDefaultColor(Color.LIGHT_GREEN);
z1hix.SetStyle(Curve.SHORT_DASH);
z1hix.HideBubble();

# day2 hi
plot z2hi = if (daycntrev <= 2 and dayqty >= 2 and dayrev_en and (d2hixsub == 0 or crslin == 3)) then d2highest else na;
plot z2hix = if (daycntrev <= 2 and dayqty >= 2 and dayrev_en and d2hixsub > 0 and crslin == 2) then d2highest else na;
z2hi.SetDefaultColor(Color.LIGHT_GREEN);
z2hi.SetStyle(Curve.FIRM);
z2hi.HideBubble();
z2hix.SetDefaultColor(Color.LIGHT_GREEN);
z2hix.SetStyle(Curve.SHORT_DASH);
z2hix.HideBubble();

# day3 hi
plot z3hi = if (daycntrev <= 3 and dayqty >= 3 and dayrev_en and (d3hixsub == 0 or crslin == 3)) then d3highest else na;
plot z3hix = if (daycntrev <= 3 and dayqty >= 3 and dayrev_en and d3hixsub > 0 and crslin == 2) then d3highest else na;
z3hi.SetDefaultColor(Color.LIGHT_GREEN);
z3hi.SetStyle(Curve.FIRM);
z3hi.HideBubble();
z3hix.SetDefaultColor(Color.LIGHT_GREEN);
z3hix.SetStyle(Curve.SHORT_DASH);
z3hix.HideBubble();

# day4 hi
plot z4hi = if (daycntrev <= 4 and dayqty >= 4 and dayrev_en and (d4hixsub == 0 or crslin == 3)) then d4highest else na;
plot z4hix = if (daycntrev <= 4 and dayqty >= 4 and dayrev_en and d4hixsub > 0 and crslin == 2) then d4highest else na;
z4hi.SetDefaultColor(Color.LIGHT_GREEN);
z4hi.SetStyle(Curve.FIRM);
z4hi.HideBubble();
z4hix.SetDefaultColor(Color.LIGHT_GREEN);
z4hix.SetStyle(Curve.SHORT_DASH);
z4hix.HideBubble();

# day5 hi
plot z5hi = if (daycntrev <= 5 and dayqty >= 5 and dayrev_en and (d5hixsub == 0 or crslin == 3)) then d5highest else na;
plot z5hix = if (daycntrev <= 5 and dayqty >= 5 and dayrev_en and d5hixsub > 0 and crslin == 2) then d5highest else na;
z5hi.SetDefaultColor(Color.LIGHT_GREEN);
z5hi.SetStyle(Curve.FIRM);
z5hi.HideBubble();
z5hix.SetDefaultColor(Color.LIGHT_GREEN);
z5hix.SetStyle(Curve.SHORT_DASH);
z5hix.HideBubble();

# day6 hi
plot z6hi = if (daycntrev <= 6 and dayqty >= 6 and dayrev_en and (d6hixsub == 0 or crslin == 3)) then d6highest else na;
plot z6hix = if (daycntrev <= 6 and dayqty >= 6 and dayrev_en and d6hixsub > 0 and crslin == 2) then d6highest else na;
z6hi.SetDefaultColor(Color.LIGHT_GREEN);
z6hi.SetStyle(Curve.FIRM);
z6hi.HideBubble();
z6hix.SetDefaultColor(Color.LIGHT_GREEN);
z6hix.SetStyle(Curve.SHORT_DASH);
z6hix.HideBubble();

# -------------------
# low lines
# day1 lo
plot z1lo = if (daycntrev <= 1 and dayqty >= 1 and dayrev_en and (d1loxsub == 0 or crslin == 3)) then d1lowest else na;
plot z1lox = if (daycntrev <= 1 and dayqty >= 1 and dayrev_en and d1loxsub > 0 and crslin == 2) then d1lowest else na;
z1lo.SetDefaultColor(Color.LIGHT_RED);
z1lo.SetStyle(Curve.FIRM);
z1lo.HideBubble();
z1lox.SetDefaultColor(Color.LIGHT_RED);
z1lox.SetStyle(Curve.SHORT_DASH);
z1lox.HideBubble();

# day2 lo
plot z2lo = if (daycntrev <= 2 and dayqty >= 2 and dayrev_en and (d2loxsub == 0 or crslin == 3)) then d2lowest else na;
plot z2lox = if (daycntrev <= 2 and dayqty >= 2 and dayrev_en and d2loxsub > 0 and crslin == 2) then d2lowest else na;
z2lo.SetDefaultColor(Color.LIGHT_RED);
z2lo.SetStyle(Curve.FIRM);
z2lo.HideBubble();
z2lox.SetDefaultColor(Color.LIGHT_RED);
z2lox.SetStyle(Curve.SHORT_DASH);
z2lox.HideBubble();

# day3 lo
plot z3lo = if (daycntrev <= 3 and dayqty >= 3 and dayrev_en and (d3loxsub == 0 or crslin == 3)) then d3lowest else na;
plot z3lox = if (daycntrev <= 3 and dayqty >= 3 and dayrev_en and d3loxsub > 0 and crslin == 2) then d3lowest else na;
z3lo.SetDefaultColor(Color.LIGHT_RED);
z3lo.SetStyle(Curve.FIRM);
z3lo.HideBubble();
z3lox.SetDefaultColor(Color.LIGHT_RED);
z3lox.SetStyle(Curve.SHORT_DASH);
z3lox.HideBubble();

# day4 lo
plot z4lo = if (daycntrev <= 4 and dayqty >= 4 and dayrev_en and (d4loxsub == 0 or crslin == 3)) then d4lowest else na;
plot z4lox = if (daycntrev <= 4 and dayqty >= 4 and dayrev_en and d4loxsub > 0 and crslin == 2) then d4lowest else na;
z4lo.SetDefaultColor(Color.LIGHT_RED);
z4lo.SetStyle(Curve.FIRM);
z4lo.HideBubble();
z4lox.SetDefaultColor(Color.LIGHT_RED);
z4lox.SetStyle(Curve.SHORT_DASH);
z4lox.HideBubble();

# day5 lo
plot z5lo = if (daycntrev <= 5 and dayqty >= 5 and dayrev_en and (d5loxsub == 0 or crslin == 3)) then d5lowest else na;
plot z5lox = if (daycntrev <= 5 and dayqty >= 5 and dayrev_en and d5loxsub > 0 and crslin == 2) then d5lowest else na;
z5lo.SetDefaultColor(Color.LIGHT_RED);
z5lo.SetStyle(Curve.FIRM);
z5lo.HideBubble();
z5lox.SetDefaultColor(Color.LIGHT_RED);
z5lox.SetStyle(Curve.SHORT_DASH);
z5lox.HideBubble();

# day6 lo
plot z6lo = if (daycntrev <= 6 and dayqty >= 6 and dayrev_en and (d6loxsub == 0 or crslin == 3)) then d6lowest else na;
plot z6lox = if (daycntrev <= 6 and dayqty >= 6 and dayrev_en and d6loxsub > 0 and crslin == 2) then d6lowest else na;
z6lo.SetDefaultColor(Color.LIGHT_RED);
z6lo.SetStyle(Curve.FIRM);
z6lo.HideBubble();
z6lox.SetDefaultColor(Color.LIGHT_RED);
z6lox.SetStyle(Curve.SHORT_DASH);
z6lox.HideBubble();
# -----------------------------

# ------------------ line on desired days -----------------

input show_lines_over_days = yes; #hint show_lines_over_days: "show 2 horizontal gray dashed lines, on the desired days. default is at the high and low levels."
def slod = show_lines_over_days;

#   lines on desired days, above bars
input day_line_offset_percent = 0.0; #hint day_line_offset_percent: "offset % for day gray lines. at 0%, they are at the high and low. ex. if 0.2 then slighly above the high and below the low.

def per2 = (1 + (day_line_offset_percent / 100));
#
# rev day 1
plot z1periodhi = if (slod and daycntrev == 1 and dayen) then (d1highest * per2) else na;
z1periodhi.SetDefaultColor(Color.LIGHT_GRAY);
z1periodhi.SetStyle(Curve.MEDIUM_DASH);
z1periodhi.SetLineWeight(1);
z1periodhi.HideBubble();

# rev day 2
plot z2periodhi = if (slod and daycntrev == 2 and dayen) then (d2highest * per2) else na;
z2periodhi.SetDefaultColor(Color.LIGHT_GRAY);
z2periodhi.SetStyle(Curve.MEDIUM_DASH);
z2periodhi.SetLineWeight(1);
z2periodhi.HideBubble();

# rev day 3
plot z3periodhi = if (slod and daycntrev == 3 and dayen) then (d3highest * per2) else na;
z3periodhi.SetDefaultColor(Color.LIGHT_GRAY);
z3periodhi.SetStyle(Curve.MEDIUM_DASH);
z3periodhi.SetLineWeight(1);
z3periodhi.HideBubble();

# rev day 4
plot z4periodhi = if (slod and daycntrev == 4 and dayen) then (d4highest * per2) else na;
z4periodhi.SetDefaultColor(Color.LIGHT_GRAY);
z4periodhi.SetStyle(Curve.MEDIUM_DASH);
z4periodhi.SetLineWeight(1);
z4periodhi.HideBubble();

# rev day 5
plot z5periodhi = if (slod and daycntrev == 5 and dayen) then (d5highest * per2) else na;
z5periodhi.SetDefaultColor(Color.LIGHT_GRAY);
z5periodhi.SetStyle(Curve.MEDIUM_DASH);
z5periodhi.SetLineWeight(1);
z5periodhi.HideBubble();

# rev day 6
plot z6periodhi = if (slod and daycntrev == 6 and dayen) then (d6highest * per2) else na;
z6periodhi.SetDefaultColor(Color.LIGHT_GRAY);
z6periodhi.SetStyle(Curve.MEDIUM_DASH);
z6periodhi.SetLineWeight(1);
z6periodhi.HideBubble();

# -----------------------
def per3 = (1 - (day_line_offset_percent / 100));
#
# low lines
plot z1periodlo = if (slod and daycntrev == 1 and dayen) then (d1lowest * per3) else na;
z1periodlo.SetDefaultColor(Color.LIGHT_GRAY);
z1periodlo.SetStyle(Curve.MEDIUM_DASH);
z1periodlo.SetLineWeight(1);
z1periodlo.HideBubble();

plot z2periodlo = if (slod and daycntrev == 2 and dayen) then (d2lowest * per3) else na;
z2periodlo.SetDefaultColor(Color.LIGHT_GRAY);
z2periodlo.SetStyle(Curve.MEDIUM_DASH);
z2periodlo.SetLineWeight(1);
z2periodlo.HideBubble();

plot z3periodlo = if (slod and daycntrev == 3 and dayen) then (d3lowest * per3) else na;
z3periodlo.SetDefaultColor(Color.LIGHT_GRAY);
z3periodlo.SetStyle(Curve.MEDIUM_DASH);
z3periodlo.SetLineWeight(1);
z3periodlo.HideBubble();

plot z4periodlo = if (slod and daycntrev == 4 and dayen) then (d4lowest * per3) else na;
z4periodlo.SetDefaultColor(Color.LIGHT_GRAY);
z4periodlo.SetStyle(Curve.MEDIUM_DASH);
z4periodlo.SetLineWeight(1);
z4periodlo.HideBubble();

plot z5periodlo = if (slod and daycntrev == 5 and dayen) then (d5lowest * per3) else na;
z5periodlo.SetDefaultColor(Color.LIGHT_GRAY);
z5periodlo.SetStyle(Curve.MEDIUM_DASH);
z5periodlo.SetLineWeight(1);
z5periodlo.HideBubble();

plot z6periodlo = if (slod and daycntrev == 6 and dayen) then (d6lowest * per3) else na;
z6periodlo.SetDefaultColor(Color.LIGHT_GRAY);
z6periodlo.SetStyle(Curve.MEDIUM_DASH);
z6periodlo.SetLineWeight(1);
z6periodlo.HideBubble();

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

# ---------------------------------------------------
input show_line_description_bubbles = yes; #hint show_line_bubbles: "plot line descriptions, in bubbles, x bars after last bar, on each visible high/low lines"
input place_description_bubbles_x_bars_in_future = 22;
def bif = place_description_bubbles_x_bars_in_future;
def cl = close;
def x = IsNaN(cl[bif]) and !IsNaN(cl[bif + 1]);
#def vert = close[bif+1];
#AddChartBubble(x, vert, vert, color.white, yes);

#  crslin = 1  invisible , crslin = 2  dashes , crslin = 3  solid
def bub = (show_line_description_bubbles and x );
AddChartBubble((bub and dayqty >= 1 and (crslin == 2 or crslin == 3 or d1hixsub == 0)), d1highest, "day 1 high", Color.GRAY, yes);
AddChartBubble((bub and dayqty >= 2 and (crslin == 2 or crslin == 3 or d2hixsub == 0)), d2highest, "day 2 high", Color.GRAY, yes);
AddChartBubble((bub and dayqty >= 3 and (crslin == 2 or crslin == 3 or d3hixsub == 0)), d3highest, "day 3 high", Color.GRAY, yes);
AddChartBubble((bub and dayqty >= 4 and (crslin == 2 or crslin == 3 or d4hixsub == 0)), d4highest, "day 4 high", Color.GRAY, yes);
AddChartBubble((bub and dayqty >= 5 and (crslin == 2 or crslin == 3 or d5hixsub == 0)), d5highest, "day 5 high", Color.GRAY, yes);
AddChartBubble((bub and dayqty >= 6 and (crslin == 2 or crslin == 3 or d6hixsub == 0)), d6highest, "day 6 high", Color.GRAY, yes);

AddChartBubble((bub and dayqty >= 1 and (crslin == 2 or crslin == 3 or d1loxsub == 0)), d1lowest, "day 1 low", Color.GRAY, no);
AddChartBubble((bub and dayqty >= 2 and (crslin == 2 or crslin == 3 or d2loxsub == 0)), d2lowest, "day 2 low", Color.GRAY, no);
AddChartBubble((bub and dayqty >= 3 and (crslin == 2 or crslin == 3 or d3loxsub == 0)), d3lowest, "day 3 low", Color.GRAY, no);
AddChartBubble((bub and dayqty >= 4 and (crslin == 2 or crslin == 3 or d4loxsub == 0)), d4lowest, "day 4 low", Color.GRAY, no);
AddChartBubble((bub and dayqty >= 5 and (crslin == 2 or crslin == 3 or d5loxsub == 0)), d5lowest, "day 5 low", Color.GRAY, no);
AddChartBubble((bub and dayqty >= 6 and (crslin == 2 or crslin == 3 or d6loxsub == 0)), d6lowest, "day 6 low", Color.GRAY, no);

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

input show_day_of_week_label = yes;
AddLabel(show_day_of_week_label, day_of_week, Color.WHITE);

input day_number_bubbles = yes; #hint day_number_bubbles: "show bubbles with the count of the desired days"
AddChartBubble(day_number_bubbles and dayen and firstbar, (high * 1.01), daycntrev, if dayrev_en then Color.YELLOW else Color.GRAY, yes);

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

input OOOO_test_data_below_OOOO = 0;

# ======================================================
# ---- test code ----------------------------------
# ---- code samples -------------------------------
# ======================================================

input test_day_count_bubbles = no;
AddChartBubble(test_day_count_bubbles and dayen, (high * 1.01), "F." + daycnt + "\nR." + daycntrev, if dayrev_en then Color.YELLOW else Color.GRAY, yes);

input test_bubbles2 = no; #hint test_bubbles2: "dayrev_en , daycntrev , dayqt"
#addchartbubble(1, low, dayrev_en, if dayrev_en then color.cyan else color.gray, no);
AddChartBubble(test_bubbles2, low, dayrev_en + "\n" + daycntrev + "\n" + dayqty, if dayrev_en then Color.CYAN else Color.GRAY, no);
# =======================================================

input test_barnumbers_for_days = no;
AddLabel(test_barnumbers_for_days, "start bn's for " + dayqty + " days" , Color.CYAN);
AddLabel(test_barnumbers_for_days, "1= " + d1rev_startbn , Color.CYAN);
AddLabel(test_barnumbers_for_days, "2= " + d2rev_startbn , Color.CYAN);
AddLabel(test_barnumbers_for_days, "3= " + d3rev_startbn , Color.CYAN);
AddLabel(test_barnumbers_for_days, "4= " + d4rev_startbn , Color.CYAN);
AddLabel(test_barnumbers_for_days, "5= " + d5rev_startbn , Color.CYAN);
AddLabel(test_barnumbers_for_days, "6= " + d6rev_startbn , Color.CYAN);

# ----------------
# show labels, with qty of crossings, for all lines
input test_labels_line_crossing_counts = no;
addlabel(test_labels_line_crossing_counts, "#1 hi crosses " + d1hixsub, color.magenta);
addlabel(test_labels_line_crossing_counts, "#2 hi crosses " + d2hixsub, color.magenta);
addlabel(test_labels_line_crossing_counts, "#3 hi crosses " + d3hixsub, color.magenta);
addlabel(test_labels_line_crossing_counts, "#4 hi crosses " + d4hixsub, color.magenta);
addlabel(test_labels_line_crossing_counts, "#5 hi crosses " + d5hixsub, color.magenta);
addlabel(test_labels_line_crossing_counts, "#6 hi crosses " + d6hixsub, color.magenta);

addlabel(test_labels_line_crossing_counts, "#1 lo crosses " + d1loxsub, color.orange);
addlabel(test_labels_line_crossing_counts, "#2 lo crosses " + d2loxsub, color.orange);
addlabel(test_labels_line_crossing_counts, "#3 lo crosses " + d3loxsub, color.orange);
addlabel(test_labels_line_crossing_counts, "#4 lo crosses " + d4loxsub, color.orange);
addlabel(test_labels_line_crossing_counts, "#5 lo crosses " + d5loxsub, color.orange);
addlabel(test_labels_line_crossing_counts, "#6 lo crosses " + d6loxsub, color.orange);
# --------------------------
# =======================================================

#AddChartBubble(1, high, dayen, color.cyan, yes);
# puts a bubble on every bar, on the desired day
#AddChartBubble(dow == (day_of_week + 1), high, day_of_week, color.cyan, yes);

# test -  first bar of day
#AddChartBubble(show_bubbles and (daycntrev == 1 ) and ( !day1[1] and Day1), (low * 0.99), "hi " + d1hi, color.yellow, no);
#AddChartBubble(show_bubbles and (daycntrev == 2 ) and ( !day1[1] and Day1), (low * 0.98), "hi " + d2hi, color.cyan, no);

# all bars on the day
#AddChartBubble(show_bubbles and dayen, (high * 1.01), day_of_week + "\n" + dayen + "\n" + daycnt, color.yellow, yes);


#AddChartBubble(show_bubbles and (daycntrev == 1 ) , (low * 0.99),
# "dayen " + dayen
# + "\nhigh." + high
# + "\nd1hi." + d1hi
# + "\nH." + d1highest
# + "\nR." + daycntrev,
# if (high == d1highest) then color.yellow else color.gray, no);

#addchartbubble(1, low*0.996, "R." + "\n" + daycntrev , color.magenta, no);

#AddChartBubble(show_bubbles and (daycntrev == 2 ) , (low * 0.99), "2 " + high + "\n" + d2highest, if (high == d2highest) then color.yellow else color.gray, no);

# show_bubbles2
#AddChartBubble(show_bubbles , (low * 0.95), daycntrev, color.gray, no);

# =======================================================


# //////////////////////////////////////
# disable - use script --------------
# this works
# count crossings of #1 hi, after desired day

#def d1hix;
#if rev1start then {
#  d1hix = fold i = 1 to (lastbar - bn + 1)
#  with p
#  do p + (if (GetValue(low, -i + 1) < GetValue(d1highest, -i)) and (GetValue(high, -i) > GetValue(d1highest, -i)) then 1 else 0);
#} else {
#    d1hix = if bn == 1 then 0 else d1hix[1];
#};
# //////////////////////////////////////


# ========================================

# i used curve,  because curve.dash line always looks like a dash line

# this works,  but points are drawn much thicker than if a line.
#  and paint.dash looks solid when zoomed out.  didn't use this

# paint , line , points
#input lines = {default LINE, POINTS};
#def paint = if lines == lines.POINTS then PaintingStrategy.POINTS else  PaintingStrategy.LINE;
# plot x1 =
#x1.SetPaintingStrategy(paint);


# this doesn't work
# chg line if price crosses it
#def paint1hi = if d1hix > 0 then PaintingStrategy.POINTS else  PaintingStrategy.LINE;

#signal.SetPaintingStrategy(if crossingType == CrossingType.above
#    then PaintingStrategy.BOOLEAN_ARROW_UP
#    else PaintingStrategy.BOOLEAN_ARROW_DOWN);

# ========================================

# input crossed_line = {"invisible", "dots", default "dashes", "solid"};
# this works , but the PaintingStrategy.dashes  line looks like a solid line when zoomed out
# --------------------
#input test_price_line1 = no;
#plot line1x = if ( test_price_line1 and (crslin == 2 or crslin == 3 or crslin == 4)) then line1 else na;
#line1x.SetDefaultColor(Color.LIGHT_GREEN);
#line1x.HideBubble();
#line1x.SetPaintingStrategy(if crossed_line == crossed_line."dots" then PaintingStrategy.points
#  else if crossed_line == crossed_line."dashes" then PaintingStrategy.dashes
#  else if crossed_line == crossed_line."solid" then PaintingStrategy.line
#  else PaintingStrategy.squares);
# -------------------

# this works.  curve.dash  looks like a dash always
#plot L1_dash = if crslin == 2 then line1 else na;
#L1_dash.SetStyle(curve.short_dash);
#L1_dash.SetDefaultColor(Color.LIGHT_GREEN);
#L1_dash.HideBubble();
#plot L1_solid = if crslin == 3 then line1 else na;
#L1_solid.SetStyle(curve.firm);
#L1_solid.SetDefaultColor(Color.LIGHT_GREEN);
#L1_solid.HideBubble();


# this doesn't work
#plot line1x = if (crslin == 2 or crslin == 3) then line1 else na;
#line1x.SetDefaultColor(Color.LIGHT_GREEN);
#line1x.HideBubble();
#line1x.SetStyle(if crossed_line == crossed_line."dashes" then curve.short_dash else if crossed_line == crossed_line."solid" then curve.firm else curve.long_dash);

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

#z1hi.SetPaintingStrategy(paint1hi);
#z1hi.SetPaintingStrategy(if d1hix > 0 then PaintingStrategy.points else PaintingStrategy.line);

# this has error
#z1hi.SetStyle(if d1hix > 0 then Curve.POINTS else Curve.FIRM);

# https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/Curve
#x.SetStyle(Curve.FIRM);
#x.SetStyle(Curve.LONG_DASH);
#x.SetStyle(Curve.MEDIUM_DASH);
#x.SetStyle(Curve.SHORT_DASH);
#x.SetStyle(Curve.POINTS);

# x.SetStyle(Curve.MEDIUM_DASH);
# x.setlineweight(1);
# x.hidebubble();
# --------------------------

# ---- sample codes --------------------------------

# plot x = (  ) ;
# x.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);  # setlineweight() has no effect on font size
# x.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
# x.SetPaintingStrategy(PaintingStrategy.BOOLEAN_wedge_down);
# x.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
# x.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
# x.SetStyle(Curve.MEDIUM_DASH);
# x.SetDefaultColor(Color.red);
# x.setlineweight(1);
# x.hidebubble();

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

i think i have the day lines offset set to 0.2, instead of 0. that draws the gray dashed lines slightly above the highs.
when i grabbed these pictures, it didn't draw the lower day line yet.

crossed lines
invisible
fIRI6wz.jpg


dashes
oGavs90.jpg


solid
2yvLLJe.jpg

hal_remove
 
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
382 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