Anchoring comparison study to the opening price of the day

static

New member
This is for the comparison study. I am wondering if there is a way to make it so the comparison study starts at the opening price each day. The next day it would do the same always resetting to the open price.

Here is an example of what I'm describing. In the left image the comparison starts way down below the opening candle. The right image shows the comparison in-line with the opening candle of that day (I have to manually move it).

1hr chart
Mh0ztcP.png


Thanks
 
Solution
This is for the comparison study. I am wondering if there is a way to make it so the comparison study starts at the opening price each day. The next day it would do the same always resetting to the open price.

Here is an example of what I'm describing. In the left image the comparison starts way down below the opening candle. The right image shows the comparison in-line with the opening candle of that day (I have to manually move it).


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...
This is for the comparison study. I am wondering if there is a way to make it so the comparison study starts at the opening price each day. The next day it would do the same always resetting to the open price.

Here is an example of what I'm describing. In the left image the comparison starts way down below the opening candle. The right image shows the comparison in-line with the opening candle of that day (I have to manually move it).


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);
#
#

0yucPJh.jpg
 
Solution
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);
#
#

i added some code to draw the line on the last bar of the day

Code:
# compare_open_reset_daily_02

# 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;
input end = 1600;
def dayopen = if secondstillTime(start) == 0 then 1 else 0;
#def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;
def lasthour = if secondsfromTime(1500) >= 0 and secondstillTime(end) > 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);

# plot a 2nd line , overlapping firt. to draw on last bar, without connect to next day
plot z2 = if lasthour then stk2 else na;
z2.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);
#
 

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