# Percent Change from open column?

A

#### aharvard

##### New member
I have this study that display the percent change from the open. I would like to create a column in my watchlist that displays the percent change only. Can someone assist with altering the code to achieve this. Thank you kindly.

Code:
``````input period_Type = AggregationPeriod.DAY;

def begin = open(period = period_Type);
def end = close(period = period_Type);
def NetChg = end - begin;
def PctChg = (end / begin) - 1;

AddLabel(yes, "Open Net Change: " + NetChg + " (" + AsPercent(PctChg) + ")", if NetChg > 0 then Color.GREEN else if NetChg < 0 then color.RED else color.LIGHT_GRAY);``````
I posted this with the possiblity to seek assistance if anyone can help me code a watchlist column that will show the percent change when the market opens. The code above does this however I'm not sure how to convert it into a watchlist column.

Can someone assist. Thank you kindly

#### inthefutures

##### Active member
In your watch list click the gear at the top then customize, and in the published list is things called custom1, custom2 and so on, click on one of them and then it should give you spot to add your code.

Edit: sorry you need to add the custom1 to your viewed list then it brings up a script editor.

C

#### ceejackson

##### New member
I am trying to take a take a stock list and see the price change and % change. For example: if stock A was \$100.00 15 days ago, but today is only 75\$ the math is easy here; -25%. If stock B was \$100 30 days ago, but \$125 today; +25%. Any way to take the formula above and select close/open, days back, and calculate the gain/loss from X of days back? The formula above looks close to me, but the results don't seem to match what am calculating.

L

#### Len20

##### Member
I posted this with the possiblity to seek assistance if anyone can help me code a watchlist column that will show the percent change when the market opens. The code above does this however I'm not sure how to convert it into a watchlist column.

Can someone assist. Thank you kindly
This code from elsewhere should do it. Keep in mind that custom watchlist columns can lag.

Code:
``````## Must Set Aggregation to Daily ##

#percent change from open on watchlist
################################
# sdi_pctChgFromOpen: plots the percentage change from the opening price in a way that is appropriate for a watchlist custom column.
#hint: plots the percentage change from the opening price in a way that is appropriate for a watchlist custom column. rev: 1.0 http://www.smallDogInvestor.com
# author: allen everhart
# date: 22june2013
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale.
# Help me get the word out about my blog by keeping this header
# in place.

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

L

#### Len20

##### Member
I am trying to take a take a stock list and see the price change and % change. For example: if stock A was \$100.00 15 days ago, but today is only 75\$ the math is easy here; -25%. If stock B was \$100 30 days ago, but \$125 today; +25%. Any way to take the formula above and select close/open, days back, and calculate the gain/loss from X of days back? The formula above looks close to me, but the results don't seem to match what am calculating.
I'm still learning Thinkscript but this should work. You could create a separate column with this code (just change the number of days) for each number of days you'd like to go back

Code:
``````# Percent change from days ago watchlist column by LennyP

def DaysAgo = 15;

plot change = round((close/close[DaysAgo]-1)*100, 1);
change.assignValueColor( if change < 0 then color.RED else color.GREEN);``````

Last edited: