In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.
// Written by liw0 active on https://www.tradingview.com/u/liw0 // If you decide to use my script in your published charts, // please keep this header as it is now and leave the name unchanged! // It would make me happy to see my script put to use in other charts :) // If you like it I would also be happy about a small donation // BTC 1GyfGTBsVHMbPovFGFeipe7b7ET1aebGx5 // Questions or Comments? Just send me a PM! // CREDITS: http://quant.stackexchange.com/questions/2816/how-to-calculate-time-segmented-volume study("Time Segmented Volume") l = input(13, title="Length") l_ma = input(7, title="MA Length") t = sum(close>close?volume*close-close:close<close?(volume*-1)*close-close:0,l) m = sma(t ,l_ma ) plot(t, color=red, style=histogram) plot(m, color=green)