Monday, August 29, 2011

sdi_hivol - decorate volume moving average when volume exceeds threshold percent

One of the indicators that is used in the InvesTools method is volume moving average. In particular, a significant trading opportunity may be indicated when volume exceeds the volume moving average by 50%. Sometimes this is easy to eyeball, other times it is a close call for which you will need to do the math. In the spirit of keeping things simple I have created a study that decorates the volume moving average with triangles when the volume exceeds the percentage threshold. Here's the image and code:


SPY with sdi_hivol indicating volume days exceeding 50% above volume moving average.
#############################
# sdi_hivol
#hint: Decorates the volume moving average with triangles when the volume exceeds a specified threshold percent.
# source: smallDogInvestor.blogspot.com
# author: allen everhart
# date: 29Aug2011
# Copyleft! 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 type: Type of the volume moving average: simple or exponential
input type = { default SMP, EXP } ;
#hint length: Number of bars to use for volume moving average.
input length = 20 ;
#hint hotPct: Percent over volume moving average to trigger decorations.
input hotPct = 50.0 ;


def ma =
  if type == type.SMP then
    simpleMovingAvg(Volume, length)
  else
    movAvgExponential(vOlume, length)
;


plot hv =
  if 100 * ((volume / ma) - 1) >= hotPct then
    ma
  else
    double.NaN
;


hv.SetDefaultColor( color.CYAN);
hv.SetLineWeight(1) ;
hv.setPaintingStrategy( PaintingStrategy.LINE_VS_TRIANGLES);


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


1 comment:

  1. I must say this is a great article i enjoyed reading it keep the good work.

    http://www.pennystockshark.com/

    ReplyDelete