Совокупная дельта объемаPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Совокупная дельта объема

Сообщение Anonymous »

Можете ли вы помочь мне преобразовать код сценария pine TradingView в код Python? CVD — это одна из вещей, которая помогает мне создать систему алгоритмической торговли. Пожалуйста, помогите завершить мой проект.

Код: Выделить всё


//@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.

\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")

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.")

Поскольку я новичок в Pine Script, некоторые вещи мне не ясны, поэтому я надеюсь, что вы поможете мне преобразовать этот код в Python.

Подробнее здесь: https://stackoverflow.com/questions/783 ... lume-delta
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»