Bogdan Ciocoiu - Greuceanu
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BogdanCiocoiu

//@version=5
indicator("Bogdan Ciocoiu - Greuceanu", shorttitle="BC - Greuceanu", format=format.price, precision=2, timeframe="", timeframe_gaps=true, explicit_plot_zorder=true)

// Description
// This indicator is an entry-level script that simplifies volume interpretation for beginning traders. 
// It is a handy tool that removes all the noise and focuses traders on identifying potential smart money injections.

// Uniqueness
// This indicator is unique because it introduces the principle of a moving average in the context of volume and then compares it with tick-based volume.
// Its uniqueness is reflected in the ability to colour code each volume bar based on the intensity of each relevant (volume) unit whilst comparing it with the volume moving average.
// Another benefit of this indicator is the colour coding scheme that removes volume below a particular threshold (default set to 1) under the volume moving average.
// In addition to the above features, the indicator differentiates the colour of each bar by price direction.

// Open source re-use
// To achieve this functionality several open source indicators have been used an integrated within the current one.
// https://www.tradingview.com/script/PpjPs450-Neglected-Volume-by-DGT/
// https://www.tradingview.com/script/s4xadZFc/


// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Volume MA
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------

_vol_MA_len_1 = input(20, 'Volume MA 1', inline='Volume MA', group='Volume MA')

_vol_MA_1  = 0.0
_vol_MA_1 := nz(_vol_MA_1[1]) + (volume-nz(_vol_MA_1[1])) / _vol_MA_len_1

_vol_ratio_1 = volume/_vol_MA_1

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Volume histogram
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------

_vol_pos_strong = input(color.new(color.green, 0), '', inline='Volume positive', group='Volume colors (pos/neg v strong/weak/others)')
_vol_pos_weak = input(color.new(color.silver, 90), '', inline='Volume positive', group='Volume colors (pos/neg v strong/weak/others)')
_vol_pos_others = input(color.new(color.green, 80), '', inline='Volume positive', group='Volume colors (pos/neg v strong/weak/others)')

_vol_neg_strong = input(color.new(color.red, 0), '', inline='Volume positive', group='Volume colors (pos/neg v strong/weak/others)')
_vol_neg_weak = input(color.new(color.silver, 90), '', inline='Volume positive', group='Volume colors (pos/neg v strong/weak/others)')
_vol_neg_others = input(color.new(color.red, 80), '', inline='Volume positive', group='Volume colors (pos/neg v strong/weak/others)')

_vol_limit_1 = input(1, 'Threshold 1', inline='Threshold ratios', group='Threshold ratios')
_vol_limit_2 = input(2.2, '2', inline='Threshold ratios', group='Threshold ratios')

_vol_color = (close > open) ? 
 (_vol_ratio_1 < _vol_limit_1) ? _vol_pos_weak : (_vol_ratio_1 > _vol_limit_2) ? _vol_pos_strong : _vol_pos_others :
 (_vol_ratio_1 < _vol_limit_1) ? _vol_neg_weak : (_vol_ratio_1 > _vol_limit_2) ? _vol_neg_strong : _vol_neg_others

plot(_vol_ratio_1, style=plot.style_columns, color=_vol_color, histbase=1)
