How to set custom start time for simple % change watchlist indicator

phil48

New member
I'm working on a script for a simple % Absolute Change from Open indicator.

This is the code I use for the Daily timeframe.

def y=round(100*((close/open)-1),2);
plot x=absValue(round(100*((close/open)-1),2));
x.assignValueColor( if y < 0 then color.RED else color.GREEN);


However, I'd like to start at 9:45 am instead of 9:30 am.

----------------------------------------------------------------------------------------

This is what I have so far, but it's showing me the same results.
input StartAggregation= 0945;
input StartPlotTime= 1;
def durationSec = StartPlotTime* 60 * 60;declare upper;

def PlotStartTime = 0945;#Hint PlotStartTime: Adjust begin time to pre/market open
def PlotEndTIme = 1600;#Hint PlotEndTime: Adjust end time to after/market close
#def Set = close(period = AggregationPeriod.DAY, priceType = PriceType.LAST)[1];#Auto grabs last close

def abs = absValue(round(100*((close/open)-1),2));

def CloseTime2 = SecondsTillTime(PlotEndTIme) >= 0;
def OpenTime2 = SecondsFromTime(PlotStartTime) >= 0;
def MarketOpen = OpenTime2 and CloseTime2;
def Chart = MarketOpen;

def secondsPassed = SecondsFromTime(StartPlotTime);

plot x= if chart>0 and startaggregation > 0 and secondsPassed >= 0 and secondsPassed <= durationSec then abs else double.NaN;
x.assignValueColor( if x < 0 then color.RED else color.GREEN);

----------------------

This is another script I've tried but am getting NaN results in the columns

declare lower;
input timeofday = 0945;
input pricetype = {default open, high, low, close};


input method = {Date, default Periods};
###
input Date = 20221104;
###
input periodsback = 0;
def ymd = GetYYYYMMDD();
def candles = !IsNaN(open);
def capture = candles and ymd != ymd[1];
def periodCount = CompoundValue(1, if capture then periodCount[1] + 1 else periodCount[1], 0);
def thisperiod = (HighestAll(periodCount) - periodCount) ;
###

def timewhen = if SecondsTillTime(timeofday)[1] > 0 and
SecondsTillTime(timeofday) <= 0 or
(SecondsTillTime(timeofday)[1] < SecondsTillTime(timeofday) and
SecondsTillTime(timeofday)[1] > 0)
then 1
else 0
;


def pricewhen = if method == method.Periods and
thisperiod == periodsback and
timewhen
then Fundamental(pricetype)
else if method == method.Date and
ymd == Date and
timewhen
then Fundamental(pricetype)
else pricewhen[1];

plot test = if pricewhen then absValue(round(100*((close/open)-1),2))else double.NaN;

Any help would be greatly appreciated!

Thanks!!
 
Solution
I'm working on a script for a simple % Absolute Change from Open indicator.

However, I'd like to start at 9:45 am instead of 9:30 am.

sleepyz, hope you don't mind, i saw this and had an idea and ran with it


phil48,
you weren't saving the open from the specified time , so you weren't comparing valid numbers.

-----------------
compare the price change from the open at some time to the current close.
default open time is 9:45


column study

zcompopen01
http://tos.mx/3FqetaR
1 minute

Code:
# zcompopen01
# compare_timeopen_00

# https://usethinkscript.com/threads/how-to-set-custom-start-time-for-simple-change-watchlist-indicator.13253/
# compare open time from xx:xx to close

#declare lower;

def na = double.nan;
def...
I'm working on a script for a simple % Absolute Change from Open indicator.

This is the code I use for the Daily timeframe.

def y=round(100*((close/open)-1),2);
plot x=absValue(round(100*((close/open)-1),2));
x.assignValueColor( if y < 0 then color.RED else color.GREEN);


However, I'd like to start at 9:45 am instead of 9:30 am.

----------------------------------------------------------------------------------------

This is what I have so far, but it's showing me the same results.
input StartAggregation= 0945;
input StartPlotTime= 1;
def durationSec = StartPlotTime* 60 * 60;declare upper;

def PlotStartTime = 0945;#Hint PlotStartTime: Adjust begin time to pre/market open
def PlotEndTIme = 1600;#Hint PlotEndTime: Adjust end time to after/market close
#def Set = close(period = AggregationPeriod.DAY, priceType = PriceType.LAST)[1];#Auto grabs last close

def abs = absValue(round(100*((close/open)-1),2));

