Friday, August 26, 2011

sdi_open - display open price level of cash market

The sdi_open study displays the open price level of the "cash market" on an intraday chart.  For those of you who do not trade products like futures and currency spots, this distinction may seem a little odd. Futures and spots typically have an official opening time in the early evening hours, US Eastern time, which is not usually a time that creates a price level that you want to watch intraday. Rather, you are more interested in the print created when the US or European stock (or cash) markets open. In any case, sdi_open allows you to specify the open time that is of interest to you, in your locality, but it defaults to 9:30, the open of the US cash market, Eastern US time. As with many of these intraday price level studies that I write, sdi_open can be configured to show the level in the right-extension area by enabling the sideline parameter. Also, the sdi_open level will hide when the aggregation period of the chart is set to DAY or larger. Here is the image and code:


SPX with sdi_open price for 9:30 bar.
#########################
# sdi_open
#hint: Shows the opening price as a dotted price level on an intraday chart. rev:1.0.1
#rev 1.0.1 8sep2011 refactored sidebar to sideline
# source: smallDogInvestor.blogspot.com
# author: allen everhart
# date: 27Aug2011
# 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 openTime: Time of the cash market open in your locality. Format:HHMM.
input openTime = 0930 ;
#hint sideline: Yes to show open price level in right extension area. No to show open price level overlaying main chart. 
input sideline = no;

def elapseSecs = secondsFromTime(openTime);
def aggSecs = getAggregationPeriod()/1000;

rec openPrice =
  if elapseSecs<0 && -elapseSecs < aggsecs  then
    open
  else if elapseSecs == 0 then
    open
  else
    openPrice[1]
;
#plot es = elapseSecs ;

def agHide =  if getAggregationPeriod() >= aggregationPeriod.DAY then
    yes
 else
   no
;

plot op =
  if sideline && !IsNaN(close) then
    double.NaN
  else if !sideline && isnaN(close) then
    double.NaN
  else if openprice == 0 then
    double.NaN
  else
    openPrice ;


Op.SetStyle(curve.POINTS);
op.setDefaultColor(color.dARK_ORANGE);
op.setHiding(aghide);

No comments:

Post a Comment