Friday, March 14, 2014

thinkscript included: sdi_overunder - chart label to display count of closes over/under previous high/low, resp.

a few weeks ago i blogged about the superbowl betting business. in the course of researching spread-bets i discovered that bookies offer another kind of bet called over-under. in the over-under wager you are betting on the whether the combined total scores of the two teams is over or under a number of your choosing. this is a bet on whether or not you feel the offense of both teams is stronger than the defenses, since defense does not generally score points (super bowl xlviii opening play aside!)

this over-under got me to thinking about a similar battle i see playing out on my charts between bulls and bears. what i see my fellow traders eyeballing on charts for trading opportunities is whether or not the current closing price of a stock is above the high or below the low of the previous bar. so i started thinking of the close-above-the-high as an over and the close-below-the-low as an under. then, just to get the feel of these things, i wrote a script that tracks how many of each of these have occurred recently and displays them on a chart label. here's how this looks:
spy with sdi_overunder chart label with 20 bar lookback.
what i observe is that these over/under counts are at least as good at evaluating the technical mood of the market as other professional studies and are an interesting confimation that is independent of moving averages. so when over is twice or more the under count then the market is generally bullish over the lookback period and vice-versa.

in addition, the total of over and under is an indication of the trend strength and/or volatility. if the total is less than half of the lookback period, as is the case above, then the majority of the trading days have been somewhat indecisive. this seems to indicate a weakening bullish trend in the above chart, which i think is a reasonable assessment of the current market.

maybe this is just a curiosity, i dunno. in any case here's the thinkscript so you can decide:

################################
# sdi_overUnder: Display count of closes-above-previous-bar-high (over) and count of closes-below-previous-bar-low (under) in a chart label.
#hint: Display count of closes-above-previous-bar-high (over) and count of closes-below-previous-bar-low (under) in a chart label. Chart label is color-coded to reflect bullish/neutral/bearish condition. rev: 1.0
http://www.smallDogInvestor.com
# author: allen everhart
# date: 14mar14

# 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.

input lookBackPeriod = 20 ;
#hint lookBackPeriod: Number of bars to evaluate. rev: 1.0
http://www.smallDogInvestor.com
def over = fold ih=0 to lookBackPeriod  with nh=0 do
    if getvalue(close,ih)> getvalue(high,ih+1) then nh+1
    else nh;

def under = fold ilo=0 to lookBackPeriod  with nlo=0 do
    if getvalue(close,ilo)< getvalue(low,ilo+1) then nlo+1
    else nlo;
plot colorChooser = double.NaN;
colorChooser.hideTitle();
colorChooser.hideBubble();
colorChooser.defineColor("Bullish", color.dark_gREEN);
colorChooser.defineColor("Neutral", color.DARK_ORANGE);
colorChooser.defineColor("Bearish", color.RED);
AddLabel(1,
  Concat(Concat(Concat("over:", over), " under:"), under),
  if ( over > under ) then colorchooser.color("Bullish")
  else if ( over == under) then colorchooser.color("Neutral")
  else Colorchooser.color("Bearish")
  );

##############################

No comments:

Post a Comment