def CloseTime2 = SecondsTillTime(PlotEndTIme) >= 0;
def OpenTime2 = SecondsFromTime(PlotStartTime) >= 0;
def MarketOpen = OpenTime2 and CloseTime2;
def Chart = MarketOpen;

def secondsPassed = SecondsFromTime(StartPlotTime);

plot x= if chart>0 and startaggregation > 0 and secondsPassed >= 0 and secondsPassed <= durationSec then abs else double.NaN;
x.assignValueColor( if x < 0 then color.RED else color.GREEN);

----------------------

This is another script I've tried but am getting NaN results in the columns

declare lower;
input timeofday = 0945;
input pricetype = {default open, high, low, close};


input method = {Date, default Periods};
###
input Date = 20221104;
###
input periodsback = 0;
def ymd = GetYYYYMMDD();
def candles = !IsNaN(open);
def capture = candles and ymd != ymd[1];
def periodCount = CompoundValue(1, if capture then periodCount[1] + 1 else periodCount[1], 0);
def thisperiod = (HighestAll(periodCount) - periodCount) ;
###

def timewhen = if SecondsTillTime(timeofday)[1] > 0 and
SecondsTillTime(timeofday) <= 0 or
(SecondsTillTime(timeofday)[1] < SecondsTillTime(timeofday) and
SecondsTillTime(timeofday)[1] > 0)
then 1
else 0
;


def pricewhen = if method == method.Periods and
thisperiod == periodsback and
timewhen
then Fundamental(pricetype)
else if method == method.Date and
ymd == Date and
timewhen
then Fundamental(pricetype)
else pricewhen[1];

plot test = if pricewhen then absValue(round(100*((close/open)-1),2))else double.NaN;

Any help would be greatly appreciated!

Thanks!!

You cannot use an intraday time on a daily chart timeframe.

Try your scripts at a 15m chart setting, for example, and see if you get the results you are wanting. If not, then let us know.
 

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

Hi @SleepyZ I should've mentioned it before. The second script (referenced below) gives me NaN when I put it on the 15-minute timeframe. When I did it on the Daily, it just gives me the same absolute % change from open, not 9:45 for the reason you mentioned. Thanks.

input StartAggregation= 0945;
input StartPlotTime= 1;
def durationSec = StartPlotTime* 60 * 60;declare upper;

def PlotStartTime = 0945;#Hint PlotStartTime: Adjust begin time to pre/market open
def PlotEndTIme = 1600;#Hint PlotEndTime: Adjust end time to after/market close
#def Set = close(period = AggregationPeriod.DAY, priceType = PriceType.LAST)[1];#Auto grabs last close

def abs = absValue(round(100*((close/open)-1),2));

def CloseTime2 = SecondsTillTime(PlotEndTIme) >= 0;
def OpenTime2 = SecondsFromTime(PlotStartTime) >= 0;
def MarketOpen = OpenTime2 and CloseTime2;
def Chart = MarketOpen;

def secondsPassed = SecondsFromTime(StartPlotTime);

plot x= if chart>0 and startaggregation > 0 and secondsPassed >= 0 and secondsPassed <= durationSec then abs else double.NaN;
x.assignValueColor( if x < 0 then color.RED else color.GREEN);
 
I'm working on a script for a simple % Absolute Change from Open indicator.

However, I'd like to start at 9:45 am instead of 9:30 am.

sleepyz, hope you don't mind, i saw this and had an idea and ran with it


phil48,
you weren't saving the open from the specified time , so you weren't comparing valid numbers.

-----------------
compare the price change from the open at some time to the current close.
default open time is 9:45


column study

zcompopen01
http://tos.mx/3FqetaR
1 minute

Code:
# zcompopen01
# compare_timeopen_00

# https://usethinkscript.com/threads/how-to-set-custom-start-time-for-simple-change-watchlist-indicator.13253/
# compare open time from xx:xx to close

#declare lower;

def na = double.nan;
def bn = barnumber();

def diffday = if getday() != getday()[1] then 1 else 0;

input start_time = 0945;
input end_tIme = 1600;
def period = if secondsfromTime(start_time) >= 0 and secondstillTime(end_time) > 0 then 1 else 0;

def sthr = floor(start_time/100);
def stmn = start_time - (sthr*100);


def start_time_open = if bn == 1 then na
#  else if diffday then na
  else if secondsfromTime(start_time) == 0 then open
  else  start_time_open[1];

def diff = close - start_time_open;
def diff_per = Round(100 * ((close/start_time_open)-1), 2);


plot z = diff_per;
# font color
z.SetDefaultColor(Color.black);

