DSL OSCILLATOR TW

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #239546 quote
    Stenozar
    Participant
    Master

    Ciao, chiedo se è possibile tradurre questo indicatore che mi pare interessante in combinazione con un indicatore di trend: https://www.tradingview.com/script/bVMgRGq8-DSL-Oscillator-BigBeluga/#:~:text=The%20DSL%20(Discontinued%20Signal%20Lines,Exponential%20Moving%20Average%20(ZLEMA)

    // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © BigBeluga

    //@version=5
    indicator(“DSL Oscillator [BigBeluga]”)

    // ====================================================================================================================}
    // INPUTS
    // ===================================================================================================================={

    // User inputs for customization
    len = input.int(10, “Length”)
    dsl_mode = input.string(“Fast”, “DSL Lines Mode”, [“Fast”, “Slow”]) == “Fast” ? 2 : 1

    // Color definitions
    color_up = #8BD8BD
    color_dn = #436cd3

    // Condition for a dashed line
    bool dashed = bool(bar_index % 2)

    // ====================================================================================================================}
    // CALCULATIONS
    // ===================================================================================================================={

    // Calculate RSI with a period of 10
    RSI = ta.rsi(close, 10)

    // Zero-Lag Exponential Moving Average function
    zlema(src, length) =>
    lag = math.floor((length – 1) / 2)
    ema_data = 2 * src – src[lag]
    ema2 = ta.ema(ema_data, length)
    ema2

    // Discontinued Signal Lines
    dsl_lines(src, length)=>
    up = 0.
    dn = 0.
    up := (src > ta.sma(src, length)) ? nz(up[1]) + dsl_mode / length * (src – nz(up[1])) : nz(up[1])
    dn := (src < ta.sma(src, length)) ? nz(dn[1]) + dsl_mode / length * (src – nz(dn[1])) : nz(dn[1])
    [up, dn]

    // Calculate DSL lines for RSI
    [lvlu, lvld] = dsl_lines(RSI, len)

    // Calculate DSL oscillator using ZLEMA of the average of upper and lower DSL Lines
    dsl_osc = zlema((lvlu + lvld) / 2, 10)

    // Calculate DSL Lines for the oscillator
    [level_up, level_dn] = dsl_lines(dsl_osc, 10)

    // Determine color based on oscillator position relative to its DSL Lines
    color = color.from_gradient(dsl_osc, level_dn, level_up, color_dn, color_up)

    // ====================================================================================================================}
    // PLOT
    // ===================================================================================================================={

    // Plot upper and lower DSL Lines
    plot(level_up, color = dashed ? color.new(color_up, 20) : na, editable = false)
    plot(level_dn, color = dashed ? color.new(color_dn, 20) : na, editable = false)

    // Plot the DSL oscillator
    plot(dsl_osc, color = color, linewidth = 2)

    // Detect crossovers for signal generation
    up = ta.crossover(dsl_osc, level_dn) and dsl_osc < 55
    dn = ta.crossunder(dsl_osc, level_up) and dsl_osc > 50

    // Plot signals on the oscillator
    plotshape(up ? dsl_osc[1] : na, “”, shape.circle, location.absolute, color_up, -1, “”, chart.fg_color, false, size.tiny)
    plotshape(dn ? dsl_osc[1] : na, “”, shape.circle, location.absolute, color_dn, -1, “”, chart.fg_color, false, size.tiny)

    // Plot signals on the chart
    plotshape(up, “”, shape.triangleup, location.bottom, color_up, 0, “Enter”, chart.fg_color, true, size.tiny,
    force_overlay = true)
    plotshape(dn, “”, shape.triangledown, location.top, color_dn, 0, “Exit”, chart.fg_color, true, size.tiny,
    force_overlay = true)

    // Color the background on signal occurrences
    bgcolor(up ? color.new(color_up, 90) : na, force_overlay = true, editable = false)
    bgcolor(dn ? color.new(color_dn, 90) : na, force_overlay = true, editable = false)

    // Color candles based on signals
    candle_col = up ? color.new(color_up, 0) : dn ? color.new(color_dn, 0) : na

    plotcandle(open, high, low, close, “”,
    candle_col,
    candle_col,
    bordercolor = candle_col,
    force_overlay = true,
    editable = false)

    // Plot horizontal lines for visual reference
    h = plot(75, display = display.none, editable = false)
    m = plot(50, display = display.none, editable = false)
    l = plot(25, display = display.none, editable = false)

    // Fill areas between horizontal lines
    fill(m, h, 120, 50, color_up, na, editable = false)
    fill(m, l, 50, -20, na, color_dn, editable = false)

    // ====================================================================================================================}

    #239738 quote
    Iván González
    Moderator
    Master

    Ciao. Eccolo qui:

    //-----------------------------------------//
    //PRC_DSL Oscillator
    //version = 0
    //29.10.2024
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-----------------------------------------//
    //-----------------------------------------//
    //-----------------------------------------//
    //len=10 //length
    //fast=1
    if fast then
    dslMode=2 
    else
    dslMode=1
    endif
    //-----------------------------------------//
    //        RSI and DSL Calculations         //
    //-----------------------------------------//
    //-----Rsi
    myrsi=rsi[10](close)
    //-----DSL Lines for RSI
    lvlu=0
    lvld=0
    if myrsi>average[len](myrsi) then
    lvlu=lvlu[1]+dslMode/len*(myrsi-lvlu[1])
    lvld=lvld[1]
    elsif myrsi<average[len](myrsi) then
    lvld=lvld[1]+dslMode/len*(myrsi-lvld[1])
    lvlu=lvlu[1]
    endif
    //-----------------------------------------//
    //     DSL Oscillator Calculations         //
    //-----------------------------------------//
    //-----DSL Oscillator 
    src=(lvlu+lvld)/2
    length=10
    lag=floor((length-1)/2)
    if barindex>lag then
    emaData=2*src-src[lag]
    endif
    dslOsc=average[length,1](emaData)
    //-----DSL Lines for the Oscillator
    levelUp=0
    levelDn=0
    if dslOsc>average[10](dslOsc) then
    levelUp=levelUp[1]+dslMode/10*(dslOsc-levelUp[1])
    levelDn=levelDn[1]
    elsif dslOsc<average[10](dslOsc) then
    levelDn=levelDn[1]+dslMode/10*(dslOsc-levelDn[1])
    levelUp=levelUp[1]
    endif
    //-----------------------------------------//
    //          Plot Configuration             //
    //-----------------------------------------//
    //-----Signals
    if dslOsc crosses under levelUp then
    drawpoint(barindex,dslOsc,2)coloured("blue")
    elsif dslOsc crosses over levelDn then
    drawpoint(barindex,dslOsc,2)coloured("fuchsia")
    endif
    //-----DSL Oscillator color
    if dslOsc > levelUp then
    r=0
    g=0
    b=255
    elsif dslOsc<levelDn then
    r=255
    g=0
    b=255
    endif
    //-----------------------------------------//
    return dslOsc style(line,2)coloured(r,g,b), levelUp as "Level Up" coloured("fuchsia")style(dottedline),levelDn as "Level Down" coloured("blue")style(dottedline), 25 style(dottedline2,1)coloured("grey",100),50 style(dottedline2,1)coloured("grey",100),75 style(dottedline2,1)coloured("grey",100)
    #239895 quote
    Stenozar
    Participant
    Master

    Ciao Ivan, ti ringrazio, mi restituisce però errore: “definisci la variabile fast len”

    puoi aiutarmi a risolvere il problema?

    Grazie

    #239903 quote
    robertogozzi
    Moderator
    Master

    Basta che togli le doppie barre (solo quelle iniziali)  dalle linee 10 e 11.

    Iván González thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

DSL OSCILLATOR TW


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
Stenozar @stenozar Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by robertogozzi
1 year, 3 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 10/26/2024
Status: Active
Attachments: No files
Logo Logo
Loading...