• Memorial Day Sale! Claim the biggest discount of the year with $50 off VIP using code MEM50. Sign up here.

Get Specific Months For Seasonality

tdespenza

New member
VIP
I've trying to replicate the seasonality with labels from Stockcharts but I'm having trouble accessing the specific months. Can someone point me in the right direction?

$NFLX example => https://stockcharts.com/freecharts/seasonality.php?symbol=nflx&compare=

Here's what I have so far:

Code:
Assert(GetAggregationPeriod() == AggregationPeriod.MONTH, "The `MonthlySeasonality` study is designed for monthly charts only");

def month = GetMonth();

def currentMoney = close - open;
def currentPercentage = (currentMoney / close) * 100;
AddLabel(visible = Yes, text = "Current: " + AsText(currentMoney, format = NumberFormat.DOLLAR) + "/" + AsText(currentPercentage) + "%", color = Color.LIGHT_GRAY);

def janDifference = Average(data = close[1]) - Average(data = open[1]);
def janPercentage = Average(janDifference) / Average(data = close[1]) * 100;
def janPostive = Average(janPercentage > 0) * 100;
AddLabel(visible = Yes, text = "Jan: " + AsText(value = janPostive) + "%+|Avg: " + AsText(janPercentage) + "%", color = Color.WHITE);
 
Last edited:

XeoNoX

Well-known member
VIP
You can do this easier by:

23moback = aggregate to monthly and scan within last 23 months since TOS scan wont go 24 months back

Code:
score = if  close > open then plus 1 else 0
finalscore = sum of score

