Bogdan Ciocoiu - Makaveli
// 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 - Makaveli", shorttitle="BC - Makaveli", format=format.price, precision=2, timeframe="", timeframe_gaps=true, explicit_plot_zorder=true)

// Description
// This indicator integrates the functionality of multiple volume price analysis algorithms whilst aligning their scales to fit in a single chart. 
// Having such indicators loaded enables traders to take advantage of potential divergences between the price action and volume related volatility.
// Users will have to enable or disable alternative algorithms depending on their choice.
// 
// Uniqueness
// This indicator is unique because it combines multiple algorithm-specific two-volume analyses with price volatility.
// This indicator is also unique because it amends different algorithms to show output on a similar scale enabling traders to observe various volume-analysis tools simultaneously whilst allocating different colour codes.
// 
// Open source re-use
// This indicator utilises the following open-source scripts:
// https://www.tradingview.com/script/TsSXNt1o-Volume-Spread-Analysis/
// https://www.tradingview.com/script/7H00I0MG-Volume-Price-Spread-Analysis-2/
 
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Method 1
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------

_O1_enable = input(true, "", inline="Method 1", group="Method 1")

_O1_colors_up = input(color.green, "", inline="Method 1", group="Method 1")
_O1_colors_down = input(color.red, "", inline="Method 1", group="Method 1")

_O1_fact_1 = input(80000, "Factor 1 (+)", inline="Method 1", group="Method 1")
_O1_fact_2 = input(0.001, "2 (*)", inline="Method 1", group="Method 1")

_O1_V = volume
_O1_close = close * _O1_V

_O1_open = _O1_close[1]
_O1_high = math.max(math.max(high * _O1_V, _O1_close), _O1_open)
_O1_low = math.min(math.min(low * _O1_V, _O1_open), _O1_close)
_O1_HL2 = (_O1_high + _O1_low) / 2

_O1_color = open < close ? _O1_colors_up : _O1_colors_down 

plotcandle (
 _O1_low * _O1_fact_2 + _O1_fact_1,
 _O1_high * _O1_fact_2 + _O1_fact_1, 
 _O1_low * _O1_fact_2 + _O1_fact_1, 
 _O1_close * _O1_fact_2 + _O1_fact_1, 
 color=(_O1_enable) ? _O1_color : na, 
 wickcolor=(_O1_enable) ? _O1_color : na,
 bordercolor=(_O1_enable) ? _O1_color : na)

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Method 2
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------

_O2_enable = input(true, "", inline="Method 2", group="Method 2")

_O2_colors_up = input(color.blue, "", inline="Method 2", group="Method 2")
_O2_colors_down = input(color.fuchsia, "", inline="Method 2", group="Method 2")

_O2_fact_1 = input(0, "Factor 1 (+)", inline="Method 2", group="Method 2")
_O2_fact_2 = input(1, "2 (*)", inline="Method 2", group="Method 2")

_O2_V = math.log(volume)

_O2_close = 0.0
_O2_close := _O2_close[1] > 1 ? ( (close*_O2_V) + (high*_O2_V) + (low*_O2_V) + _O2_close[1] )*0.25 : ( (close*_O2_V) + (high*_O2_V) + (low*_O2_V) + (((close[1]*_O2_V[1])+(open*_O2_V))*0.5))*0.25

_O2_open = (_O2_close[1]+(open*_O2_V))*0.5
_O2_high = math.max(math.max(high*_O2_V,_O2_close),_O2_open)
_O2_low = math.min(math.min(low*_O2_V,_O2_open),_O2_close)
_O2_HL2 = ( _O2_high + _O2_low ) / 2

_O2_color = open < close ? _O2_colors_up : _O2_colors_down 

_O2_se = input.string("HL2", "", options=["HL2", "High", "Low", "Open", "Close"], inline="Method 2", group="Method 2")
_O2_wid = input(2, "", inline="Method 2", group="Method 2")
_O2_cl_col = input(color.white, "", inline="Method 2", group="Method 2")

plotcandle(
 _O2_open * _O2_fact_2 + _O2_fact_1, 
 _O2_high * _O2_fact_2 + _O2_fact_1, 
 _O2_low * _O2_fact_2 + _O2_fact_1, 
 _O2_close * _O2_fact_2 + _O2_fact_1, 
 color=(_O2_enable) ? _O2_color : na, 
 wickcolor=(_O2_enable) ? _O2_color : na,
 bordercolor=(_O2_enable) ? _O2_color : na)

_O2_ploter = (_O2_se == "Close") ? _O2_close : ( _O2_se == "Open" ) ? _O2_open : ( _O2_se == "HL2" ) ? _O2_HL2 : ( _O2_se == "High" ) ? _O2_high : ( _O2_se == "Low" ) ? _O2_low : 0
_O2_signal = plot(_O2_ploter, color=(_O2_enable) ? _O2_cl_col : na, style=plot.style_circles, linewidth=_O2_wid)
