Volume Variation Index Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © thequantscience

//@version=5
indicator("VolumeVariationIndex", overlay = false)

//-----------VolumeVariationIndex--------------{
//Measures the change in trading volume.
//Green columns indicate increasing volume trades. 
//Red columns indicate decreasing volume trades.
//You can check the average of the variations.
//You can active volume variation avarage from UI.
//You can setting avarage variation period from UI.
//---------}

// Calculate volume var
VolumeVariation = volume[1] - volume

GreenVolume = if VolumeVariation > 0
    VolumeVariation
else
    0

RedVolume = if VolumeVariation < 0
    VolumeVariation
else
    0

plot(GreenVolume, title = "VolumeIncrease", style = plot.style_columns, color = color.green)
plot(RedVolume, title = "VolumeDecrease", style = plot.style_columns, color = color.red)

// Calculate volume var avarage
ActiveAvarage = input.string("NO", title="ActiveAvarageVariation", 
     options=["NO", "YES"]) == "YES"

AvaragePeriod = input(10)
AvarageVolumeVariation = ta.sma(VolumeVariation, AvaragePeriod)

Avarage = if AvarageVolumeVariation and ActiveAvarage 
    AvarageVolumeVariation
else
    0

plot(Avarage, color = color.blue)



