Percentage % change from market open

N

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 !
 
J

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:
N

nervo88

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

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:
N

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 iverall it's working good !
 
A

alphabeta

Member
@JabronLames hi is it possible to make watchlist? i tried your script but in watchlist is display Nan thank you!!
 
V

Vimal Mittal

Member
@JabronLames Is that possible to create watchlist in premarket or after hours? Premarket 5am to 9;30 am after hours 4pm to 7 pm or so. Thanks
 

Similar threads

Top