Display daily percentage change on different timeframes

Alex100

New member
Is it possible to display a label showing the daily percentage change of the current symbol, even if the chart is on a different timeframe, such as a 5-minute or weekly timeframe?

The following code successfully displays the daily percentage change, but only on the daily timeframe. On other timeframes, it shows either zero or 'n/a'. On weekly and monthly timeframes, it does not display at all, and I receive this error message: "Secondary period cannot be less than primary".

Code:
def c = close(period = AggregationPeriod.DAY);
AddLabel(yes, Round(((c - c[1]) / c[1]) * 100, 2) + "%", Color.BLACK);

If this isn't possible, could you kindly advise me on how to display the daily price change on the chart, regardless of the timeframe? The TOS % change displayed at the top of each chart is written very small among the bid/ask/last prices, and I'm unable to increase the font size without globally enlarging the font size in 'Application Settings'.

Thank you!

Alex
 
Last edited:
Is it possible to display a label showing the daily percentage change of the current symbol, even if the chart is on a different timeframe, such as a 5-minute or weekly timeframe?

The following code successfully displays the daily percentage change, but only on the daily timeframe. On other timeframes, it shows either zero or 'n/a'. On weekly and monthly timeframes, it does not display at all, and I receive this error message: "Secondary period cannot be less than primary".

Code:
def c = close(period = AggregationPeriod.DAY);
AddLabel(yes, Round(((c - c[1]) / c[1]) * 100, 2) + "%", Color.BLACK);

If this isn't possible, could you kindly advise me on how to display the daily price change on the chart, regardless of the timeframe? The TOS % change displayed at the top of each chart is written very small among the bid/ask/last prices, and I'm unable to increase the font size without globally enlarging the font size in 'Application Settings'.

Thank you!

Alex

this works if the chart time is less than a day.

this finds the OHLC levels from yesterday
previous day open is cyan. close is yellow.
it compares the close form yesterday to current price.
a label shows the difference. it is colored depending on if it is higher or lower

you could check what the chart aggregation time is ( day or less) and use your formula or mine.

if the chart is set to week, then each candle has open, high, low, close for a week.
then there won't be data for day close. a candle won't have data during the candle.

Code:
#prev_day_ohlc_noagg

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

def d = getday();
def isprevday = (d + 1) == getlastday();
def currentday = d == getlastday();

def prevdayopn = if bn == 1 then 0
 else if isprevday and d[1] != d then open
 else prevdayopn[1];

def prevdaycls = if bn == 1 then 0
 else if isprevday and d != d[-1] then close
 else prevdaycls[1];

def prevdayhi = if bn == 1 then 0
 else if isprevday then max(prevdayhi[1], high)
 else prevdayhi[1];

def prevdaylo = if bn == 1 then big
 else if isprevday then min(prevdaylo[1], low)
 else prevdaylo[1];

plot zopn = if currentday then prevdayopn else na;
plot zhi = if currentday then prevdayhi else na;
plot zlo = if currentday then prevdaylo else na;
plot zcls = if currentday then prevdaycls else na;
zopn.setdefaultcolor(color.cyan);
zhi.setdefaultcolor(color.gray);
zlo.setdefaultcolor(color.gray);
zcls.setdefaultcolor(color.yellow);

def clsdiff = close - prevdaycls;
addlabel(1, "close diff " + clsdiff, (if clsdiff > 0 then color.green else color.red));
#
 
Thank you for the script! I'm not sure what's happening, but when I load a daily timeframe it shows a value, and then when I switch to a 5 minute timeframe it shows a whole different value. At some point, on a one minute timeframe, I got a really big number, like 500 or so.

The fact that only works on smaller timeframes is ok with me, but on every intraday timeframe it should consistently display the daily price change for that stock (preferably as a percent change). So there should be no difference at all between daily and intraday timeframes, they should all show the daily change.

Alex
 
I trade futures- and I would love to have this label with customizable start time... so I can evaluate based on sessions etc.
this works if the chart time is less than a day.

this finds the OHLC levels from yesterday
previous day open is cyan. close is yellow.
it compares the close form yesterday to current price.
a label shows the difference. it is colored depending on if it is higher or lower

you could check what the chart aggregation time is ( day or less) and use your formula or mine.

if the chart is set to week, then each candle has open, high, low, close for a week.
then there won't be data for day close. a candle won't have data during the candle.

Code:
#prev_day_ohlc_noagg

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

def d = getday();
def isprevday = (d + 1) == getlastday();
def currentday = d == getlastday();

def prevdayopn = if bn == 1 then 0
 else if isprevday and d[1] != d then open
 else prevdayopn[1];

def prevdaycls = if bn == 1 then 0
 else if isprevday and d != d[-1] then close
 else prevdaycls[1];

def prevdayhi = if bn == 1 then 0
 else if isprevday then max(prevdayhi[1], high)
 else prevdayhi[1];

def prevdaylo = if bn == 1 then big
 else if isprevday then min(prevdaylo[1], low)
 else prevdaylo[1];

plot zopn = if currentday then prevdayopn else na;
plot zhi = if currentday then prevdayhi else na;
plot zlo = if currentday then prevdaylo else na;
plot zcls = if currentday then prevdaycls else na;
zopn.setdefaultcolor(color.cyan);
zhi.setdefaultcolor(color.gray);
zlo.setdefaultcolor(color.gray);
zcls.setdefaultcolor(color.yellow);

def clsdiff = close - prevdaycls;
addlabel(1, "close diff " + clsdiff, (if clsdiff > 0 then color.green else color.red));
#
I trade futures- and I would love to have this label with customizable start time... so I can evaluate based on sessions etc.
 
Thank you for the script! I'm not sure what's happening, but when I load a daily timeframe it shows a value, and then when I switch to a 5 minute timeframe it shows a whole different value. At some point, on a one minute timeframe, I got a really big number, like 500 or so.

The fact that only works on smaller timeframes is ok with me, but on every intraday timeframe it should consistently display the daily price change for that stock (preferably as a percent change). So there should be no difference at all between daily and intraday timeframes, they should all show the daily change.

Alex
my charts show the same number.
if the chart is just 1 day, then a big number appear. pick a chart time that spans 2+ days
 
my charts show the same number.

Please check the attached screenshot, it displays two Tesla charts.

The 5-minute chart shows a value of -1.11, while the daily chart indicates a value of -2.88. So, they do not match.

What I need is for both charts to display the daily percentage change, which is -1.92%, as indicated by TOS.

Alex
 

Attachments

  • screenshot.png
    screenshot.png
    50.7 KB · Views: 48

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
331 Online
Create Post

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