on_balance_volume
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dandrideng

//@version=5

// @description on_balance_volume: custom on balance volume
library("on_balance_volume", overlay=false)

import dandrideng/moving_average/1 as ma

// @function obv_diff: custom on balance volume diff version
// @param string type: the moving average type of on balance volume
// @param simple int len: the moving average length of on balance volume
// @returns obv_diff: custom on balance volume diff value
export obv_diff(string type, simple int len) =>
	//TODO : add function body and return value here
    float obv = ta.cum(math.sign(ta.change(close)) * volume)
    float obv_ma = ma.variant(type, obv, len)
    float obv_diff = obv - obv_ma
    obv_diff

// @function obv_diff_norm: custom normalized on balance volume diff version
// @param string type: the moving average type of on balance volume
// @param simple int len: the moving average length of on balance volume
// @returns obv_diff: custom normalized on balance volume diff value
export obv_diff_norm(string type, simple int len) =>
	//TODO : add function body and return value here
    float obv_diff = obv_diff(type, len)
    float obv_diff_dev = ta.dev(obv_diff, len)
    float obv_diff_norm = obv_diff / obv_diff_dev
    obv_diff_norm
    
// plot(obv_diff("EMA", 30))
plot(obv_diff_norm("EMA", 30))