traduzione codice TW WaveTrend Ribbon

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #231608 quote
    Msport71
    Participant
    Junior

    Buongiorno,

    richiedo consueta cortese aiuto per tradurre il seguente codice che mi sembra interessante e che abbina la logica wave trend con il concetto di divergenza ( finora da me trovato in abbinamento al RSI).

    Grazie per la collaborazione.

     

    https://it.tradingview.com/script/mFXrPy9V-WaveTrend-Ribbon-AlgoAlpha/

    //@version=5
    indicator(“WaveTrend Ribbon [AlgoAlpha]”, shorttitle=”AlgoAlpha – wave trend ribbon”, overlay=false)

    // WaveTrend parameters
    n1 = input(10, “Channel Length”)
    n2 = input(21, “Average Length”)
    obLevel = input(2.0, “Overbought Z-score Level”)
    osLevel = input(-2.0, “Oversold Z-score Level”)
    lengthZ = input(20, “Length for Z-score Calculation”)
    hmaLength = input(12, “HMA Length for Z-score Smoothing”)
    wmaLength = input(3, “WMA Length for Z-Score”)
    upColor = input.color(#00ffbb, “Up Color”)
    downColor = input.color(#ff1100, “Down Color”)

    // WaveTrend calculation
    ap = hlc3
    esa = ta.ema(ap, n1)
    d = ta.ema(math.abs(ap – esa), n1)
    ci = (ap – esa) / (0.015 * d)
    tci = ta.ema(ci, n2)

    // Z-score calculation
    meanWT = ta.sma(tci, lengthZ)
    stdDevWT = ta.stdev(tci, lengthZ)
    zScore = (tci – meanWT) / stdDevWT
    zScore := ta.hma(zScore, hmaLength)
    zma = ta.wma(zScore, wmaLength)

    // Overbought/Oversold conditions
    obCondition = zScore > obLevel
    osCondition = zScore < osLevel

    // Plotting
    //p1 = plot(zScore, color= zScore > zma ? color.new(upColor, 30) : color.new(downColor, 30), title=”WaveTrend Z-Score”)
    //p2 = plot(zma, color= zScore > zma ? color.new(upColor, 30) : color.new(downColor, 30), title=”WaveTrend Z-Score”)
    p1 = plot(zScore, color = zScore > 0 ? color.new(upColor, 50) : color.new(downColor, 50), title=”WaveTrend Z-Score”)
    p2 = plot(zma, color = zScore > 0 ? color.new(upColor, 50) : color.new(downColor, 50), title=”WaveTrend Z-Score”)
    m = plot(0, color = color.gray)
    hline(obLevel, “Overbought”, color=downColor)
    hline(osLevel, “Oversold”, color=upColor)
    bgcolor(obCondition ? color.new(downColor, 90) : na)
    bgcolor(osCondition ? color.new(upColor, 90) : na)

    //fill(p1, p2, zScore > zma ? color.new(upColor, 30) : color.new(downColor, 30))
    fill(p1, p2, zScore > 0 ? color.new(upColor, 50) : color.new(downColor, 50))
    fill(p1, m, zScore, 0, zScore > 0 ? color.new(upColor, 50) : color.new(downColor, 50), color.new(chart.bg_color, 80))

    // Reversal signals
    plotchar(obCondition and zScore[1] > zScore ? 3 : na , char = “▼”, location=location.absolute, color=downColor, title=”Overbought Reversal”, size = size.tiny)
    plotchar(osCondition and zScore[1] < zScore ? -3 : na, char = “▲”, location=location.absolute, color=upColor, title=”Oversold Reversal”, size = size.tiny)
    plotchar(ta.cross(zScore, zma) ? zma : na, char = “●”, location=location.absolute, color= zScore > 0 ? color.new(upColor, 0) : color.new(downColor, 0), title=”Trend Swing”, size = size.tiny)

    plotBullish = input(title=”Plot Bullish”, defval=true, group = “Divergences”)
    plotHiddenBull = input(title=”Plot Hidden Bullish”, defval=false, group = “Divergences”)
    plotBear = input(title=”Plot Bearish”, defval=true, group = “Divergences”)
    plotHiddenBear = input(title=”Plot Hidden Bearish”, defval=false, group = “Divergences”)
    bearColor = downColor
    bullColor = upColor
    hiddenBullColor = color.new(upColor, 80)
    hiddenBearColor = color.new(downColor, 80)
    textColor = color.white
    noneColor = color.new(color.white, 100)
    osc = zScore

    lbR = input(title=”Pivot Lookback Right”, defval=1)
    lbL = input(title=”Pivot Lookback Left”, defval=20)

    plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
    phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
    _inRange(cond) =>
    bars = ta.barssince(cond == true)
    -80 <= bars and bars <= 80

    // Regular Bullish
    oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
    priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
    bullCond = plotBullish and priceLL and oscHL and plFound
    plot(plFound ? osc[lbR] : na, offset=-lbR, title=”Regular Bullish”, linewidth=2, color=(bullCond ? bullColor : noneColor))
    plotshape(bullCond ? osc[lbR] : na, offset=-lbR, title=”Regular Bullish Label”, text=” Bull “, style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor)

    // Hidden Bullish
    oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
    priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)
    hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound
    plot(plFound ? osc[lbR] : na, offset=-lbR, title=”Hidden Bullish”, linewidth=2, color=(hiddenBullCond ? hiddenBullColor : noneColor))
    plotshape(hiddenBullCond ? osc[lbR] : na, offset=-lbR, title=”Hidden Bullish Label”, text=” H Bull “, style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor)

    // Regular Bearish
    oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
    priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
    bearCond = plotBear and priceHH and oscLH and phFound
    plot(phFound ? osc[lbR] : na, offset=-lbR, title=”Regular Bearish”, linewidth=2, color=(bearCond ? bearColor : noneColor))
    plotshape(bearCond ? osc[lbR] : na, offset=-lbR, title=”Regular Bearish Label”, text=” Bear “, style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor)

    // Hidden Bearish
    oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
    priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)
    hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound
    plot(phFound ? osc[lbR] : na, offset=-lbR, title=”Hidden Bearish”, linewidth=2, color=(hiddenBearCond ? hiddenBearColor : noneColor))
    plotshape(hiddenBearCond ? osc[lbR] : na, offset=-lbR, title=”Hidden Bearish Label”, text=” H Bear “, style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor)

    //Alerts
    alertcondition(bullCond, “Bullish Divergence”, “Bullish Divergence”)
    alertcondition(bearCond, “Bearish Divergence”, “Bearish Divergence”)
    alertcondition(ta.crossover(zScore, zma), “Bullish Swing”, “Bullish Swing”)
    alertcondition(ta.crossunder(zScore, zma), “Bearish Swing”, “Bearish Swing”)
    alertcondition(osCondition and zScore[1] < zScore, “Bullish Reversal”, “Bullish Reversal”)
    alertcondition(osCondition and zScore[1] < zScore, “Bearish Divergence”, “Bearish Divergence”)

    Screenshot-2024-04-17-at-10-14-20-Trader-AlgoAlpha-—-Grafici-e-idee-di-trading.png Screenshot-2024-04-17-at-10-14-20-Trader-AlgoAlpha-—-Grafici-e-idee-di-trading.png
    #231627 quote
    Iván González
    Moderator
    Master

    Eccolo qui: https://www.prorealcode.com/prorealtime-indicators/wavetrend-ribbon-indicator-to-detect-market-reversals/

    //-------------------------------------------------------------------------------//
    //PRC_WaveTrend Ribbon
    //version = 0
    //17.04.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-------------------------------------------------------------------------------//
    //-----Inputs--------------------------------------------------------------------//
    //-----WaveTrend
    n1=10//Channel length
    n2=21//Average length
    oblevel=2//Overbought Z-score level
    oslevel=-2//Oversold Z-score level
    lengthZ=20//Length for Z-score Calculation
    hmaLength=12//HMA Length for Z-score Smoothing
    wmaLength=3//WMA Length for Z-Score
    //-----Divergences
    plotdivergences=1//show bullish and bearish divergences
    plothiddendiv=1//show hidden bullish and bearish divergences
    //-----Pivots
    lbR=1//lookback Right
    lbL=20//lookback Left
    //-------------------------------------------------------------------------------//
    //-----WaveTrend Calculation-----------------------------------------------------//
    ap=(high+low+close)/3
    esa=average[n1,1](ap)
    d=average[n1,1](abs(ap-esa))
    ci=(ap-esa)/(0.0015*d)
    tci=average[n2,1](ci)
    //-------------------------------------------------------------------------------//
    //-----Z-Score Calculation-------------------------------------------------------//
    meanWT=average[lengthZ](tci)
    stdDevWT=std[lengthZ](tci)
    zScoreaux=(tci-meanWT)/stdDevWT
    zScore=hullaverage[hmaLength](zScoreaux)
    zma=weightedaverage[wmaLength](zScore)
    //-------------------------------------------------------------------------------//
    //-----Colors--------------------------------------------------------------------//
    if zScore > 0 then
    r=0
    g=255
    b=187
    else
    r=255
    g=17
    b=0
    endif
    colorbetween(zScore,zma,r,g,b,70)
    //-------------------------------------------------------------------------------//
    //-----Overbought/Oversold conditions--------------------------------------------//
    obCondition = zScore > obLevel
    osCondition = zScore < osLevel
    if obCondition then
    backgroundcolor(255,17,0,30)
    elsif osCondition then
    backgroundcolor(0,255,187,30)
    endif
    if obCondition and zScore[1]>zScore then
    drawtext("▼",barindex,3)coloured("red")
    elsif osCondition and zScore[1]<zScore then
    drawtext("▲",barindex,-3)coloured("green")
    elsif zscore crosses over zma or zscore crosses under zma then
    drawpoint(barindex,zma,2)coloured(r,g,b)
    endif
    //-------------------------------------------------------------------------------//
    //-----Pivots High-Low Z-Score---------------------------------------------------//
    osc=zScore
    //-----pivots low
    if osc > osc[lbR] and lowest[lbR](osc) > osc[lbR] and osc[lbR] < lowest[lbL](osc)[lbR+1] then
    $pl[z+1] = osc[lbR]
    $plx[z+1] = barindex[lbR]
    $priceL[z+1] = low[lbR]
    //drawpoint(barindex[lbR],osc[lbR],2)coloured("blue",50)
    z = z + 1
    endif
    //-----pivots high
    if osc < osc[lbR] and highest[lbR](osc)<osc[lbR] and osc[lbR]>highest[lbL](osc)[lbR+1] then
    $ph[t+1]=osc[lbR]
    $phx[t+1]=barindex[lbR]
    $priceH[t+1]=high[lbR]
    //drawpoint(barindex[lbR],osc[lbR],2)coloured("blue",50)
    t=t+1
    endif
    //-------------------------------------------------------------------------------//
    //-----Regular Bullish
    oscHL = $pl[z] > $pl[max(0,z-1)] and $plx[max(0,z)] - $plx[max(0,z-1)]<=80
    priceLL = low[lbR] < $priceL[max(0,z-1)]
    bullCond = priceLL and oscHL and isset($pl[z])
    //-----Hidden Bullish
    oscLL = $pl[z] < $pl[max(0,z-1)] and $plx[max(0,z)] - $plx[max(0,z-1)]<=80
    priceHL = low[lbR] > $priceL[max(0,z-1)]
    hiddenbullCond = priceHL and oscLL and isset($pl[z])
    //-----Regular Bearish
    oscLH = $ph[t] < $ph[max(t-1,0)] and $phx[t] - $phx[max(0,t-1)]<=80
    priceHH = high[lbR] > $priceH[max(0,t-1)]
    bearCond = priceHH and oscLH and isset($ph[t])
    //-----HiddenBearish
    oscHH = $ph[t] > $ph[max(t-1,0)] and $phx[t] - $phx[max(0,t-1)]<=80
    priceLH = high[lbR] < $priceH[max(0,t-1)]
    hiddendbearCond = priceLH and oscHH and isset($ph[t])
    
    if z<>z[1] and bullCond and plotdivergences then
    drawsegment($plx[max(0,z-1)],$pl[max(0,z-1)],$plx[z],$pl[z])coloured("green")
    drawtext("Bull",$plx[z],$pl[z]-0.25*tr)coloured("green")
    elsif z<>z[1] and hiddenbullCond and plothiddendiv  then
    drawsegment($plx[max(0,z-1)],$pl[max(0,z-1)],$plx[z],$pl[z])coloured("green",50)
    drawtext("H.Bull",$plx[z],$pl[z]-0.25*tr)coloured("green",80)
    elsif t<>t[1] and bearCond and plotdivergences then
    drawsegment($phx[max(0,t-1)],$ph[max(0,t-1)],$phx[t],$ph[t])coloured("red")
    drawtext("Bear",$phx[t],$ph[t]+0.25*tr)coloured("red")
    elsif t<>t[1] and hiddendbearCond and plothiddendiv then
    drawsegment($phx[max(0,t-1)],$ph[max(0,t-1)],$phx[t],$ph[t])coloured("red",50)
    drawtext("H.Bear",$phx[t],$ph[t]+0.25*tr)coloured("red",80)
    endif
    //-------------------------------------------------------------------------------//
    //-------------------------------------------------------------------------------//
    return zScore as "Z-Score"coloured(r,g,b)style(line,1),zma as "Avg Z-Score"coloured(r,g,b)style(line,1),0 as "0" coloured("gray"),obLevel as "Overbought"coloured(255,17,0),osLevel as "Overshold"coloured(0,255,187)
    
    #231628 quote
    Msport71
    Participant
    Junior

    Ivan,

    grazie e mille come sempre.

    Un saludo cordial

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

traduzione codice TW WaveTrend Ribbon


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 Msport71
1 year, 10 months ago.

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