pequet

Volume Impetus Index (VI%)

Remove from Favorite Scripts Add to Favorite Scripts
// Created by @pequet (https://www.tradingview.com/u/pequet) April 4 2016 
// Inspired by a concept by @CRInvestor (http://www.therationalinvestor.co)
// https://github.com/pequet/the-vix
// MIT License
// @version=2
// 
// This Index is related to my Volume Impetus Indicator (The VIMP) available here: 
// https://www.tradingview.com/u/pequet/#published-scripts
// 
// The Volume Impetus Index (VI%) is simply the bullish percentage of the running 
// total of the past bullish and bearish volumes. An exponential moving average is 
// then calculated, because everybody loves exponential moving averages.  
// 
// The sample length, normal or weighted average, EMA length, upper and lower 
// bands are all adjustable.  
//
// As a visual clue the background colour of the indicator represents the relative 
// positions of the VI% in relation to its moving average, and of the moving 
// average relative to the "50%" point (also adjustable).
//

study(title="Volume Impetus Index (VI%)", shorttitle="VI% v1.0") 

// 1. Indicator 
// inputs
vixSampleLength = input(14, title="Sample Length", minval=1)
vixWeighted = input(true, title="Weighted Average") 
vixEMALength = input(21, title="EMA", minval=1)
vixLowerBand = input(0.2, type=float, title="Lower Band", minval=0, maxval=1)
vixMiddleBand = input(0.5, type=float, title="Middle Band", minval=0, maxval=1)
vixUpperBand = input(0.8, type=float, title="Upper Band", minval=0, maxval=1)
// our two protagonists
vimpBullVolume = iff(close > open, volume, na) 
vimpBearVolume = iff(close < open, volume, na)  
// for confirmations we need to fill in the n/a values with the trailing volume
vixBullVolumeFill = iff(vimpBullVolume, vimpBullVolume, vixBullVolumeFill[1])
vixBearVolumeFill = iff(vimpBearVolume, vimpBearVolume, vixBearVolumeFill[1])
// add the volumes 
vixBullsTotal = 0, vixBearsTotal = 0, vixMultiplierTotal = 0
for i = 1 to vixSampleLength  
    multiplier = 1 + iff(vixWeighted, vixSampleLength-i, 0) 
    vixBullsTotal := nz(vixBullsTotal + multiplier * nz(vimpBullVolume[vixSampleLength-i]))  
    vixBearsTotal := nz(vixBearsTotal + multiplier * nz(vimpBearVolume[vixSampleLength-i]))  
    vixMultiplierTotal := vixMultiplierTotal + multiplier
vixBullsTotal := vixBullsTotal / vixMultiplierTotal
vixBearsTotal := vixBearsTotal / vixMultiplierTotal
// if there is no volume at all we repeat the previous bar value 
vix = iff(vixBullsTotal+vixBearsTotal>0, vixBullsTotal/(vixBullsTotal+vixBearsTotal), vix[1])
vixPlotObj = plot(vix, style=line, color=#999999, transp=0, linewidth=1, title="VI%") 
// ema 
vixEMA = ema(vix, vixEMALength)
vixEMAPlotObj = plot(vixEMA, color=#ff0000, transp=10, linewidth=2, title="VI% EMA")  
// bands
hLower = hline(vixLowerBand, title="Lower Band")
hMiddle = hline(vixMiddleBand, title="Middle Band")
hUpper = hline(vixUpperBand, title="Upper Band")

// 2. Conditions 
// vix above ema
vixOnTop = vix > vixEMA
// bull market
vixEMABull = vixEMA > vixMiddleBand

// 3. Background 
bgcolor(color=vixEMABull ? vixOnTop ? lime : yellow : vixOnTop ? orange: red, transp=80, offset=0, title="VI%/EMA/50%")

// stay tuned for more
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out