Traduzione codice TW Dvd

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #248702 quote
    Msport71Msport71
    Participant
    Senior

    Buongiorno,

    chiedo cortese traduzione codice in oggetto che vorrei testare.

    Grazie per l’aiuto.

    https://it.tradingview.com/script/2e7GfTx8-Dual-Volume-Divergence-Line/

    // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // Dual Volume Divergence Index [DW] oscillator is utilized and get inspired by.
    // Original concept by DonovanWall
    // Modified by © keremertem
    //@version=6
    indicator(‘Dual Volume Divergence Line’, shorttitle = ‘DVD/Line’, overlay = true)
    import TradingView/ta/9

    //—————————————————————————–\\
    // — Ayarlar
    //—————————————————————————–//
    zaman = input.int(17, ‘Dvd Sampling Period’, 2, 100)
    genislik = input.int(12, ‘Band Width’, 2, 50)
    takip = input.int(3, ‘Trailing Length’, 2, 20)
    kaynak = input.source(hlc3, ‘Source’)
    carpan = input.float(1, ‘Multiplier’, 0.5, 10, 0.5)
    //— SON —

    //—————————————————————————–\\
    // — DVD Gostergesi
    //—————————————————————————–//
    hacim = volume

    // Pozitif Hacim Endeksi (PVI) Hesaplama
    var float pvi = 0.0
    pvi := kaynak > kaynak[1] ? pvi + (kaynak – kaynak[1]) : pvi

    // PVI Sinyali ve Iraksama
    pvi_sinyal = ta.wma(pvi, zaman) // EMA fonksiyonu yerine WMA geldi
    pvi_iraksama = (pvi – pvi_sinyal)

    // Negatif Hacim Endeksi (NVI) Hesaplama
    var float nvi = 0.0
    nvi := kaynak < kaynak[1] ? nvi – (kaynak – kaynak[1]) : nvi

    // NVI Sinyali ve Iraksama
    nvi_sinyal = ta.wma(nvi, zaman) // EMA fonksiyonu yerine WMA geldi
    nvi_iraksama = (nvi – nvi_sinyal)

    // DVD Hesaplama
    Dvdi = (pvi_iraksama – nvi_iraksama) * carpan
    Dvd = ta.wma(Dvdi + kaynak, genislik) // EMA fonksiyonu yerine WMA geldi
    Dvd2 = ta.linreg(Dvd, takip, 1) // Takip cizgisi
    Max = ta.highest(Dvd, genislik)
    Min = ta.lowest(Dvd, genislik)
    Ust = ta.rms(Max, genislik)
    Alt = ta.rms(Min, genislik)
    Orta = (Alt + Ust)/2
    Ust := 2 * Ust – Orta
    Alt := 2 * Alt – Orta

    // Cizim
    rnk = Dvd > Dvd2 ? #00e6de : #fb00ff
    ciz1 = plot(Dvd, ‘DVD Line’, rnk, 3)
    gosterBand = input.bool(false, ‘Show Bands’)
    ciz2 = plot(Ust, ‘Upper Band’, #ff525280, 2, plot.style_cross, display = gosterBand ? display.all : display.none)
    ciz3 = plot(Alt, ‘Lower Band’, #00e67780, 2, plot.style_cross, display = gosterBand ? display.all : display.none)
    ornk = Orta > Orta[1] ? #00e67780 : #ff525280
    ciz4 = plot(Orta, ‘Middle Band’, ornk, 3)
    //— SON —

    //—————————————————————————–\\
    // — Iraksama Gostergesi Secimi
    //—————————————————————————–//
    string N_type = input.string(‘DVDI’, title = ‘Divergence Selection’, options=[‘DVDI’, ‘DVD Line’], group = ‘Divergence’)

    Ir_Go(type) =>
    switch type
    ‘DVDI’ => Dvdi
    ‘DVD Line’ => Dvd
    //— SON —

    //—————————————————————————–\\
    // — Iraksama Saptama
    //—————————————————————————–//
    IrGo = Ir_Go(N_type)

    // Pivot Noktalari Saptama
    Ir = input.int(1, ‘Divergence Range’)
    py = na(ta.pivothigh(IrGo, Ir, Ir)) ? false : true
    pd = na(ta.pivotlow(IrGo, Ir, Ir)) ? false : true
    pyFiyat = ta.valuewhen(py, high[Ir], 1)
    pdFiyat = ta.valuewhen(pd, low[Ir], 1)
    pyIrGo = ta.valuewhen(py, IrGo[Ir], 1)
    pdIrGo = ta.valuewhen(pd, IrGo[Ir], 1)

    // Boga Iraksama (Normal & Gizli)
    bogaNormal = pd and IrGo[Ir] > pdIrGo and low[Ir] < pdFiyat
    bogaGizli = pd and IrGo[Ir] < pdIrGo and low[Ir] > pdFiyat

    // Ayı Iraksama (Normal & Gizli)
    ayiNormal = py and IrGo[Ir] < pyIrGo and high[Ir] > pyFiyat
    ayiGizli = py and IrGo[Ir] > pyIrGo and high[Ir] < pyFiyat

    // Etiketleme
    gosterNormal = input.bool(true, ‘Show Normal Divergences’)
    gosterGizli = input.bool(false, ‘Show Hidden Divergences’)
    if gosterNormal and bogaNormal
    label.new(x=bar_index – Ir, y=low[Ir], text=’Bull’, color=color.green, style=label.style_label_up, textcolor=color.white, size=size.small)
    if gosterGizli and bogaGizli
    label.new(x=bar_index – Ir, y=low[Ir], text=’hid.’, color=color.lime, style=label.style_label_up, textcolor=color.white, size=size.small)
    if gosterNormal and ayiNormal
    label.new(x=bar_index – Ir, y=high[Ir], text=’Bear’, color=color.red, style=label.style_label_down, textcolor=color.white, size=size.small)
    if gosterGizli and ayiGizli
    label.new(x=bar_index – Ir, y=high[Ir], text=’hid.’, color=color.orange, style=label.style_label_down, textcolor=color.white, size=size.small)
    //— SON —

    Screenshot-2025-07-07-at-10-35-00-Dual-Volume-Divergence-Line-—-Indicatore-di-keremertem-—-TradingView.png Screenshot-2025-07-07-at-10-35-00-Dual-Volume-Divergence-Line-—-Indicatore-di-keremertem-—-TradingView.png
    #248723 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Ecco:

    // ------------------------------------------
    // PRC_Dual Volume Divergence Line (DVD/Line)
    //version = 0
    //08.07.25
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    // ------------------------------------------
    // --- Configuración de Parámetros
    // ------------------------------------------
    zaman = 17 // Dvd Sampling Period
    genislik = 12 // Band Width
    takip = 3 // Trailing Length
    carpan = 1.0 // Multiplier
    gosterBand = 0 // 'Show Bands'
    gosterNormal = 1 // 'Show Normal Divergences'
    gosterGizli = 1 // 'Show Hidden Divergences'
    Ir = 1 // 'Divergence Range'
    Ntype = 1 // Divergence Selection
    // ------------------------------------------
    // -- Cálculo del Indicador DVD
    // ------------------------------------------
    // --- Origen de datos ---
    kaynak = (high + low + close) / 3
    // --- Cálculo del Índice de Volumen Positivo (PVI)
    IF barindex > 0 THEN
       IF kaynak > kaynak[1] THEN
          pvi = pvi[1] + (kaynak - kaynak[1])
       ELSE
          pvi = pvi[1]
       ENDIF
    ELSE
       pvi = 0
    ENDIF
    
    // --- Señal y Divergencia PVI ---
    pviSinyal = WeightedAverage[zaman](pvi)
    pviIraksama = pvi - pviSinyal
    
    // --- Cálculo del Índice de Volumen Negativo (NVI) ---
    IF barindex > 0 THEN
       IF kaynak < kaynak[1] THEN
          nvi = nvi[1] - (kaynak - kaynak[1])
       ELSE
          nvi = nvi[1]
       ENDIF
    ELSE
       nvi = 0
    ENDIF
    
    // --- Señal y Divergencia NVI ---
    nviSinyal = WeightedAverage[zaman](nvi)
    nviIraksama = nvi - nviSinyal
    
    // --- Cálculo del DVD ---
    Dvdi = (pviIraksama - nviIraksama) * carpan
    Dvd = WeightedAverage[genislik](Dvdi + kaynak)
    Dvd2 = LinearRegression[takip](Dvd)-LinearRegressionSlope[takip](Dvd) // ta.linreg(Dvd, takip, 1)
    
    // --- Cálculo de Bandas ---
    MaxDVD = Highest[genislik](Dvd)
    MinDVD = Lowest[genislik](Dvd)
    
    // Implementación de la función RMS (Root Mean Square)
    rmsMax = SQRT(Average[genislik](SQUARE(MaxDVD)))
    rmsMin = SQRT(Average[genislik](SQUARE(MinDVD)))
    
    Ust = rmsMax
    Alt = rmsMin
    Orta = (Alt + Ust) / 2
    
    // Proyección de las bandas
    Ust = 2 * Ust - Orta
    Alt = 2 * Alt - Orta
    
    // --- Variables para colorear las líneas ---
    // Línea DVD principal
    IF Dvd > Dvd2 THEN
       Rdvd = 0
       Gdvd = 230
       Bdvd = 222
    ELSE
       Rdvd = 251
       Gdvd = 0
       Bdvd = 255
    ENDIF
    
    // Línea Media
    IF Orta > Orta[1] THEN
       Rorta = 0
       Gorta = 230
       Borta = 119
    ELSE
       Rorta = 282
       Gorta = 82
       Borta = 82
    ENDIF
    
    // -----------------------------------------------------------------------------\\
    // -- Detección de Divergencias
    // -----------------------------------------------------------------------------//
    
    // --- Selección del Oscilador para Divergencia ---
    IF Ntype = 1 THEN
       IrGo = Dvdi
    ELSE
       IrGo = Dvd
    ENDIF
    
    // --- Detección de Puntos Pivote (con retraso necesario en ProBuilder) ---
    pivotHighDetected = (IrGo[Ir] = HIGHEST[2 * Ir + 1](IrGo))
    pivotLowDetected = (IrGo[Ir] = LOWEST[2 * Ir + 1](IrGo))
    
    // --- Almacenamiento de valores de pivotes anteriores ---
    ONCE lastPHprice = 0
    ONCE lastPLprice = 0
    ONCE lastPHosc = 0
    ONCE lastPLosc = 0
    once lastPHindex=-1
    once lastPLindex=-1
    
    ayiNormal=0
    ayiGizli=0
    bogaNormal=0
    bogaGizli=0
    // Actualizar valores del último Pivote ALTO
    IF pivotHighDetected and lastPHindex <> barindex[ir] THEN
       if lastPHindex<> -1 then
          if high[Ir]>LastPHprice and IrGo[Ir]<lastPHosc then
             ayiNormal = 1
          endif
          if high[Ir]<lastPHprice and IrGo[Ir]>lastPHosc then
             ayiGizli = 1
          endif
       endif
       lastPHprice = high[Ir]
       lastPHosc = IrGo[Ir]
       lastPHIndex=barindex[Ir]
    ENDIF
    
    // Actualizar valores del último Pivote BAJO
    IF pivotLowDetected and lastPLindex<>barindex[Ir] THEN
       if lastPLindex<>-1 then
          if low[Ir]<lastPLprice and IrGo[Ir]>lastPLosc then
             bogaNormal=1
          endif
          if low[Ir]<lastPLprice and IrGo[Ir]<lastPLosc then
             bogaGizli=1
          endif
       endif
       lastPLprice = low[Ir]
       lastPLosc = IrGo[Ir]
       lastPLindex = barindex[Ir]
    ENDIF
    
    // --- Dibujo de Etiquetas de Divergencia ---
    atr=averagetruerange[14](close)
    // Normal Alcista
    IF gosterNormal AND bogaNormal THEN
       DRAWTEXT("Bull", barindex[Ir], low[Ir] - 0.15*atr ) COLOURED("green")
    ENDIF
    
    // Oculta Alcista
    IF gosterGizli AND bogaGizli THEN
       DRAWTEXT("hid.Bull", barindex[Ir], low[Ir] - 0.15*atr) COLOURED("lime")
    ENDIF
    
    // Normal Bajista
    IF gosterNormal AND ayiNormal THEN
       DRAWTEXT("Bear", barindex[Ir], high[Ir] +  0.15*atr) COLOURED("red")
    ENDIF
    
    // Oculta Bajista
    IF gosterGizli AND ayiGizli THEN
       DRAWTEXT("hid.Bear", barindex[Ir], high[Ir] +  0.15*atr) COLOURED("orange")
    ENDIF
    
    // -----------------------------------------------------------------------------\\
    // --- Salida de Datos (Plot)
    // -----------------------------------------------------------------------------//
    RETURN Ust COLOURED(255, 82, 82, gosterBand*128) STYLE(POINT, 2) AS "Upper Band", Alt COLOURED(0, 230, 119, gosterBand*128) STYLE(POINT, 2) AS "Lower Band", Dvd as "Dvd Line" coloured(Rdvd,Gdvd,Bdvd)style(line,3), orta as "Middle band"coloured(Rorta,Gorta,Borta,80)style(line,3)
    
    Msport71 thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Traduzione codice TW Dvd


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
Msport71 @carlo-pasca Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván GonzálezIván González
1 year, 2 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 07/07/2025
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...