Monday, November 4, 2013

thinkScript: Custom Quote - Daily/Weekly/Monthly Gain or Loss

Updated 11/04/13

Instructions for using this code can be found here: TOS Tip: Custom Quotes

Daily Price change 1 trading day ago:

#####begin custom quote: -Day 1
#
# Shows gain or loss 1 trading day ago for an equity or index.
# GREEN = Gain, RED = Loss.
# Use to customize a column in MarketWatch Quotes or Stock Hacker Scans.
# Paste this code into 1 of the 19 custom fields.
#
# by John Latrobe
# revised 11/04/13
#
DEF price = FundamentalType.CLOSE;
DEF priceday = Fundamental(price, Period = AggregationPeriod.DAY);
#
PLOT pricechg = priceday[1] - priceday[2];
AssignBackgroundColor(if pricechg > 0 then Color.DARK_GREEN else if pricechg < 0 then Color.DARK_RED else Color.CURRENT);
pricechg.AssignValueColor(Color.WHITE);
#
#####end custom quote.

Daily Price change 2 trading days ago:

#####begin custom quote: -Day 2
#
# Shows gain or loss 2 trading days ago for an equity or index.
# GREEN = Gain, RED = Loss.
# Use to customize a column in MarketWatch Quotes or Stock Hacker Scans.
# Paste this code into 1 of the 19 custom fields.
#
# by John Latrobe
# revised 11/04/13
#
DEF price = FundamentalType.CLOSE;
DEF priceday = Fundamental(price, Period = AggregationPeriod.DAY);
#
PLOT pricechg = priceday[2] - priceday[3];
AssignBackgroundColor(if pricechg > 0 then Color.DARK_GREEN else if pricechg < 0 then Color.DARK_RED else Color.CURRENT);
pricechg.AssignValueColor(Color.WHITE);
#
#####end custom quote.

Daily Price change 3 trading days ago:

#####begin custom quote: -Day 3
#
# Shows gain or loss 3 trading days ago for an equity or index.
# GREEN = Gain, RED = Loss.
# Use to customize a column in MarketWatch Quotes or Stock Hacker Scans.
# Paste this code into 1 of the 19 custom fields.
#
# by John Latrobe
# revised 11/04/13
#
DEF price = FundamentalType.CLOSE;
DEF priceday = Fundamental(price, Period = AggregationPeriod.DAY);
#
PLOT pricechg = priceday[3] - priceday[4];
AssignBackgroundColor(if pricechg > 0 then Color.DARK_GREEN else if pricechg < 0 then Color.DARK_RED else Color.CURRENT);
pricechg.AssignValueColor(Color.WHITE);
#
#####end custom quote.

Daily Price change 4 trading days ago:

#####begin custom quote: -Day 4
#
# Shows gain or loss 4 trading days ago for an equity or index.
# GREEN = Gain, RED = Loss.
# Use to customize a column in MarketWatch Quotes or Stock Hacker Scans.
# Paste this code into 1 of the 19 custom fields.
#
# by John Latrobe
# revised 11/04/13
#
DEF price = FundamentalType.CLOSE;
DEF priceday = Fundamental(price, Period = AggregationPeriod.DAY);
#
PLOT pricechg = priceday[4] - priceday[5];
AssignBackgroundColor(if pricechg > 0 then Color.DARK_GREEN else if pricechg < 0 then Color.DARK_RED else Color.CURRENT);
pricechg.AssignValueColor(Color.WHITE);
#
#####end custom quote.

Daily Price change 5 trading days (1 week) ago:

#####begin custom quote: -Day 5
#
# Shows gain or loss 5 trading days ago for an equity or index.
# GREEN = Gain, RED = Loss.
# Use to customize a column in MarketWatch Quotes or Stock Hacker Scans.
# Paste this code into 1 of the 19 custom fields.
#
# by John Latrobe
# revised 11/04/13
#
DEF price = FundamentalType.CLOSE;
DEF priceday = Fundamental(price, Period = AggregationPeriod.DAY);
#
PLOT pricechg = priceday[5] - priceday[6];
AssignBackgroundColor(if pricechg > 0 then Color.DARK_GREEN else if pricechg < 0 then Color.DARK_RED else Color.CURRENT);
pricechg.AssignValueColor(Color.WHITE);
#
#####end custom quote.

Weekly Price change for past week (last 5 trading days):

