Volume Power Flow - Taylor V1
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TaylorTneh

//@version=4
study(title="Volume Power Flow", shorttitle="Flow Vol", format=format.volume, resolution="")

//------------------------------------------------------------------------------------------------------- Volume Power Flow
vflow = input(title="Volume Power Flow", defval=true)
maType = input(title="VPF Average Type", options=["RMA", "Single EMA", "Double EMA"], defval="RMA")
length = input(13, title="VPF Average Length : 8/13")
x = 3.1
vpfred   = color.red 
vpfgreen = color.green 
// Basic Volume Calcs //
vol  =  volume
bull =  close>open?vol:0 
bear =  open>close?vol:0
// Double EMA Function //
dema(src, len) => (2 * ema(src, len) - ema(ema(src, len), len))
// BEAR Moving Average Calculation
bullma = maType == "Single EMA" ?        ema(bull, length) :
         maType == "Double EMA" ? dema(bull, length) :
         rma(bull, length)
// BEAR Moving Average Calculation //
bearma = maType == "Single EMA" ?        ema(bear, length) :
         maType == "Double EMA" ? dema(bear, length) :
         rma(bear, length)
// ma dif //
vf_dif = bullma-bearma
vf_absolute = vf_dif > 0 ? vf_dif : vf_dif * (-1)
// Volume Spikes //
gsig=crossover(bull, bullma*x)?vol:na
rsig=crossover(bear, bearma*x)?vol:na
// Color Calcs //
vdClr = vf_dif > 0 ? vpfgreen : vpfred
vClr=close>open? vpfgreen:vpfred
// Plots //
vflowplot = vflow ? vf_absolute/2.5 : na
plot(vflowplot, style=plot.style_area, color=vdClr, title="Volume Power Flow")
