traduzione codice Donchian Channel Strenght

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

    Buongiorno,

    sempre in tema di Canale di Donchain, mi piacerebbe testare questo codice che sembra un oscillatore RSI applicato a Donchian, con evidenziazione di zone

    di overbought e oversold.

    Ringrazio sempre per il cortese aiuto.

    https://it.tradingview.com/script/hCfZsNU2-Donchian-Channels-Strength/

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

    //@version=5
    indicator(title=”Donchian Channels Strength”, shorttitle=”DC Strength”, overlay=false, timeframe=””, timeframe_gaps=true)

    // Input
    src = input(close, “Source”, inline = “Source”)
    include_wicks = input.bool(false, “Include Wicks”, inline = “Source”)
    length = input.int(13, “Length”, minval=2)
    maTypeInput = input.string(“SMMA (RMA)”, title=”MA Type”, options=[“SMA”, “EMA”, “SMMA (RMA)”, “WMA”, “VWMA”])
    signal_length = input.int(9, “Signal Length”)
    overbought_zone = input.int(80, “Overbought Zone”, tooltip = “Can be used for alerts”)
    oversold_zone = input.int(20, “Oversold Zone”, tooltip = “Can be used for alerts”)

    // MA Switch
    ma(source, length, type) =>
    switch type
    “SMA” => ta.sma(source, length)
    “EMA” => ta.ema(source, length)
    “SMMA (RMA)” => ta.rma(source, length)
    “WMA” => ta.wma(source, length)
    “VWMA” => ta.vwma(source, length)

    // Calculations
    lower = ta.lowest(src, length)
    upper = ta.highest(src, length)

    if include_wicks
    lower := ta.lowest(low, length)
    upper := ta.highest(high, length)

    basis = math.avg(upper, lower)
    dif = src – basis
    ma_dif = ma(dif, length, maTypeInput)
    ma_dif_abs = ma(math.abs(dif), length, maTypeInput)
    dc_strength = ma_dif / ma_dif_abs * 50 + 50

    // Lines
    hline(overbought_zone, linestyle = hline.style_dotted, display = display.none)
    hline(50, linestyle = hline.style_solid)
    hline(oversold_zone, linestyle = hline.style_dotted, display = display.none)

    // Plots
    p_50 = plot(50, editable = false, display = display.none) // only used for filling
    p_strength = plot(dc_strength, “DC Strength”, color = dc_strength > 50 ? color(#00cbff) : color(#ff0099))
    plot(ta.ema(dc_strength, signal_length), “Signal”, color = color(#d1d4dc))

    // Filling
    fill(p_strength, p_50, 80, 50, color.new(#00cbff, 70), na, title = “Upper Filling”)
    fill(p_50, p_strength, 50, 20, na, color.new(#ff0099, 70), title = “Lower Filling”)

    // Alerts
    alertcondition(ta.crossover(dc_strength, 50), “DC Strength crossover 50”, “DC Strength crossover 50”)
    alertcondition(ta.crossunder(dc_strength, 50), “DC Strength crossunder 50”, “DC Strength crossunder 50”)
    alertcondition(ta.crossover(dc_strength, overbought_zone), “DC Strength entered overbought zone”, “DC Strength entered overbought zone”)
    alertcondition(ta.crossunder(dc_strength, overbought_zone), “DC Strength left overbought zone”, “DC Strength left overbought zone”)
    alertcondition(ta.crossunder(dc_strength, oversold_zone), “DC Strength entered oversold zone”, “DC Strength entered oversold zone”)
    alertcondition(ta.crossover(dc_strength, oversold_zone), “DC Strength left oversold zone”, “DC Strength left oversold zone”)

    Screenshot-2024-05-17-at-08-14-25-Donchian-Channels-Strength-—-Indicatore-di-Daniel_Ge.jpg Screenshot-2024-05-17-at-08-14-25-Donchian-Channels-Strength-—-Indicatore-di-Daniel_Ge.jpg
    #232822 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Ciao. Ecco il codice tradotto:

    //--------------------------------------------------//
    //PRC_Donchian Channels Strength
    //version = 0
    //20.05.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //--------------------------------------------------//
    //-----Inputs---------------------------------------//
    src=close
    includeWicks=0//Boolean//Include Wicks
    length=13
    maTypeInput=3//0=SMA, 1=EMA 2=WMA, 3=SMMA (RMA)
    signalLength=9//
    overboughtZone=80//Overbought Zone
    oversoldZone=20//Oversold Zone
    //--------------------------------------------------//
    //-----Calculations---------------------------------//
    if includewicks then
    lower=lowest[length](low)
    upper=highest[length](high)
    else
    lower=lowest[length](src)
    upper=highest[length](src)
    endif
    
    basis=(upper+lower)/2
    dif=src-basis
    //----MA DIF Calculations----------------------------//
    source=dif
    if maTypeInput=0 then
    madif=average[length,0](source)
    elsif maTypeInput=1 then
    madif=average[length,1](source)
    elsif maTypeInput=2 then
    madif=average[length,2](source)
    else
    alpha = 1/length
    if barindex <= 2*length then
    madif = average[length](source)
    else
    madif = alpha*source + (1-alpha)*madif[1]
    endif
    endif
    //--------------------------------------------------//
    //----MA abs(DIF) Calculations----------------------//
    source2=abs(dif)
    if maTypeInput=0 then
    madifabs=average[length,0](source2)
    elsif maTypeInput=1 then
    madifabs=average[length,1](source2)
    elsif maTypeInput=2 then
    madifabs=average[length,2](source2)
    else
    alpha = 1/length
    if barindex <= 2*length then
    madifabs = average[length](source2)
    else
    madifabs = alpha*source2 + (1-alpha)*madifabs[1]
    endif
    endif
    //--------------------------------------------------//
    //-----Strength-------------------------------------//
    dcstrength=madif/madifabs*50+50
    signalstrength=average[signallength,1](dcstrength)
    //--------------------------------------------------//
    //-----Colours----------------------------------------//
    if dcstrength>50 then
    r=0
    g=203
    b=255
    else
    r=255
    g=0
    b=153
    endif
    colorbetween(50,dcstrength,r,g,b,35)
    //--------------------------------------------------//
    return overboughtZone style(dottedline2), oversoldZone style(dottedline2), 50, dcstrength as "DC Strength"coloured(r,g,b)style(line,3),signalstrength as "Signal"coloured("grey")style(line,2)
    
    #232826 quote
    Msport71Msport71
    Participant
    Senior

    Grazie e mille!

Viewing 3 posts - 1 through 3 (of 3 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 Donchian Channel Strenght


ProBuilder: Indicatori & Strumenti Personalizzati

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

This topic contains 2 replies,
has 2 voices, and was last updated by Msport71Msport71
2 years, 4 months ago.

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