Monday, August 22, 2011

sdi_yearClose - Display Last Year's Closing Price

This study is an off-shoot of my study sdi_yesterClose. It started as an enhancement to yesterClose but, due to limitations in ThinkScript (no support for the aggregation period: YEAR), it was just cleaner and easier to put this out as its own study. Like many of my scripts you can choose whether you want to see the level overlaying the main chart or on the right-extension area via the sideline parameter. Here's the image and code:

SPX with sdi_yearClose study.
############################################
# sdi_yearClose: Display Last Year's Closing Price
#hint: Displays last year's closing price. rev 1.0.2 http://www.smallDogInvestor.com
# author: allen everhart
# date: 21AUG2011
# rev:1.0.2 15july2013 corrected incompatibility with a tos update that produced a java stack overflow.
# rev:1.0.1 8sep2011 refactored sidebar to sideline
# copylefts reserved. 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 sideline: Where to show the yesterClose. If yes then yesterClose only displays in the right extension area of the chart otherwise yesterClose displays in the regular chart area.
input sideline = no;

plot yr =
  if isNaN(close) && !sideline then
    double.NaN
  else if !isNaN(close) && sideline then
    double.Nan
  else
    getvalue( close( period=aggregationPeriod.MONTH), getMonth())
  ;

yr.setDefaultColor(color.BLUE);
yr.setStyle(curve.POINTS);
##########


No comments:

Post a Comment