#####begin custom quote: -Wk 1
#
# Shows gain or loss last 5 trading days for an equity or index.
# GREEN = Gain, RED = Loss.
# Use to customize a column in MarketWatch Quotes or Stock Hacker Scans.
# Paste this code into 1 of the 19 custom fields.
#
# by John Latrobe
# revised 11/04/13
#
DEF price = FundamentalType.CLOSE;
DEF priceday = Fundamental(price, Period = AggregationPeriod.DAY);
#
PLOT pricechg = priceday[1] - priceday[6];
AssignBackgroundColor(if pricechg > 0 then Color.DARK_GREEN else if pricechg < 0 then Color.DARK_RED else Color.CURRENT);
pricechg.AssignValueColor(Color.YELLOW);
#
#####end custom quote.

Weekly Price change 2 weeks ago (trading days -10 thru -6):

#####begin custom quote: -Wk 2
#
# Shows gain or loss for week ending 6 trading days ago (days -10 thru -6) for an equity or index.
# GREEN = Gain, RED = Loss.
# Use to customize a column in MarketWatch Quotes or Stock Hacker Scans.
# Paste this code into 1 of the 19 custom fields.
#
# by John Latrobe
# revised 11/04/13
#
DEF price = FundamentalType.CLOSE;
DEF priceday = Fundamental(price, Period = AggregationPeriod.DAY);
#
PLOT pricechg = priceday[6] - priceday[11];
AssignBackgroundColor(if pricechg > 0 then Color.DARK_GREEN else if pricechg < 0 then Color.DARK_RED else Color.CURRENT);
pricechg.AssignValueColor(Color.YELLOW);
#
#####end custom quote.

Weekly Price change 3 weeks ago (trading days -15 thru -11):

#####begin custom quote: -Wk 3
#
# Shows gain or loss for week ending 11 trading days ago (days -15 thru -11) for an equity or index.
# GREEN = Gain, RED = Loss.
# Use to customize a column in MarketWatch Quotes or Stock Hacker Scans.
# Paste this code into 1 of the 19 custom fields.
#
# by John Latrobe
# revised 11/04/13
#
DEF price = FundamentalType.CLOSE;
DEF priceday = Fundamental(price, Period = AggregationPeriod.DAY);
#
PLOT pricechg = priceday[11] - priceday[16];
AssignBackgroundColor(if pricechg > 0 then Color.DARK_GREEN else if pricechg < 0 then Color.DARK_RED else Color.CURRENT);
pricechg.AssignValueColor(Color.YELLOW);
#
#####end custom quote.

Weekly Price change 4 weeks ago (trading days -20 thru -16):

#####begin custom quote: -Wk 4
#
# Shows gain or loss for week ending 16 trading days ago (days -20 thru -16) for an equity or index.
# GREEN = Gain, RED = Loss.
# Use to customize a column in MarketWatch Quotes or Stock Hacker Scans.
# Paste this code into 1 of the 19 custom fields.
#
# by John Latrobe
# revised 11/04/13
#
DEF price = FundamentalType.CLOSE;
DEF priceday = Fundamental(price, Period = AggregationPeriod.DAY);
#
PLOT pricechg = priceday[16] - priceday[21];
AssignBackgroundColor(if pricechg > 0 then Color.DARK_GREEN else if pricechg < 0 then Color.DARK_RED else Color.CURRENT);
pricechg.AssignValueColor(Color.YELLOW);
#
#####end custom quote.

Monthly Price change for past month (last 21 trading days):

#####begin custom quote: -Mo 1
#
# Shows gain or loss for past month (trading days -21 thru -1) for an equity or index.
# -Mo 2 would use trading days -42 thru -22, etc.
# GREEN = Gain, RED = Loss.
# Use to customize a column in MarketWatch Quotes or Stock Hacker Scans.
# Paste this code into 1 of the 19 custom fields.
#
# by John Latrobe
# revised 11/04/13
#
DEF price = FundamentalType.CLOSE;
DEF priceday = Fundamental(price, Period = AggregationPeriod.DAY);
#
PLOT pricechg = priceday[1] - priceday[22];
AssignBackgroundColor(if pricechg > 0 then Color.DARK_GREEN else if pricechg < 0 then Color.DARK_RED else Color.CURRENT);
pricechg.AssignValueColor(Color.WHITE);
#
#####end custom quote.

No comments:

Post a Comment