Tuesday, March 24, 2015

thinkscript include: sdi_hilo_cnt - chart label to display count of highs and lows.

think your stock is overbought and can't possibly go higher? think again. the sdi_hilo_cnt chart label counts the number of range highs and range lows on your chart and displays the count in a chart label. here's the picture:
aapl with sdi_hilo_cnt label
the chart label is saying that aapl pushed up new 1-year highs 56 times on this one year chart. the '252' is the number of bars in the lookback range and defaults to the number of trading days in a year. also note that aapl did not carve any new lows. this means that the chart low (not shown) is a number that aged into that designation. (and, yes, you can select the color for the label.)

here's the code:


#############################
# sdi_hilo_cnt
#hint: displays a count of new highs and new lows in a chart label rev:1.0.0 http://www.smallDogInvestor.com 
input length=252;
# author: allen everhart
# date: 24Mar2015
# Copyleft! This is free software. That means you are free
# to use or modify it for your own usage but not for resale. 
# Help me get the word out about my blog by keeping this header
# in place. 
#hint length: number of bars in comparison range. rev:1.0.0 http://www.smallDogInvestor.com 
def isHigh= high>highest(high,length)[1];
def isLow= low<lowest(low,length)[1];
plot labelColor=double.NaN;
labelColor.setHiding(1);
labelColor.hideBubble();
labelColor.hideTitle();
labelColor.setDefaultColor(color.BLUE);
addLabel(1, 
    concat( "(",
    concat( length,
    concat( ") highs:",
    concat( Sum(isHigh,length),
    concat( " lows:",
    totalSum(isLow)))))),  
    labelColor.takeValueColor());
###############################


No comments:

Post a Comment