• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Percentage Change From Open Indicator for ThinkorSwim

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.
 

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.
 

Len20

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

#################
 

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:

docsep

New member
VIP
Hello.

Could someone help me create a percent change column for TOS watchlist with customize-able time frames?

I'm new to writing script and am unable to figure out how to do this.

Thanks,

Shane
 

Len20

Member
Try this:
Code:
input barsAgo = 10;

def price = close;
def oldPrice = close[barsAgo];

plot change = round(100 * ((price / oldPrice) - 1), 1);
change.assignValueColor( if change < 0 then color.RED else color.GREEN);

It's important to set the aggregation period up top when you create the watchlist. So in the example above, if you set it to Daily, it would compare the current price to 10 days ago. If you set it to "1 Minute" it would compare the current price to 10 minutes ago
 
If I have to see this in one minute daily chart for intraday trading and need to see price change back in 3 minutes candles how the script would be different?

I need to compare price 3 minutes ago in three minute daily chart. will it work?
 

nervo88

New member
Hello All ! I tried to look on the forum but did not find. Tried to build it myself but with no success.

I'm trying to add a column or a scan for %change since the market opens at 09:30...and not from the previous close price.

Thank you for your help !
 

JabronLames

Member
VIP
Hello,

I'm a bit new to this, but the code below should do the trick!

Code:
# Get percent change from Open

input Agg = AggregationPeriod.DAY;

def currentPrice = ask;
def openPrice = open;

def priceDifference = ask - open;

plot percentChange = priceDifference / open;

AddLabel(yes, open + "  " + close + "   " +asPercent(round(percentChange,4)), if close < open then color.RED else color.Green);

#Edit - fixed the label
 
Last edited:
I got it. Thanks. If I have to use on 5 minutes chart then what value do I set “input bar ago”?

If I understand correctly, any time frame for intraday 1 min, 3 min or 15 min, “Input bars ago” will remain always 1 bar ago?
I am novice so apologize for this.
Thanks.
 

JabronLames

Member
VIP
@Nervo,


The first input agg will set the currentPrice to day(I made sure I followed through with adding this as a parameter below).

currentPrice fetches the ask. Which should be a constant across all time periods..

I caught an error or two on the original code though now that you mention it..the fixed version is below. Thanks for helping me catch it!

Code:
# Get percent change from Open

input agg = AggregationPeriod.DAY;

def currentPrice = ask;
def openPrice = open(period = agg); # Fixed: I didn't set the agg as a parameter to the open price


def priceDifference = ask - open;

plot percentChange = priceDifference / open;

AddLabel(yes, asPercent(round(percentChange,4)), if ask < open then color.RED else color.Green); # changed close to ask

#Edit - fixed the label
 
Last edited:

Similar threads

Top