reference for scoring ( https://usethinkscript.com/threads/basic-scoring-system.4954/#post-46304 )

final_scan = final score percent forumula

if you want help repeat this pattern below until you get to month1 and post the code back ( just repeat the countdown till you hit 1, should be a total of 23 lines that look similar)

Code:
def month21 = if (open(period = AggregationPeriod.MONTH)[21]) < (close(period = AggregationPeriod.MONTH)[21]) then 1 else 0;
def month22 = if (open(period = AggregationPeriod.MONTH)[22]) < (close(period = AggregationPeriod.MONTH)[22]) then 1 else 0;
def month23 = if (open(period = AggregationPeriod.MONTH)[23]) < (close(period = AggregationPeriod.MONTH)[23]) then 1 else 0;
 
Last edited:

XeoNoX

Well-known member
VIP
@tdespenza You were looking for something like this? One shows the percentage of higher closes over 48 months and the other shows number of consecutive bars over 48 months plotted (non percent) or were u looking for year over year same month comparison 4 years back?

Capture.png
 

tdespenza

New member
VIP
Unfortunately, I don't have a better one.

But what I'm looking for are labels to add to the chart. Whereas it displays the seasonality of a specific month.
 

bp805

Member
Giving this a bump. Im interested in trying to get this to work as well.

Basically what we're looking for is a chart label for every month displayed on a monthly time frame that gives the historical % that a given stock is up during that month, and an average % gain for that month. Ideally we'd be able to have the label show this for the life of the stock, but if that wont work, at least 10 years worth would be good.
 

bp805

Member
Hi All,

I am creating a set of labels to display on a monthly chart to show the historical average return by month, and the % of time that that month is a positive returning month (trying to mirror the seasonality chart available on stockcharts.com). I have the labels coded up correctly (I manually calculated the values that the labels should display, and they are working right), and January/February/March display the correct return. However, once I begin to add April and May to the code, the percentages on the labels all of a sudden change to incorrect percentages and I cannot figure out why this is. Does anyone know why this might be the case? See screenshot examples below.

I am using the chart of Visa (V) displayed on a 10 year Monthly chart as my reference point while I build this out.

These are the correct percentages:
24WGHCN.jpg


Once I begin to add additional months to the code, the percentages change to this:
JrVrKJH.jpg


This is the thinkscript code I am using. All I am doing for each new month is changing the GetMonth() == # to the appropriate month #, and changing the three letter month prefix (Jan, Feb, March, etc) throughout the code. I have tried switching back and fourth from a 5 and 20 year monthly and back to the 10 year to see if the problem is "refreshed" and fixed so to speak, but that doesn't do it. Can't seem to figure out why this is happening. The % Positive labels on a 5 and 10 year monthly chart should display in whole 10% increments, but you'll notice in the second image this is not the case once I add more months the code, and the "January Average" changes from .2% to .11%. Any thoughts or help would be appreciated. Thanks!

Code:
#January
def JanCount = if GetMonth() == 1 then JanCount[1] + 1 else JanCount[1];
def JanChg = if GetMonth() == 1 then JanChg[1] + ((close - open) / open) else JanChg[1];

def JanPOSCount = if GetMonth() == 1 AND Close > Open then JanPOSCount[1] + 1 else JanPosCount[1];

def JanPOSChg = if GetMonth() == 1 AND Close > Open then JanPOSChg[1] + ((close-open) / open) else JanPOSChg[1];

AddLabel(1, "January Average: " + AsPercent(JanChg / JanCount),  Color.CYAN);

addLabel(1, "% Positive: " + AsPercent(JanPosCount/JanCount), Color.CYAN);
 

Slippage

Well-known member
Giving this a bump. Im interested in trying to get this to work as well.

Basically what we're looking for is a chart label for every month displayed on a monthly time frame that gives the historical % that a given stock is up during that month, and an average % gain for that month. Ideally we'd be able to have the label show this for the life of the stock, but if that wont work, at least 10 years worth would be good.

10+ years x 12 months = minimum 120 labels on the chart per stock. I doubt you're really going to want that. You should take a look at the built-in MonthlySeasonality study if you want that much data.

Like that study, for any custom solution you'll be limited to use on a monthly chart. You can't access enough data via ThinkScript for 10 years from a daily chart.

You can access the same month in a prior year by using an index of 12. For multiple years ago, multiply by twelve.

I wrote the code below for you to use as an example. It calculates the average return for each month over the last 10 years. Note, the way TOS averaging works, if there's not 10 years of data then you'll get nothing.

Again, This will only work on a monthly chart.
Ruby:
Assert(GetAggregationPeriod() == AggregationPeriod.MONTH, "The `Seasonality` study is designed for monthly charts only");

def return = close / open;
def r = Round(if return > 1 then (return - 1) * 100 else if return < 1 then (1 - return) * -100 else 1, 2);
def factor = 12;
def avg = (
  r[factor] + r[factor * 2] + r[factor * 3] + r[factor * 4] + r[factor * 5]
  + r[factor * 6] + r[factor * 7] + r[factor * 8] + r[factor * 9] + r[factor * 10]
) / 10;


# display the month-to-date return
AddLabel(yes, "MTD: " + r + "%", Color.LIGHT_GRAY);

def m = GetMonth();

# display the average return for this month
AddLabel(
  yes,
  (if m == 1 then "Jan"
    else if m == 2 then "Feb"
    else if m == 3 then "Mar"
    else if m == 4 then "Apr"
    else if m == 5 then "May"
    else if m == 6 then "Jun"
    else if m == 7 then "Jul"
    else if m == 8 then "Aug"
    else if m == 9 then "Sep"
    else if m == 10 then "Oct"
    else if m == 11 then "Nov"
    else "Dec") + ": " + Round(avg, 2) + "%",
  Color.LIGHT_GRAY
);

# display the average return for next month
AddLabel(
  yes,
  (if m[-1] == 1 then "Jan"
    else if m[-1] == 2 then "Feb"
    else if m[-1] == 3 then "Mar"
    else if m[-1] == 4 then "Apr"
    else if m[-1] == 5 then "May"
    else if m[-1] == 6 then "Jun"
    else if m[-1] == 7 then "Jul"
    else if m[-1] == 8 then "Aug"
    else if m[-1] == 9 then "Sep"
    else if m[-1] == 10 then "Oct"
    else if m[-1] == 11 then "Nov"
    else "Dec") + ": " + Round(avg[-1], 2) + "%",
  Color.LIGHT_GRAY
);
 

bp805

Member
10+ years x 12 months = minimum 120 labels on the chart per stock. I doubt you're really going to want that. You should take a look at the built-in MonthlySeasonality study if you want that much data.

Like that study, for any custom solution you'll be limited to use on a monthly chart. You can't access enough data via ThinkScript for 10 years from a daily chart.

You can access the same month in a prior year by using an index of 12. For multiple years ago, multiply by twelve.

I wrote the code below for you to use as an example. It calculates the average return for each month over the last 10 years. Note, the way TOS averaging works, if there's not 10 years of data then you'll get nothing.

Again, This will only work on a monthly chart.
Ruby:
Assert(GetAggregationPeriod() == AggregationPeriod.MONTH, "The `Seasonality` study is designed for monthly charts only");

def return = close / open;
def r = Round(if return > 1 then (return - 1) * 100 else if return < 1 then (1 - return) * -100 else 1, 2);
def factor = 12;
def avg = (
  r[factor] + r[factor * 2] + r[factor * 3] + r[factor * 4] + r[factor * 5]
  + r[factor * 6] + r[factor * 7] + r[factor * 8] + r[factor * 9] + r[factor * 10]
) / 10;


# display the month-to-date return
AddLabel(yes, "MTD: " + r + "%", Color.LIGHT_GRAY);

def m = GetMonth();

# display the average return for this month
AddLabel(
  yes,
  (if m == 1 then "Jan"
    else if m == 2 then "Feb"
    else if m == 3 then "Mar"
    else if m == 4 then "Apr"
    else if m == 5 then "May"
    else if m == 6 then "Jun"
    else if m == 7 then "Jul"
    else if m == 8 then "Aug"
    else if m == 9 then "Sep"
    else if m == 10 then "Oct"
    else if m == 11 then "Nov"
    else "Dec") + ": " + Round(avg, 2) + "%",
  Color.LIGHT_GRAY
);

# display the average return for next month
AddLabel(
  yes,
  (if m[-1] == 1 then "Jan"
    else if m[-1] == 2 then "Feb"
    else if m[-1] == 3 then "Mar"
    else if m[-1] == 4 then "Apr"
    else if m[-1] == 5 then "May"
    else if m[-1] == 6 then "Jun"
    else if m[-1] == 7 then "Jul"
    else if m[-1] == 8 then "Aug"
    else if m[-1] == 9 then "Sep"
    else if m[-1] == 10 then "Oct"
    else if m[-1] == 11 then "Nov"
    else "Dec") + ": " + Round(avg[-1], 2) + "%",
  Color.LIGHT_GRAY
);

@Slippage I guess I should have explained more clearly. Not looking for one label per month for each year for 10 years (total of 120 labels) but one label for each month, total of 12, displayed on a monthly chart that would show the total average return for that month. I'd also want a second label that shows the % of time that that given month has a positive return (50%, 60%, 70% etc.). Essentially trying to replicate what stockcharts.com has on their seasonality charts here: https://stockcharts.com/freecharts/seasonality.php?symbol=aapl&compare=

See the below screenshot for what I've tried to achieve.

LkrcvY8.jpg


I've also started a post a couple days ago with the code that I'm using that I'm having issues with. See the link below for that post....

https://usethinkscript.com/threads/monthly-average-labels-problem.6456/

Thanks!
 

Slippage

Well-known member
I modified your label to include the count:

Ruby:
def JanCount = if GetMonth() == 1 then JanCount[1] + 1 else JanCount[1];
def JanChg = if GetMonth() == 1 then JanChg[1] + ((close - open) / open) else JanChg[1];
def JanPOSCount = if GetMonth() == 1 AND Close > Open then JanPOSCount[1] + 1 else JanPosCount[1];
AddLabel(1,
  "Jan Avg: " + AsPercent(JanChg / JanCount) + " | % Positive: " + AsPercent(JanPOSCount / JanCount) + " of " + JanCount,
   Color.CYAN
);

I copy/paste/modified that to have labels through July. When I have Jan through Apr there are 10 Jans. When I add May there are 11 Jans. The same occurs with SPY and TSLA so it's not anything symbol-specific. I'm guessing this happens when the current month is added to the code. Next month May won't break the code but June will. It seems to be an issue with how TOS provides the rolling time period. I adjusted my expansion area but, as I expected, that had no effect.

The calculations are accurate if you consider them in the context of calendar years. In the last 10 whole calendar years plus the current partial calendar year, there have been 11 Jans and 10 Junes. If you set the chart to a fixed time range of 5/4/12 to 5/4/21 it gives you 10 Jans, 10 Mays, 9 Junes, 9 Julys.

Now that there's an explanation for this and the data is accurate, with the caveat of months in the current year that have already passed are 11 yr averages instead of 10, you could choose to live with it. Another option is to look back instead of tracking as time passes, like the code I gave you in the other thread, but the problem with that is symbols that don't have enough data for the average length won't show anything.

If you stick with this code, you might want to consider modifying to use a single label per month like I did above. That way if the labels take up too much horizontal space and end up wrapping, the values for a single month will stay together.
 
Last edited:

bp805

Member
I modified your label to include the count:

Ruby:
def JanCount = if GetMonth() == 1 then JanCount[1] + 1 else JanCount[1];
def JanChg = if GetMonth() == 1 then JanChg[1] + ((close - open) / open) else JanChg[1];
def JanPOSCount = if GetMonth() == 1 AND Close > Open then JanPOSCount[1] + 1 else JanPosCount[1];
AddLabel(1,
  "Jan Avg: " + AsPercent(JanChg / JanCount) + " | % Positive: " + AsPercent(JanPOSCount / JanCount) + " of " + JanCount,
   Color.CYAN
);

I copy/paste/modified that to have labels through July. When I have Jan through Apr there are 10 Jans. When I add May there are 11 Jans. The same occurs with SPY and TSLA so it's not anything symbol-specific. I'm guessing this happens when the current month is added to the code. Next month May won't break the code but June will. It seems to be an issue with how TOS provides the rolling time period. I adjusted my expansion area but, as I expected, that had no effect.

The calculations are accurate if you consider them in the context of calendar years. In the last 10 whole calendar years plus the current partial calendar year, there have been 11 Jans and 10 Junes. If you set the chart to a fixed time range of 5/4/12 to 5/4/21 it gives you 10 Jans, 10 Mays, 9 Junes, 9 Julys.

Now that there's an explanation for this and the data is accurate, with the caveat of months in the current year that have already passed are 11 yr averages instead of 10, you could choose to live with it. Another option is to look back instead of tracking as time passes, like the code I gave you in the other thread, but the problem with that is symbols that don't have enough data for the average length won't show anything.

If you stick with this code, you might want to consider modifying to use a single label per month like I did above. That way if the labels take up too much horizontal space and end up wrapping, the values for a single month will stay together.

Thanks for looking at it. I had a feeling that something to the effect of what you're saying was taking place (the # of months that it was dividing by was off by 1 in certain instances), but then when looking at the chart and actually counting the # of months on a 5 year monthly chart for example there are an equal number of each month displayed (a 5 year chart starts with June currently and ends with May). But perhaps since the current month doesn't have a closing value yet that it throws the code off, or does it use the current days close in the calculation? I guess that may throw the average % off a bit.

But what it doesn't explain is when I am using two separate studies loaded onto the chart with the exact same code for the same month (March) and getting two completely different values on a 5 year monthly chart of Visa (V) (see screen shot below). Any thoughts?

FhA54Nm.png


I looked at your code from the other thread and may end up using that one and just adjust the code to be fixed to a 5 year chart instead of 10 and be happy with it. Do you feel like that code is more accurate? Thanks!
 

Slippage

Well-known member
or does it use the current days close in the calculation? I guess that may throw the average % off a bit.

Yes, once the market opens any time in the calendar month that monthly bar is created and has the day's open and the current price as the month's close. Your code will include that in the average. The code I posted in the other thread will not.

But what it doesn't explain is when I am using two separate studies loaded onto the chart with the exact same code for the same month (March) and getting two completely different values on a 5 year monthly chart of Visa (V) (see screen shot below). Any thoughts?

FhA54Nm.png

That one I can't explain. That seems like a bug on their end, in addition to this other weirdness probably also being a bug. You could contact customer support so they can be aware of the problem and maybe fix it some day but I wouldn't expect it to be fixed in a hurry.
 

bp805

Member
10+ years x 12 months = minimum 120 labels on the chart per stock. I doubt you're really going to want that. You should take a look at the built-in MonthlySeasonality study if you want that much data.

Like that study, for any custom solution you'll be limited to use on a monthly chart. You can't access enough data via ThinkScript for 10 years from a daily chart.

You can access the same month in a prior year by using an index of 12. For multiple years ago, multiply by twelve.

I wrote the code below for you to use as an example. It calculates the average return for each month over the last 10 years. Note, the way TOS averaging works, if there's not 10 years of data then you'll get nothing.

Again, This will only work on a monthly chart.
Ruby:
Assert(GetAggregationPeriod() == AggregationPeriod.MONTH, "The `Seasonality` study is designed for monthly charts only");

def return = close / open;
def r = Round(if return > 1 then (return - 1) * 100 else if return < 1 then (1 - return) * -100 else 1, 2);
def factor = 12;
def avg = (
  r[factor] + r[factor * 2] + r[factor * 3] + r[factor * 4] + r[factor * 5]
  + r[factor * 6] + r[factor * 7] + r[factor * 8] + r[factor * 9] + r[factor * 10]
) / 10;


# display the month-to-date return
AddLabel(yes, "MTD: " + r + "%", Color.LIGHT_GRAY);

def m = GetMonth();

# display the average return for this month
AddLabel(
  yes,
  (if m == 1 then "Jan"
    else if m == 2 then "Feb"
    else if m == 3 then "Mar"
    else if m == 4 then "Apr"
    else if m == 5 then "May"
    else if m == 6 then "Jun"
    else if m == 7 then "Jul"
    else if m == 8 then "Aug"
    else if m == 9 then "Sep"
    else if m == 10 then "Oct"
    else if m == 11 then "Nov"
    else "Dec") + ": " + Round(avg, 2) + "%",
  Color.LIGHT_GRAY
);

# display the average return for next month
AddLabel(
  yes,
  (if m[-1] == 1 then "Jan"
    else if m[-1] == 2 then "Feb"
    else if m[-1] == 3 then "Mar"
    else if m[-1] == 4 then "Apr"
    else if m[-1] == 5 then "May"
    else if m[-1] == 6 then "Jun"
    else if m[-1] == 7 then "Jul"
    else if m[-1] == 8 then "Aug"
    else if m[-1] == 9 then "Sep"
    else if m[-1] == 10 then "Oct"
    else if m[-1] == 11 then "Nov"
    else "Dec") + ": " + Round(avg[-1], 2) + "%",
  Color.LIGHT_GRAY
);
@Slippage....So I used your above code and saved two different scripts, one for 5 years worth of data and one for 10 years (as posted above). I edited the 5 year script to remove years 6-10. The script seems to always show "Dec" no matter what month it is (appears to be the case in the code).

Anyway, I manually calculated the total average for AAPL in December for 5 years and or 10 years. The 5 year average is 1.91% and the 10 year average is -1.28%, however the script returns a 5 year average of 3.31% and a 10 year average of .16%. 5 year is the light gray label and 10 year is the cyan label in below screen shot. The script shows the return for the current "MTD" accurately however (which as of today, 5/9/21) is -1.39%.

CFh3sZg.jpg


I've tried this on both 5 year and 10 year monthly charts and the label values stay constant. The script doesn't seem to be calculating correctly. Any thoughts? Thanks!
 

Slippage

Well-known member
@Slippage....So I used your above code and saved two different scripts, one for 5 years worth of data and one for 10 years (as posted above). I edited the 5 year script to remove years 6-10. The script seems to always show "Dec" no matter what month it is (appears to be the case in the code).

Anyway, I manually calculated the total average for AAPL in December for 5 years and or 10 years. The 5 year average is 1.91% and the 10 year average is -1.28%, however the script returns a 5 year average of 3.31% and a 10 year average of .16%. 5 year is the light gray label and 10 year is the cyan label in below screen shot. The script shows the return for the current "MTD" accurately however (which as of today, 5/9/21) is -1.39%.

CFh3sZg.jpg


I've tried this on both 5 year and 10 year monthly charts and the label values stay constant. The script doesn't seem to be calculating correctly. Any thoughts? Thanks!

Since the script is looking back by specifying an index, the length of time in the chart won't matter. You could set it to just show a couple of bars and it'll still pull data for the 5 or 10 years.

I should have time in the next couple of days to work on debugging this. What I'll probably do, if you decide to work on it sooner, is add labels or maybe a plot to show each of the past r values and see if they're correct for the calendar months expected. If not, then see what months it is matching and adjust as needed.
 

Slippage

Well-known member
@Slippage....So I used your above code and saved two different scripts, one for 5 years worth of data and one for 10 years (as posted above). I edited the 5 year script to remove years 6-10. The script seems to always show "Dec" no matter what month it is (appears to be the case in the code).

Anyway, I manually calculated the total average for AAPL in December for 5 years and or 10 years. The 5 year average is 1.91% and the 10 year average is -1.28%, however the script returns a 5 year average of 3.31% and a 10 year average of .16%. 5 year is the light gray label and 10 year is the cyan label in below screen shot. The script shows the return for the current "MTD" accurately however (which as of today, 5/9/21) is -1.39%.

CFh3sZg.jpg


I've tried this on both 5 year and 10 year monthly charts and the label values stay constant. The script doesn't seem to be calculating correctly. Any thoughts? Thanks!

This new code should fix that. However, in debugging I found the open and close values TOS stores may sometimes have 3 or 4 decimal places so the results may not match your manual calculation exactly but they should be very, very close.

I made it so this single study automatically switches between 5 and 10 yr depending on how much data is available and hides the labels if there's less than 5 years of data. For my own use, I'm slightly considering adding a 3 yr level and if there's not 3 yrs then just showing last year's return.

I left in my debug labels with an input to turn them on and off, defaulted to off.

Ruby:
declare hide_on_intraday;
input debug = no;

DefineGlobalColor("FirstColor", CreateColor(50,200,250));
DefineGlobalColor("SecondColor", CreateColor(50,240,200));

Assert(GetAggregationPeriod() == AggregationPeriod.MONTH,
"The `MonthlySeasonality` study is designed for monthly charts only");

def r = close / open - 1;
def up = close > open;
def factor = 12;

def avg5 = (
  r[factor] + r[factor * 2] + r[factor * 3] + r[factor * 4] + r[factor * 5]
) / 5;

def avg10 = (
  r[factor] + r[factor * 2] + r[factor * 3] + r[factor * 4] + r[factor * 5]
  + r[factor * 6] + r[factor * 7] + r[factor * 8] + r[factor * 9] + r[factor * 10]
) / 10;

def percentUp5 = (
  up[factor] + up[factor * 2] + up[factor * 3] + up[factor * 4] + up[factor * 5]
) / 5;

def percentUp10 = (
  up[factor] + up[factor * 2] + up[factor * 3] + up[factor * 4] + up[factor * 5]
  + up[factor * 6] + up[factor * 7] + up[factor * 8] + up[factor * 9] + up[factor * 10]
) / 10;

AddLabel(debug,r[factor], Color.CYAN);
AddLabel(debug,r[factor*2], Color.CYAN);
AddLabel(debug,r[factor*3], Color.CYAN);
AddLabel(debug,r[factor*4], Color.CYAN);
AddLabel(debug,r[factor*5], Color.CYAN);
AddLabel(debug,r[factor*6], Color.CYAN);
AddLabel(debug,r[factor*7], Color.CYAN);
AddLabel(debug,r[factor*8], Color.CYAN);
AddLabel(debug,r[factor*9], Color.CYAN);
AddLabel(debug,r[factor*10], Color.CYAN);

AddLabel(debug,close[factor], Color.LIGHT_GRAY);
AddLabel(debug,close[factor*2], Color.LIGHT_GRAY);
AddLabel(debug,close[factor*3], Color.LIGHT_GRAY);
AddLabel(debug,close[factor*4], Color.LIGHT_GRAY);
AddLabel(debug,close[factor*5], Color.LIGHT_GRAY);
AddLabel(debug,close[factor*6], Color.LIGHT_GRAY);
AddLabel(debug,close[factor*7], Color.LIGHT_GRAY);
AddLabel(debug,close[factor*8], Color.LIGHT_GRAY);
AddLabel(debug,close[factor*9], Color.LIGHT_GRAY);
AddLabel(debug,close[factor*10], Color.LIGHT_GRAY);

def m = GetMonth();

# display the month-to-date return
AddLabel(yes, "MTD: " + AsPercent(r), Color.LIGHT_GRAY);

# display the average return for this month
AddLabel(
  !IsNaN(avg5),
  (if m == 1 then "Jan"
    else if m == 2 then "Feb"
    else if m == 3 then "Mar"
    else if m == 4 then "Apr"
    else if m == 5 then "May"
    else if m == 6 then "Jun"
    else if m == 7 then "Jul"
    else if m == 8 then "Aug"
    else if m == 9 then "Sep"
    else if m == 10 then "Oct"
    else if m == 11 then "Nov"
    else "Dec")
    + " " + (if !isNaN(avg10) then "10" else "5") + "yr"
    + " Average: " + AsPercent(if !isNaN(avg10) then avg10 else avg5)
    + " | Up: " + AsPercent(if !isNaN(percentUp10) then percentUp10 else percentUp5)
  ,
  GlobalColor("FirstColor")
);

# display the average return for next month
AddLabel(
  !IsNaN(avg5),
  (if m[-1] == 1 then "Jan"
    else if m[-1] == 2 then "Feb"
    else if m[-1] == 3 then "Mar"
    else if m[-1] == 4 then "Apr"
    else if m[-1] == 5 then "May"
    else if m[-1] == 6 then "Jun"
    else if m[-1] == 7 then "Jul"
    else if m[-1] == 8 then "Aug"
    else if m[-1] == 9 then "Sep"
    else if m[-1] == 10 then "Oct"
    else if m[-1] == 11 then "Nov"
    else "Dec")
    + " " + (if !isNaN(avg10[-1]) then "10" else "5") + "yr"
    + " Average: " + AsPercent(if !isNaN(avg10[-1]) then avg10[-1] else avg5[-1])
    + " | Up: " + AsPercent(if !isNaN(percentUp10[-1]) then percentUp10[-1] else percentUp5[-1])
  ,
  GlobalColor("SecondColor")
);
 
Last edited:
Top