Traduzione codice TW Hull Butterfly
Forums › ProRealTime forum Italiano › Supporto ProBuilder › Traduzione codice TW Hull Butterfly
- This topic has 2 replies, 3 voices, and was last updated 3 days ago by
LucasBest.
-
-
02/17/2025 at 1:24 PM #243946
Buongiorno,
chiedo cortese traduzione del seguente codice che mi sembra interessante.
Grazie per l’aiuto.
https://it.tradingview.com/script/xtuVIaa8-Hull-Butterfly-Oscillator-LuxAlgo/
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo//@version=5
indicator(“Hull Butterfly Oscillator [LuxAlgo]”, “Hull Butterfly Oscillator [LuxAlgo]”)
//—————————————————————————–}
//Settings
//—————————————————-a————————-{
length = input(14)mult = input(2., ‘Levels Multiplier’)
src = input(close)
//Style
bull_css_0 = input.color(color.new(#0cb51a, 50), ‘Bullish Gradient’
, inline = ‘inline0’
, group = ‘Style’)bull_css_1 = input.color(#0cb51a, ”
, inline = ‘inline0’
, group = ‘Style’)bear_css_0 = input.color(color.new(#ff1100, 50), ‘Bearish Gradient’
, inline = ‘inline1’
, group = ‘Style’)bear_css_1 = input.color(#ff1100, ”
, inline = ‘inline1’
, group = ‘Style’)//—————————————————————————–}
//Normalization variables
//—————————————————————————–{
var short_len = int(length / 2)
var hull_len = int(math.sqrt(length))var den1 = short_len * (short_len + 1) / 2
var den2 = length * (length + 1) / 2
var den3 = hull_len * (hull_len + 1) / 2//—————————————————————————–}
//Hull coefficients
//—————————————————————————–{
var lcwa_coeffs = array.new_float(hull_len, 0)
var hull_coeffs = array.new_float(0)if barstate.isfirst
//Linearly combined WMA coeffs
for i = 0 to length-1
sum1 = math.max(short_len – i, 0)
sum2 = length – iarray.unshift(lcwa_coeffs, 2 * (sum1 / den1) – (sum2 / den2))
//Zero padding of linearly combined WMA coeffs
for i = 0 to hull_len-2
array.unshift(lcwa_coeffs, 0)//WMA convolution of linearly combined WMA coeffs
for i = hull_len to array.size(lcwa_coeffs)-1
sum3 = 0.
for j = i-hull_len to i-1
sum3 += array.get(lcwa_coeffs, j) * (i – j)array.unshift(hull_coeffs, sum3 / den3)
//—————————————————————————–}
//Hull squeeze oscillator
//—————————————————————————–{
var os = 0
var len = array.size(hull_coeffs)-1
hma = 0.
inv_hma = 0.for i = 0 to len
hma += src[i] * array.get(hull_coeffs, i)
inv_hma += src[len-i] * array.get(hull_coeffs, i)hso = hma – inv_hma
cmean = ta.cum(math.abs(hso)) / bar_index * mult
os := ta.cross(hso, cmean) or ta.cross(hso, -cmean) ? 0
: hso < hso[1] and hso > cmean ? -1
: hso > hso[1] and hso < -cmean ? 1
: os//—————————————————————————–}
//Plot
//—————————————————————————–{
//Colors
css0 = color.from_gradient(hso, 0, cmean, bull_css_0, bull_css_1)
css1 = color.from_gradient(hso, -cmean, 0, bear_css_1, bear_css_0)
css = hso > 0 ? css0 : css1//Oscillator line/histogram
plot(hso, ‘Hull Butterfly’, css
, style = plot.style_histogram)plot(hso, ‘Hull Butterfly’, chart.fg_color)
//Dots
plot(os > os[1] and os == 1 ? hso : na, ‘Bullish Dot’
, bull_css_1
, 2
, plot.style_circles)plot(os < os[1] and os == -1 ? hso : na, ‘Bearish Dot’
, bear_css_1
, 2
, plot.style_circles)//Levels
plot(cmean, color = color.gray, editable = false)plot(cmean / 2, color = color.gray, editable = false)
plot(-cmean / 2, color = color.gray, editable = false)
plot(-cmean, color = color.gray, editable = false)
//—————————————————————————–}
02/17/2025 at 4:30 PM #243949123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103//--------------------------------------------//// PRC_Hull Butterfly Oscillator// Version = 0// 17.02.25// Translated by Iván González @ www.prorealcode.com// Sharing ProRealTime knowledge//--------------------------------------------////--------------------------------------------//// Input Parameters//--------------------------------------------//oscPeriod = 14 // Oscillator lengthmult = 2.0 // Level multipliersrc = close // Data source (closing price)//--------------------------------------------//// Normalized Variable Definitions//--------------------------------------------//shortLen = round(oscPeriod / 2)hullLen = round(sqrt(oscPeriod))den1 = shortLen * (shortLen + 1) / 2den2 = oscPeriod * (oscPeriod + 1) / 2den3 = hullLen * (hullLen + 1) / 2//--------------------------------------------//// Hull Coefficients Calculation//--------------------------------------------//// Calculation of linearly combined WMA coefficientsFOR i = 0 TO oscPeriod-1 DOsum1 = max(shortLen - i, 0)sum2 = oscPeriod - i$lcwaCoeffs[i] = 2 * (sum1 / den1) - (sum2 / den2)NEXT// Zero padding for alignmentFOR i = 0 TO hullLen-2 DO$lcwaCoeffs[i] = 0NEXT// Convolution of the linearly combined WMAFOR i = hullLen TO oscPeriod-1 DOsum3 = 0FOR j = i-hullLen TO i-1 DOsum3 = sum3 + $lcwaCoeffs[j] * (i - j)NEXT$hullCoeffs[i] = sum3 / den3NEXT//--------------------------------------------//// Hull Squeeze Oscillator Calculation//--------------------------------------------//hma = 0invHma = 0len = oscPeriod - 1FOR i = 0 TO len DOhma = hma + src[i] * $hullCoeffs[i]invHma = invHma + src[len-i] * $hullCoeffs[i]NEXThso = hma - invHma// Cumulative mean calculation for level normalizationcmean = CUMSUM(ABS(hso)) / barindex * mult// Oscillator signal calculation based on crosses over levelsIF (hso CROSSES OVER cmean OR hso CROSSES UNDER cmean) OR (hso CROSSES OVER -cmean OR hso CROSSES UNDER -cmean) THENos = 0ELSIF hso < hso[1] AND hso > cmean THENos = -1ELSIF hso > hso[1] AND hso < -cmean THENos = 1ENDIF//--------------------------------------------//// Define Colors//--------------------------------------------//IF hso > 0 THENr = 0g = 181b = 26 // GreenELSEr = 255g = 17b = 0 // RedENDIF//--------------------------------------------//// Draw Reversal Points//--------------------------------------------//IF os > os[1] AND os = 1 THENDRAWTEXT("●", barindex, hso, Dialog, Bold, 14) COLOURED(0, 181, 26, 255) // Green bullish dotENDIFIF os < os[1] AND os = -1 THENDRAWTEXT("●", barindex, hso, Dialog, Bold, 14) COLOURED(255, 17, 0, 255) // Red bearish dotENDIF//--------------------------------------------//// Plot//--------------------------------------------//RETURN hso AS "Hull Butterfly" STYLE(HISTOGRAM) COLOURED(r, g, b),cmean AS "Nivel 100%" STYLE(LINE) COLOURED(128, 128, 128),cmean / 2 AS "Nivel 50%" STYLE(LINE) COLOURED(128, 128, 128),-cmean / 2 AS "Nivel -50%" STYLE(LINE) COLOURED(128, 128, 128),-cmean AS "Nivel -100%" STYLE(LINE) COLOURED(128, 128, 128)1 user thanked author for this post.
02/17/2025 at 11:17 PM #243963Pubblico anche la traduzione che ho fatto di questo indicatore qualche mese fa, così come il file itf
Hull Butterfly Oscillator12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394// ProRealTime Code for Hull Butterfly Oscillator [LuxAlgo]Src = customclose // Direct assignment in ProBuilder// Normalization variablesonce ShortLen = floor(Length / 2)once HullLen = floor(sqrt(Length))once Den1 = ShortLen * (ShortLen + 1) / 2once Den2 = Length * (Length + 1) / 2once Den3 = HullLen * (HullLen + 1) / 2once init = 0If init = 0 thenFor i = 0 to Length - 1 dosum1 = max(ShortLen - i, 0)sum2 = Length - i$lcwaCoeffs[LastSet($lcwaCoeffs)+1] = 2 * (sum1 / Den1) - (sum2 / Den2)nextFor i = 0 to HullLen-2 do$lcwaCoeffs[LastSet($lcwaCoeffs)+1] = 0nextFor i = HullLen to LastSet($lcwaCoeffs) dosum3 = 0For j = i-HullLen to i-1 dosum3 = sum3 + $lcwaCoeffs[LastSet($lcwaCoeffs)-j]*(i - j)next$HullCoeffs[lastset($HullCoeffs)+1] = sum3 / den3nextinit = 1Lag = barindex-1hso = 0hsocum = 0NBar = 0EndIfIf init = 1 thenonce os = 0once len = lastset($HullCoeffs)hma = 0invhma = 0For i = 0 to len dohma = hma + src[i] * $HullCoeffs[lastset($hullcoeffs)-i]invhma = invhma + src[len-i] * $HullCoeffs[lastset($hullcoeffs)-i]nexthso = hma - invhma//hsocum = abs(hso)if abs(hso) > 0 thenhsocum = hsocum + abs(hso)NBar = Nbar + 1endifcmean = Mult * hsocum / NBaros = 0If hso crosses over cmean or hso crosses under -cmean thenos = 0Elsif hso < hso[1] and hso > cmean thenos = -1Elsif hso > hso[1] and hso < -cmean thenos = 1EndIfif hso > 0 thencolR = 0colG = 128colB = 0elsecolR = 178colG = 34colB = 34endifIf os > os[1] and os = 1 thendrawpoint(barindex,hso,5) coloured("green",255)endifIf os < os[1] and os = -1 thendrawpoint(barindex,hso,5) coloured("red",255)endifEndifReturn cmean style(line,1) coloured("gray"), -cmean style(line,1) coloured("gray"), cmean/2 style(line,1) coloured("gray"), -cmean/2 style(line,1) coloured("gray"), hso style(histogram,1) coloured(colR,colG,colB,255), hso style(line,3) coloured("black",255)1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on