Can you help me this tradingview pine script code convert to Python code. CVD is one of the things that helps me to create an algo trading system. Please help to complete my project.
//@version=5
indicator("Cumulative Volume Delta", "CVD", format=format.volume)
anchorInput = input.timeframe("1D", "Anchor period")
lowerTimeframeTooltip = "The indicator scans lower timeframe data to approximate up and down volume used in the delta calculation. By default, the timeframe is chosen automatically. These inputs override this with a custom timeframe.
nnHigher 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")
upAndDownVolume() =>
posVol = 0.0
negVol = 0.0
var isBuyVolume = true
switch
close > open => isBuyVolume := true
close < open => isBuyVolume := false
close > close[1] => isBuyVolume := true
close < close[1] => isBuyVolume := false
if isBuyVolume
posVol += volume
else
negVol -= volume
posVol + negVol
var lowerTimeframe = switch
useCustomTimeframeInput => lowerTimeframeInput
timeframe.isseconds => "1S"
timeframe.isintraday => "1"
timeframe.isdaily => "5"
=> "60"
diffVolArray = request.security_lower_tf(syminfo.tickerid, lowerTimeframe, upAndDownVolume())
getHighLow(arr) =>
float cumVolume = na
float maxVolume = na
float minVolume = na
for item in arr
cumVolume := nz(cumVolume) + item
maxVolume := math.max(nz(maxVolume), cumVolume)
minVolume := math.min(nz(minVolume), cumVolume)
[maxVolume, minVolume, cumVolume]
[maxVolume, minVolume, lastVolume] = getHighLow(diffVolArray)
var cumulLastVolume = 0.0
anchorChange = timeframe.change(anchorInput) or barstate.isfirst
cumulOpenVolume = anchorChange and not na(lastVolume) ? 0.0 : cumulLastVolume[1]
cumulMaxVolume = cumulOpenVolume + maxVolume
cumulMinVolume = cumulOpenVolume + minVolume
cumulLastVolume := cumulOpenVolume + lastVolume
col = cumulLastVolume >= cumulOpenVolume ? color.teal : color.red
hline(0)
plotcandle(cumulOpenVolume, cumulMaxVolume, cumulMinVolume, cumulLastVolume, "CVD", color = col, bordercolor = col, wickcolor = col)
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.")
As I am new to Pine Script, some things are not clear to me, so I hope you can help me to convert this code to python.
New contributor
Adhithyan Vs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.