Wednesday, August 31, 2011

sdi_openrange - display the open range on an intraday chart

The range exhibited during the cash-market opening is important to some intraday traders. Very often the high and low of the opening range are reversal levels. The sdi_openrange study will help you stay vigilant about these levels by displaying the opening range overlaying the main chart or on the sidebar. Also, this intraday study is smart enough to know when to get out of the way - if you reset your aggregation size (the duration of each chart bar) larger than the opening period sdi_openrange will hide so you don't have to fiddle with the chart settings to get a clean chart. Enabling the sideline parameter will throw the range cloud over to the right-extension area where it won't interfere with your chart drawings.

Here's the image and code:

SPX with sdi_openrange.
#########################
# sdi_openrange
#hint: Show the high and low range of the opening period. Rev:1.0.1
#rev 1.0.1 8sep2011 - refactor sidebar to sideline
# source: smalldoginvestor.blogspot.com
# author: allen everhart
# date: 31Aug2011
# 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 openMinutes: The duration of the opening period.
input openMinutes = 30 ;
#hint displayMinutes: Determines the number of bars to extend the open range cloud when displayed overlaying the main chart.
input displayMinutes = 120 ;
#hint sideline: Yes to display the open range on the right-extension area.
input sideline = no;

def minPerAg = getAggregationPeriod() / aggregationPeriod.MIN;
def elapseSecs = secondsFromTime(openTime);
rec startHi =
  if elapseSecs == 0 then
    high
  else if between(elapseSecs, 0, (openMinutes * 60) - 1) then
    Max(high, startHi[1])
  else
    startHi[1]
;
rec startLo =
  if elapseSecs == 0 then
    low
  else if between(elapseSecs, 1, (openMinutes * 60) - 1) && startLo[1] == 0 then #rev2
    low  #rev2
  else if between(elapseSecs, 0, (openMinutes * 60) - 1) then
    Min(low, startLo[1])
  else
    startLo[1]
;
plot sh =
  if !sideline && between(elapseSecs, 0, (openMinutes + displayMinutes) * 60)  then
    startHi
  else if sideline && isnaN(close) then
    startHi
  else
    double.NaN
;
plot sl =
  if !sideline && between(elapseSecs, 0, (openMinutes + displayMinutes) * 60)  then
    startLo
  else if sideline && isnaN(close) then
    startLo
  else
    double.NaN
;
sh.SetDefaultColor(color.YELLOW);
sl.SetDefaultColor(color.YELLOW);
def aghide =
  if getAggregationPeriod() > openMinutes * aggregationPeriod.MIN then
    yes
  else
    no
;
sl.setHiding(aghide);
sh.setHiding(aghide);
AddCloud( sl, sh, color.YELLOW,color.YELLOW);
#################################

No comments:

Post a Comment