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

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:

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:

nervo88

New member
@JabronLames Hello ! And thank you for your response. Please tell me , the current price and open price that you defined. How do you know it's using the data from when market open and not from the last bar ?
 

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:

nervo88

New member
@JabronLames Thanks man !!! I noticed it takes some time to load after I scan. Guess it's heavy for TOS. And tbere are some stocks it's not showing at all. But overall it's working good !
 

takiz1ma

New member
VIP
Can someone please help me create net change from open watch list column script, and a scanner. Thank you so much
 

jngy2k

Member
VIP
What's the difference between your column and the colume %CHANGE on TOS???
@Len20 @aharvard
I'd actually like to expand on this topic.
When I use this scan below, is the % change from yesterday to current price OR is the % change from the open of today to the current price???

edit: the TOS % change is from yesterday close to current price. But is it possible to scan criteria today %change from open to current price is a certain %????


last edit: figured it out
Code:
input price = close;
input percentchange = 1.0;
input Choice = {default less};

def fromopen = round(100*((close/open)-1),1);
plot scan;

switch (Choice){

case less:
    scan = fromopen <= -percentchange;

}

 
Last edited:

DSG

New member
I'm new to thinkscript and I've been searching what I thought would have been a simply scan, but not so easy for a newbie. I'm trying to create a way to find a bar that had a certain percent change within the past 10 days. Not total percent change from 10 days ago but a single day that had at least, let's say 20% change on any particular day within that 10 day period. So grateful to anyone who knows how to code this.
 

gladdin

New member
@jngy2k

I'm new to this. Does this indicate a 1 percent or greater change from open will show in the scan query? If so, can anyone advise as to why when entered I'm getting % change results (as indicated by the column % change and it's corresponding values) that are beyond that 1%? I'm trying to achieve a scan result that will only show stocks that have changed a certain percentage since open, whether it be negative or positive, so that I can set an alert for that query and react accordingly. Any help would be greatly appreciated.

Edit: Or, what about this? I'm still confused about the aggregator period and what that means, exactly. Running the below gives the same results as the default %change so I don't know if I have to wait until the market opens up to get an open value or what, tbh. Is it saying, for 1 days worth of time calculate the percentage change using the given (if aggregator is set to 1D). If that's the case, do you have to wait an entire day for it to update, or is it real-time? What is it saying if you set it to 1 hour? Percentage change from open for the most recent hour, excluding time previous to that, lol? I dunno.

Code:
input MinChangeFromOpen = 0.9; #Change from open, %
def ChangeFromOpen = AbsValue((close-open)/open*100);
plot Signal = ChangeFromOpen >= MinChangeFromOpen;
 
Last edited:

Explore28

New member
VIP
@jngy2k How do I show stocks that are greater than a specific percentage? This code worked perfectly for pulling stocks below a specific percentage. I'm sure it's extremely easy but I wasn't able to make it work. Thank you very much!
 

Similar threads

Top