# column cell color
Assignbackgroundcolor((if diff_per < 0 then Color.RED else Color.GREEN));
#

==============================


test - upper study
draws a line from the specified open price

Code:
# compare_timeopen_00

# https://usethinkscript.com/threads/how-to-set-custom-start-time-for-simple-change-watchlist-indicator.13253/
# compare open time from xx:xx to close

def na = double.nan;
def bn = barnumber();

def diffday = if getday() != getday()[1] then 1 else 0;

input start_time = 0945;
input end_tIme = 1600;
def period = if secondsfromTime(start_time) >= 0 and secondstillTime(end_time) > 0 then 1 else 0;

def sthr = floor(start_time/100);
def stmn = start_time - (sthr*100);


def start_time_open = if bn == 1 then na
# else if diffday then na
  else if secondsfromTime(start_time) == 0 then open
  else  start_time_open[1];

def diff = close - start_time_open;
def diff_per = Round(100 * ((close/start_time_open)-1), 2);

plot o = start_time_open;
o.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
o.SetStyle(Curve.MEDIUM_DASH);
o.SetDefaultColor(Color.magenta);
o.setlineweight(1);
o.hidebubble();


addlabel(1, " ", color.black);
addlabel(1, "price difference from open at " + sthr + ":" + stmn + "  $" + diff, (if diff_per < 0 then Color.RED else Color.GREEN));
addlabel(1, " ", color.black);
addlabel(1, "percent gain " + diff_per + "%", (if diff_per < 0 then Color.RED else Color.GREEN));
#


----------------------


test - lower study

Code:
# compare_timeopen_00_lower

# https://usethinkscript.com/threads/how-to-set-custom-start-time-for-simple-change-watchlist-indicator.13253/
# compare open time from xx:xx to close

declare lower;

def na = double.nan;
def bn = barnumber();

def diffday = if getday() != getday()[1] then 1 else 0;

input start_time = 0945;
input end_tIme = 1600;
def period = if secondsfromTime(start_time) >= 0 and secondstillTime(end_time) > 0 then 1 else 0;

def sthr = floor(start_time/100);
def stmn = start_time - (sthr*100);


def start_time_open = if bn == 1 then na
  #else if diffday then na
  else if secondsfromTime(start_time) == 0 then open
  else  start_time_open[1];

def diff = close - start_time_open;
def diff_per = Round(100 * ((close/start_time_open)-1), 2);

#plot o = start_time_open;
#o.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#o.SetStyle(Curve.MEDIUM_DASH);
#o.SetDefaultColor(Color.magenta);
#o.setlineweight(1);
#o.hidebubble();


#addlabel(1, " ", color.black);
#addlabel(1, "price difference from open at " + sthr + ":" + stmn + "  $" + diff, (if diff_per < 0 then Color.RED else Color.GREEN));
#addlabel(1, " ", color.black);
#addlabel(1, "percent gain " + diff_per + "%", (if diff_per < 0 then Color.RED else Color.GREEN));

addlabel(1, diff_per + "%", Color.black);

Assignbackgroundcolor((if diff_per < 0 then Color.RED else Color.GREEN));
#

column , 1 minute
list percent change from the specified open
fgy3PDn.jpg



test - upper
lines drawn from specified open
N4E38aG.jpg
 
Solution
This is amazing @halcyonguy ! Thanks so much! I adjusted the code slightly to match what I currently had for absolute % change from open.


byM4Gr5.png


The code you sent and I updated (labeled "EN") is on the left and my original Absolute % Change from open is on the right.

For some reason I'm getting errors on just two tickers and I don't know why. 😬

(The edited code reflected in my screenshot is written below)

# zcompopen01
# compare_timeopen_00

# https://usethinkscript.com/threads/...-for-simple-change-watchlist-indicator.13253/
# compare open time from xx:xx to close

#declare lower;

def na = double.nan;
def bn = barnumber();

def diffday = if getday() != getday()[1] then 1 else 0;

input start_time = 0945;
input end_tIme = 1600;
def period = if secondsfromTime(start_time) >= 0 and secondstillTime(end_time) > 0 then 1 else 0;

def sthr = floor(start_time/100);
def stmn = start_time - (sthr*100);


def start_time_open = if bn == 1 then na
# else if diffday then na
else if secondsfromTime(start_time) == 0 then open
else start_time_open[1];

def diff = close - start_time_open;
def diff_per = Round(100 * ((close/start_time_open)-1), 2);


plot z = absValue(diff_per);
# font color
z.assignValueColor( if diff_per < 0 then color.RED else color.GREEN);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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