Monday, November 25, 2013

thinkscript_included: sdi_ivpls - the popular iv rank (aka percentile) as a lower study

following on the succes of the popular iv rank, or percentile as it was originally called, there have been requests to show the graph of the indicator. simple enough, so here's the image of this new lower study called sdi_ivpls:


and here's the code:


################################
# sdi_ivpls: Display Implied Volatility Percentile as a lower study
#hint: Displays the Implied Volatility Percentile as a chart lower study. sdi_ivpls rev: 1.0 http://www.smallDogInvestor.com
# author: allen everhart
# date: 11/25/2013
# 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 lower;
input period = AggregationPeriod.DAY ;
#hint period: time period to use for aggregating implied volatility. sdi_ivpls rev: 1.0 http://www.smallDogInvestor.com
input length =252 ;
#hint length: #bars to use in implied volatility calculation.
def ivGapHi = if isnan(imp_volatility(period=period)) then 99999999999 else imp_volatility(period=period);
def ivGapLo = if isnan(imp_volatility(period=period)) then -99999999999 else imp_volatility(period=period);
def periodHigh = highest( ivGapLo,length=length);
def periodLow = lowest( ivGapHi, length=length);
def ivRange = periodHigh - periodLow ;
def ivp = round( 100*(imp_volatility(period=period) - periodLow)/ivRange, 0);
#plot labelColor = 0; # only to pull in color select widget
#labelColor.setHiding(1) ; #never want to show this
#labelColor.hideBubble();
#labelColor.hideTitle();
#labelColor.setDefaultColor(color.PLUM);
#AddLabel(1, Concat("IV%: ", ivp), labelColor.takeValueColor() );
plot ivpr=ivp;
ivpr.setDefaultColor(color.PLUM);
####################################

No comments:

Post a Comment