this will show a line for a second stock price, and reset it on the first bar of each day.
can choose to match up the 2 stocks on the day first bar, by open or close.
if you choose open, then it draws a line at the open prices for all the bars of stock2.
it doesn't draw a line on the last bar, bacause that would cause a line to connect to the first bar of the next day.
Code:
# compare_open_reset_daily_0
# https://usethinkscript.com/threads/anchoring-comparison-study-to-the-opening-price-of-the-day.13214/#post-111472
# compare, reset daily
#Anchoring comparison study to the opening price of the day
# static 11/1
def na = double.nan;
input start = 0930;
def dayopen = if secondstillTime(start) == 0 then 1 else 0;
#addverticalline(dayopen, "-", color.cyan);
input chart_type = { default open , close };
def stk1_open = open;
def stk1_close = close;
input stock2 = "SPY";
def stk2_open = open(stock2);
def stk2_close = close(stock2);
def stk2o_off = if dayopen then stk1_open - stk2_open
else stk2o_off[1];
def stk2c_off = if dayopen then stk1_close - stk2_close
else stk2c_off[1];
def stk2;
def type;
switch (chart_type) {
case open:
stk2 = stk2_open + stk2o_off;
type = 1;
case close:
stk2 = stk2_close + stk2c_off;
type = 2;
}
plot z = if dayopen[-1] then na else stk2;
z.SetDefaultColor(Color.cyan);
addlabel(1, "comparing " + stock2, color.yellow);
addlabel(1, (if type == 1 then "reset to day bar1 Open"
else if type == 2 then "reset to day bar1 close"
else "-"), color.yellow);
#
#