traduzione codice TW WaveTrend Ribbon
Forums › ProRealTime forum Italiano › Supporto ProBuilder › traduzione codice TW WaveTrend Ribbon
- This topic has 2 replies, 2 voices, and was last updated 8 months ago by Msport71.
-
-
04/17/2024 at 9:10 AM #231608
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 = zScorelbR = 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”)04/17/2024 at 5:25 PM #231627Eccolo qui: https://www.prorealcode.com/prorealtime-indicators/wavetrend-ribbon-indicator-to-detect-market-reversals/
PRC_WaveTrend Ribbon123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117//-------------------------------------------------------------------------------////PRC_WaveTrend Ribbon//version = 0//17.04.24//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//-------------------------------------------------------------------------------////-----Inputs--------------------------------------------------------------------////-----WaveTrendn1=10//Channel lengthn2=21//Average lengthoblevel=2//Overbought Z-score leveloslevel=-2//Oversold Z-score levellengthZ=20//Length for Z-score CalculationhmaLength=12//HMA Length for Z-score SmoothingwmaLength=3//WMA Length for Z-Score//-----Divergencesplotdivergences=1//show bullish and bearish divergencesplothiddendiv=1//show hidden bullish and bearish divergences//-----PivotslbR=1//lookback RightlbL=20//lookback Left//-------------------------------------------------------------------------------////-----WaveTrend Calculation-----------------------------------------------------//ap=(high+low+close)/3esa=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)/stdDevWTzScore=hullaverage[hmaLength](zScoreaux)zma=weightedaverage[wmaLength](zScore)//-------------------------------------------------------------------------------////-----Colors--------------------------------------------------------------------//if zScore > 0 thenr=0g=255b=187elser=255g=17b=0endifcolorbetween(zScore,zma,r,g,b,70)//-------------------------------------------------------------------------------////-----Overbought/Oversold conditions--------------------------------------------//obCondition = zScore > obLevelosCondition = zScore < osLevelif obCondition thenbackgroundcolor(255,17,0,30)elsif osCondition thenbackgroundcolor(0,255,187,30)endifif obCondition and zScore[1]>zScore thendrawtext("▼",barindex,3)coloured("red")elsif osCondition and zScore[1]<zScore thendrawtext("▲",barindex,-3)coloured("green")elsif zscore crosses over zma or zscore crosses under zma thendrawpoint(barindex,zma,2)coloured(r,g,b)endif//-------------------------------------------------------------------------------////-----Pivots High-Low Z-Score---------------------------------------------------//osc=zScore//-----pivots lowif 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 + 1endif//-----pivots highif 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+1endif//-------------------------------------------------------------------------------////-----Regular BullishoscHL = $pl[z] > $pl[max(0,z-1)] and $plx[max(0,z)] - $plx[max(0,z-1)]<=80priceLL = low[lbR] < $priceL[max(0,z-1)]bullCond = priceLL and oscHL and isset($pl[z])//-----Hidden BullishoscLL = $pl[z] < $pl[max(0,z-1)] and $plx[max(0,z)] - $plx[max(0,z-1)]<=80priceHL = low[lbR] > $priceL[max(0,z-1)]hiddenbullCond = priceHL and oscLL and isset($pl[z])//-----Regular BearishoscLH = $ph[t] < $ph[max(t-1,0)] and $phx[t] - $phx[max(0,t-1)]<=80priceHH = high[lbR] > $priceH[max(0,t-1)]bearCond = priceHH and oscLH and isset($ph[t])//-----HiddenBearishoscHH = $ph[t] > $ph[max(t-1,0)] and $phx[t] - $phx[max(0,t-1)]<=80priceLH = high[lbR] < $priceH[max(0,t-1)]hiddendbearCond = priceLH and oscHH and isset($ph[t])if z<>z[1] and bullCond and plotdivergences thendrawsegment($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 thendrawsegment($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 thendrawsegment($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 thendrawsegment($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)04/17/2024 at 5:57 PM #231628 -
AuthorPosts
Find exclusive trading pro-tools on