Sunday, August 21, 2011

sdi_yesterClose - Display Yesterday's Closing Price On Today's Intraday Chart

If you are an intraday trader then you know it is vitally important to be vigilent about yesterday's closing price because it is often the case that this is where price movement is challenged. The sdi_yesterClose study will help you stay vigilent by plotting yesterday's closing price on your intraday chart. Also, it has the hooks to display the previous close of a variety of aggregation periods such as last week or month. As an added convenience, you may set it to display only in the right extension area (sideline.)  Moreover, this study will hide if you increase your chart's aggregation period up to a level where it does not make sense to display (e.g. you change from intraday to daily.)  Here's an image of the study followed by source code:


SPX intraday plot with yesterday's closing price.

############################################
# sdi_yesterClose: Display A Previous Closing Price
#hint: Displays yesterday's closing price. rev 1.2.2 http://www.smallDogInvestor.com
# author: allen everhart
# date: 21AUG2011
# rev:
#   1.2.2 13jul2013- corrected incompatibility with new tos.
#   1.2.1 8sep2011- refactor sidebar to sideline
#   1.2 21aug2011- was not extending value to right on sideline
#   1.1 21AUG2011- fixed bug with 2 DAYS, 3 DAYS selections
# 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.
declare upper ;
#hint yesterPeriod: The aggregation period from which to select the previous closing price. When you adjust the chart aggregation period equal to or greater than yesterPeriod then the yesterClose will automatically hide.  
input yesterPeriod = aggregationPeriod.DAY;
#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 prox = proximity;
plot yc =
  if !sideline && IsNaN(close) then
    double.NaN
  else if sideline && !isnaN(close) then
    double.NaN
  else
    close(period = yesterPeriod)[1] ;

def agHide =  if getAggregationPeriod() >= yesterPeriod then
   yes
 else
   no
;

def hidePc =   if agHide then
    yes
  else
    no
;
yc.setHiding( hidePc );
yc.SetStyle(curve.POINTS);
yc.setDefaultColor(color.RED);

#

No comments:

Post a Comment