Sunday, October 27, 2013

thinkScript: Price Percent chart label

A useful indicator or strength or weakness in an equity is when the price moves up or down 10% in 2 weeks. For indexes this change is 5%.


This Chart label compares the current price with the high and low for the past specified period (default is 2 weeks) and displays the maximum price change. When the default threshold of +/- 5% is reached the label will turn red for a loss and green for a gain.


####begin study: TT_PricePercent
#
# Hint: From TastyTrade. Takes the high and low close for the specified period and compares to the current. The greater change is displayed as a percentage in a label.
#
# length is # of trading days. 10 = 2 weeks.
input length = 10;
input price = FundamentalType.CLOSE;
input pricePercentUP = 5.0;
input pricePercentDOWN = -5.0;
#
def priceday = Fundamental(price, period = aggregationPeriod.DAY);
def high = Highest(priceday[1], length);
def low = Lowest(priceday[1], length);
def PcntChHigh = 100 * (priceday/high -1);
def PcntChLow = 100 * (priceday/low -1);
def PercentChg = if(AbsValue(PcntChHigh) >= AbsValue(PcntChLow), Round(PcntChHigh, 2), Round(PcntChlow, 2));
#
AddLabel(1, Concat ("% Chng: ", PercentChg),if percentChg >= pricePercentUP then color.DARK_GREEN else if percentChg <= pricePercentDOWN then color.RED else color.GRAY);
#
#####end study.

No comments:

Post a Comment