Net change compared to 1 week ago, 1 month ago, etc.

jphalip

New member
Hi,

TOS watchlists have the "Net Chng" default column that shows the percent change since open (or close from the previous day, I'm not sure).

Now, I'd like to add similar columns that show the net change of the current price compared to 1 week ago, 1 month ago, or any arbitrary number of days.

What code would you recommend using to create such custom quotes?

Thanks!

Julien
 

SleepyZ

Well-known member
Hi,

TOS watchlists have the "Net Chng" default column that shows the percent change since open (or close from the previous day, I'm not sure).

Now, I'd like to add similar columns that show the net change of the current price compared to 1 week ago, 1 month ago, or any arbitrary number of days.

What code would you recommend using to create such custom quotes?

Thanks!

Julien

See if the helps. Use this to develop separate watchlist columns. The debug label will allow you to ensure that the proper values are being used.

Code:
#For watchlist columns, set to Day (D)
def ye = if GetYear() != GetLastYear() then close else ye[1];
def we = if GetWeek() != GetLastWeek() then close else we[1];
input num_days_ago = 1;
def de = if GetDay() == GetLastDay() - num_days_ago then close else de[1];

AddLabel(1, "Y: " + AsPercent((close - ye) / ye), if (close - ye) > 0 then Color.GREEN else Color.RED);
AddLabel(1, "W: " + AsPercent((close - we) / we), if (close - we) > 0 then Color.GREEN else Color.RED);
AddLabel(1, num_days_ago + "D: " + AsPercent((close - de) / de), if (close - de) > 0 then Color.GREEN else Color.RED);


input debug = yes;
AddLabel(debug, "Closes - Today : " + close + ";  Year: " + ye + ";  Week: " + we + " ;  " + num_days_ago + " Days Ago: " + de, Color.WHITE);
 

jphalip

New member
Excellent! I ended up using the following code based on your suggestion:

Code:
input num_days_ago = 5;
def old_price = if GetDay() == GetLastDay() - num_days_ago then close else close[num_days_ago];
def percent = 100 * (close - old_price) / old_price;
AddLabel(1, Round(percent, 2), if percent > 0 then Color.GREEN else Color.RED);

(Changing the value of "num_days_ago" for each column / custom quote)

Thanks a lot!
 

JJJJJJ11111

New member
Excellent! I ended up using the following code based on your suggestion:

Code:
input num_days_ago = 5;
def old_price = if GetDay() == GetLastDay() - num_days_ago then close else close[num_days_ago];
def percent = 100 * (close - old_price) / old_price;
AddLabel(1, Round(percent, 2), if percent > 0 then Color.GREEN else Color.RED);

(Changing the value of "num_days_ago" for each column / custom quote)

Thanks a lot!
hi thanks for sharing.. i have an issue with this code.
I tried sort it in order, but the sorting were not correct
 

SleepyZ

Well-known member
Labels w
hi thanks for sharing.. i have an issue with this code.
I tried sort it in order, but the sorting were not correct
Labels will not sort properly. Plots are better, See if this mod to that code helps

Code:
input num_days_ago = 5;
def old_price = if GetDay() == GetLastDay() - num_days_ago then close else close[num_days_ago];
plot percent = 100 * (close - old_price) / old_price;
percent.setdefaultColor(color.black);
assignbackgroundColor(if percent>0 then color.light_green else color.light_red);
 
Last edited:

JJJJJJ11111

New member
Labels w

Labels will not sort properly. Plots are better, See if this mod to that code helps

Code:
input num_days_ago = 5;
def old_price = if GetDay() == GetLastDay() - num_days_ago then close else close[num_days_ago];
plot percent = 100 * (close - old_price) / old_price;
percent.setdefaultColor(color.black);
assignbackgroundColor(if percent>0 then color.light_green else color.light_red);
works out well.
thank u
 

Similar threads

Top