// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © mohammadmaruful89 //@version=5 indicator("~Up/Down Volume[Mrf]", format=format.volume) lowerTimeframeTooltip = "The indicator scans lower timeframe data to approximate Up/Down volume. By default, the timeframe is chosen automatically. These inputs override this with a custom timeframe. \n\nHigher timeframes provide more historical data, but the data will be less precise." useCustomTimeframeInput = input.bool(false, "Use custom timeframe", tooltip = lowerTimeframeTooltip) lowerTimeframeInput = input.timeframe("1", "Timeframe") length = input(12, 'Average volume length') upAndDownVolume(average_vol) => posVol = 0.0 negVol = 0.0 switch close > open => posVol := average_vol * math.abs(open / close - 1) close < open => negVol := average_vol * math.abs(open / close - 1) //close >= close[1] => posVol += volume //close < close[1] => negVol -= volume [posVol, negVol] lowerTimeframe = switch useCustomTimeframeInput => lowerTimeframeInput timeframe.isintraday => "1" timeframe.isdaily => "5" => "60" average_vol = ta.sma(volume, length) [upVolumeArray, downVolumeArray] = request.security_lower_tf(syminfo.tickerid, lowerTimeframe, upAndDownVolume(average_vol)) upVolume = array.sum(upVolumeArray) downVolume = array.sum(downVolumeArray) downVolume1 = 0 - downVolume delta = upVolume + downVolume1 plot(upVolume, "Up Volume", style = plot.style_columns, color=color.new(color.green, 60)) plot(downVolume1, "Down Volume", style = plot.style_columns, color=color.new(color.red, 60)) plotchar(delta, "delta", "—", location.absolute, color = delta > 0 ? color.green : color.red, size = size.tiny) var cumVol = 0. cumVol += nz(volume) if barstate.islast and cumVol == 0 runtime.error("The data vendor doesn't provide volume data for this symbol.")