As described here:
www.investopedia.com...ow-it-calculated.asp
www.investopedia.com...ow-it-calculated.asp
//@version=2 study(title='[RS]Trade Volume Index V0', overlay=false) smooth = input(title='Signal Smoothness, (<0 to hide):', type=integer, defval=4) f_tvi()=> _min_tick = syminfo.mintick _price_change = close-open // can be change(close) if want to include gaps _direction = _price_change > _min_tick ? 1 : _price_change < -_min_tick ? -1 : _direction[1] //1=accumulation, -1=distribution _return_tvi = na(_return_tvi[1]) ? volume : _direction > 0 ? _return_tvi[1] + volume : _direction < 0 ? _return_tvi[1] - volume : _return_tvi[1] plot(title='TVI', series=f_tvi(), color=black) plot(title='Signal', series=smooth <= 0 ? na : sma(f_tvi(), smooth), color=red) hline(title='0', price=0, color=black)