Conversion of Jurik DMX Histogram Indicator from Trading View
Forums › ProRealTime English forum › ProBuilder support › Conversion of Jurik DMX Histogram Indicator from Trading View
- This topic has 2 replies, 2 voices, and was last updated 6 months ago by Ξ3.
-
-
01/17/2024 at 12:17 PM #226461
Please could you convert the below Trading View code found on the following website: Jurik DMX Histogram [Loxx] — Indicator by loxx — TradingView
Jurik DMX Histogram is the ultra-smooth, low lag version of your classic DMI indicator.
//@version=5
indicator(title=”Jurik DMX Histogram [Loxx]”, shorttitle=”JDMXH [Loxx]”, timeframe=””, timeframe_gaps=true, overlay = false)greencolor = #2DD204
redcolor = #D2042D
bluecolor = #042dd2lightgreencolor = #96E881
lightredcolor = #DF4F6C
lightbluecolor = #4f6cdfdarkGreenColor = #1B7E02
darkRedColor = #93021F
darkBlueColor = #021f93_f_hp(_src, max_len) =>
var c = 360 * math.pi / 180
_alpha = (1 – math.sin(c / max_len)) / math.cos(c / max_len)
_hp = 0.0
_hp := 0.5 * (1 + _alpha) * (_src – nz(_src[1])) + _alpha * nz(_hp[1])
_hp_f_ess(_src, _len) =>
var s = 1.414
_a = math.exp(-s * math.pi / _len)
_b = 2 * _a * math.cos(s * math.pi / _len)
_c2 = _b
_c3 = -_a * _a
_c1 = 1 – _c2 – _c3
_out = 0.0
_out := _c1 * (_src + nz(_src[1])) / 2 + _c2 * nz(_out[1], nz(_src[1], _src)) + _c3 * nz(_out[2], nz(_src[2], nz(_src[1], _src)))
_out_auto_dom(src, min_len, max_len, ave_len) =>
var c = 2 * math.pi
var s = 1.414
avglen = ave_lenfilt = _f_ess(_f_hp(src, max_len), min_len)
arr_size = max_len * 2var corr = array.new_float(arr_size, initial_value=0)
var cospart = array.new_float(arr_size, initial_value=0)
var sinpart = array.new_float(arr_size, initial_value=0)
var sqsum = array.new_float(arr_size, initial_value=0)
var r1 = array.new_float(arr_size, initial_value=0)
var r2 = array.new_float(arr_size, initial_value=0)
var pwr = array.new_float(arr_size, initial_value=0)for lag = 0 to max_len by 1
m = avglen == 0 ? lag : avglen
Sx = 0.0, Sy = 0.0, Sxx = 0.0, Syy = 0.0, Sxy = 0.0
for i = 0 to m – 1 by 1
x = nz(filt[i])
y = nz(filt[lag + i])
Sx += x
Sy += y
Sxx += x * x
Sxy += x * y
Syy += y * y
Syy
if (m * Sxx – Sx * Sx) * (m * Syy – Sy * Sy) > 0
array.set(corr, lag, (m * Sxy – Sx * Sy) / math.sqrt((m * Sxx – Sx * Sx) * (m * Syy – Sy * Sy)))for period = min_len to max_len by 1
array.set(cospart, period, 0)
array.set(sinpart, period, 0)
for n = ave_len to max_len by 1
array.set(cospart, period, nz(array.get(cospart, period)) + nz(array.get(corr, n)) * math.cos(c * n / period))
array.set(sinpart, period, nz(array.get(sinpart, period)) + nz(array.get(corr, n)) * math.sin(c * n / period))
array.set(sqsum, period, math.pow(nz(array.get(cospart, period)), 2) + math.pow(nz(array.get(sinpart, period)), 2))for period = min_len to max_len by 1
array.set(r2, period, nz(array.get(r1, period)))
array.set(r1, period, 0.2 * math.pow(nz(array.get(sqsum, period)), 2) + 0.8 * nz(array.get(r2, period)))maxpwr = 0.0
for period = min_len to max_len by 1
if nz(array.get(r1, period)) > maxpwr
maxpwr := nz(array.get(r1, period))for period = ave_len to max_len by 1
array.set(pwr, period, nz(array.get(r1, period)) / maxpwr)dominantcycle = 0.0, peakpwr = 0.0
for period = min_len to max_len by 1
if nz(array.get(pwr, period)) > peakpwr
peakpwr := nz(array.get(pwr, period))spx = 0.0, sp = 0.0
for period = min_len to max_len by 1
if peakpwr >= 0.25 and nz(array.get(pwr, period)) >= 0.25
spx += period * nz(array.get(pwr, period))
sp += nz(array.get(pwr, period))dominantcycle := sp != 0 ? spx / sp : dominantcycle
dominantcycle := sp < 0.25 ? dominantcycle[1] : dominantcycle
dominantcycle := dominantcycle < 1 ? 1 : dominantcycle
dom_in = math.min(math.max(dominantcycle, min_len), max_len)
dom_in_a_jurik_filt(src, len, phase) =>
len1 = math.max(math.log(math.sqrt(0.5 * (len-1))) / math.log(2.0) + 2.0, 0)
pow1 = math.max(len1 – 2.0, 0.5)
volty = 7.0, avolty = 9.0, vsum = 8.0, bsmax = 5.0, bsmin = 6.0, avgLen = 65del1 = src – nz(bsmax[1])
del2 = src – nz(bsmin[1])div = 1.0 / (10.0 + 10.0 * (math.min(math.max(len-10, 0), 100)) / 100)
volty := math.abs(del1) > math.abs(del2) ? math.abs(del1) : math.abs(del2)
vsum := nz(vsum[1]) + div * (volty – nz(volty[10]))temp_avg = ta.sma(vsum, avgLen)
y = bar_index + 1
if(y <= avgLen + 1)
avolty := nz(avolty[1]) + 2.0 * (vsum – nz(avolty[1])) / (avgLen + 1)
else
avolty := temp_avgdVolty = avolty > 0 ? volty / avolty : 0
dVolty := dVolty > math.pow(len1, 1.0/pow1) ? math.pow(len1, 1.0/pow1) : dVolty
dVolty := dVolty < 1 ? 1 : dVolty
pow2 = math.pow(dVolty, pow1)
len2 = math.sqrt(0.5 * (len – 1)) * len1
Kv = math.pow(len2 / (len2 + 1), math.sqrt(pow2))bsmax := del1 > 0 ? src : src – Kv * del1
bsmin := del2 < 0 ? src : src – Kv * del2phaseRatio = phase < -100 ? 0.5 : phase > 100 ? 2.5 : phase / 100 + 1.5
beta = 0.45 * (len – 1) / (0.45 * (len – 1) + 2)
alpha = math.pow(beta, pow2)
jma1 = 0.0, e0 = 0.0, e1 = 0.0, e2 = 0.0
e0 := (1 – alpha) * src + alpha * nz(e0[1])
e1 := (src – e0) * (1 – beta) + beta * nz(e1[1])
e2 := (e0 + phaseRatio * e1 – nz(jma1[1])) * math.pow(1 – alpha, 2) + math.pow(alpha, 2) * nz(e2[1])
jma1 := e2 + nz(jma1[1])
jma1adapt = input.string(“Fixed”, “Calculation type”, options = [“Fixed”, “Autocorrelation Adaptive”], group = “Basic Settings”)
len = input.int(32, minval=1, title=”Length”, group = “Basic Settings”)
phs = input.int(0, title= “Jurik Phase”, group = “Basic Settings”)
siglen = input.int(5, minval=1, title=”Signal Smoothing Length”, group = “Basic Settings”)auto_src = input.source(close, title=’JMA Source’, group = “Autocorrelation Periodgram Algorithm”)
auto_min = input.int(8, minval = 1, title=’JMA Min Length’, group = “Autocorrelation Periodgram Algorithm”)
auto_max = input.int(50, minval = 1, title=’JMA Max Length’, group = “Autocorrelation Periodgram Algorithm”)
auto_avg = input.int(32, minval = 1, title=’JMA Average Length’, group = “Autocorrelation Periodgram Algorithm”)colorbars = input.bool(false, “Color bars?”, group = “UI Options”)
auto = _auto_dom(auto_src, auto_min, auto_max, auto_avg)
out = adapt == “Fixed” ? len : int(auto) < 1 ? 1 : int(auto)up = ta.change(high)
down = -ta.change(low)plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)trur = _a_jurik_filt(ta.tr, out, phs)
plus = fixnan(100 * _a_jurik_filt(plusDM, out, phs) / trur)
minus = fixnan(100 * _a_jurik_filt(minusDM, out, phs) / trur)trigger = plus-minus
signal = _a_jurik_filt(trigger, siglen, phs)colorout =
trigger >= 0 and trigger >= signal ? greencolor :
trigger >= 0 and trigger < signal ? lightgreencolor :
trigger < 0 and trigger < signal ? redcolor :
lightredcolorplot(trigger, color=colorout, title = “DMX”, style = plot.style_histogram)
plot(trigger, color = trigger >= 0 ? darkGreenColor : darkRedColor , title = “DMX”, linewidth = 1)
plot(signal, color = color.white, title = “Signal”, linewidth = 2)barcolor(colorbars ? colorout : na)
03/13/2024 at 1:46 PM #229698Hi,
Here it’s the code: https://www.prorealcode.com/prorealtime-indicators/jurik-dmx-histogram-indicator/PRC_Jurik DMX Histogram123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386//PRC_Jurik DMX Histogram//version = 0//13.03.24//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge////////////////////////////////////////////////////////////////////////inputs////////////////////////////////////siglen = 5 // Signal Smoothing lengthphs = 0 //Jurik Phaselen = 32 //Length////////////////////////////////////////////len = MAX(len, 1)len1 = max(log(sqrt(0.5*(len-1)))/log(2)+2,0)Pow1 = max(len1-2,0.5)avglen = 65//////PlusDM and MinusDM////////////////////if barindex=0 thenup = highdown = highelseup = high-high[1]down = -(low-low[1])endifif up > down and up > 0 thenplusDM = upelseplusDM = 0endifif down > up and down > 0 thenminusDM = downelseminusDM = 0endif//////////////////////////////////TRUR - JURIK AVERAGEIF BarIndex < avglen+1 THENFilt0tr = trFilt1tr = trtrur = trbsmaxtr = 0bsmintr = 0vsumtr = 0avoltytr = 0ELSEdel1tr = tr-bsmaxtr[1]del2tr = tr-bsmintr[1]div = 1/(10+10*(min(max(len-10,0),100))/100)if abs(del1tr)>abs(del2tr) thenvoltytr = abs(del1tr)elsevoltytr = abs(del2tr)endifvsumtr = vsumtr[1]+div*(voltytr-voltytr[10])tempavgtr = average[avglen](vsumtr)y= barindex+1if (y <= avglen+1) thenavoltytr = avoltytr[1]+2*(vsumtr-avoltytr[1])/(avglen+1)elseavoltytr = tempavgtrendifif avoltytr > 0 thendvoltytr = voltytr/avoltytrelsedvoltytr = 0endifif dvoltytr > pow(len1,1/pow1) thendvoltytr = pow(len1,1/pow1)elsedvoltytr = dvoltytrendifif dvoltytr < 1 thendvoltytr= 1elsedvoltytr = dvoltytrendifpow2tr = pow(dvoltytr,pow1)len2 = sqrt(0.5*(len-1))*len1kvtr = pow(len2/(len2+1),sqrt(pow2tr))if del1tr > 0 thenbsmaxtr = trelsebsmaxtr = tr - kvtr*del1trendifif del2tr < 0 thenbsmintr = trelsebsmintr = tr - kvtr*del2trendifif phs < -100 thenphaseratio = 0.5elsif phs > 100 thenphaseratio = 2.5elsephaseratio =phs/100+1.5endifbeta = 0.45 * (len - 1) / (0.45 * (len - 1) + 2)alphatr = pow(beta,pow2tr)Filt0tr = (1 - alphatr) * tr + alphatr * Filt0tr[1]Det0tr = (tr - Filt0tr[0]) * (1 - beta) + beta * Det0tr[1]Filt1tr = Filt0tr[0] + phaseratio * Det0tr[0]Det1tr = (Filt1tr[0] - trur[1]) * ((1 - alphatr) * (1 - alphatr)) + (alphatr * alphatr) * Det1tr[1]trur = trur[1] + Det1tr[0]ENDIF/////PlusIF BarIndex < avglen+1 THENFilt0pl = 0Filt1pl = 0jurikPlus = 0bsmaxpl = 0bsminpl = 0vsumpl = 0avoltypl = 0ELSEdel1pl = plusDM-bsmaxpl[1]del2pl = plusDM-bsminpl[1]div = 1/(10+10*(min(max(len-10,0),100))/100)if abs(del1pl)>abs(del2pl) thenvoltypl = abs(del1pl)elsevoltypl = abs(del2pl)endifvsumpl = vsumpl[1]+div*(voltypl-voltypl[10])tempavgpl = average[avglen](vsumpl)y= barindex+1if (y <= avglen+1) thenavoltypl = avoltypl[1]+2*(vsumpl-avoltypl[1])/(avglen+1)elseavoltypl = tempavgplendifif avoltypl > 0 thendvoltypl = voltypl/avoltyplelsedvoltypl = 0endifif dvoltypl > pow(len1,1/pow1) thendvoltypl = pow(len1,1/pow1)elsedvoltypl = dvoltyplendifif dvoltypl < 1 thendvoltypl= 1elsedvoltypl = dvoltyplendifpow2pl = pow(dvoltypl,pow1)len2 = sqrt(0.5*(len-1))*len1kvpl = pow(len2/(len2+1),sqrt(pow2pl))if del1pl > 0 thenbsmaxpl = plusDMelsebsmaxpl = plusDM - kvpl*del1plendifif del2pl < 0 thenbsminpl = plusDMelsebsminpl = plusDM - kvpl*del2plendifif phs < -100 thenphaseratio = 0.5elsif phs > 100 thenphaseratio = 2.5elsephaseratio =phs/100+1.5endifbeta = 0.45 * (len - 1) / (0.45 * (len - 1) + 2)alphapl = pow(beta,pow2pl)Filt0pl = (1 - alphapl) * plusDM + alphapl * Filt0pl[1]Det0pl = (plusDM - Filt0pl[0]) * (1 - beta) + beta * Det0pl[1]Filt1pl = Filt0pl[0] + phaseratio * Det0pl[0]Det1pl = (Filt1pl[0] - jurikPlus[1]) * ((1 - alphapl) * (1 - alphapl)) + (alphapl * alphapl) * Det1pl[1]jurikPlus = jurikPlus[1] + Det1pl[0]ENDIFplus = (100*jurikPlus/trur)////////////////////////////////////////////////////minusIF BarIndex < avglen+1 THENFilt0mn = 0Filt1mn = 0jurikMinus = 0bsmaxmn = 0bsminmn = 0vsummn = 0avoltymn = 0ELSEdel1mn = minusDM-bsmaxmn[1]del2mn = minusDM-bsminmn[1]div = 1/(10+10*(min(max(len-10,0),100))/100)if abs(del1mn)>abs(del2mn) thenvoltymn = abs(del1mn)elsevoltymn = abs(del2mn)endifvsummn = vsummn[1]+div*(voltymn-voltymn[10])tempavgmn = average[avglen](vsummn)y= barindex+1if (y <= avglen+1) thenavoltymn = avoltymn[1]+2*(vsummn-avoltymn[1])/(avglen+1)elseavoltymn = tempavgmnendifif avoltymn > 0 thendvoltymn = voltymn/avoltymnelsedvoltymn = 0endifif dvoltymn > pow(len1,1/pow1) thendvoltymn = pow(len1,1/pow1)elsedvoltymn = dvoltymnendifif dvoltymn < 1 thendvoltymn= 1elsedvoltymn = dvoltymnendifpow2mn = pow(dvoltymn,pow1)len2 = sqrt(0.5*(len-1))*len1kvmn = pow(len2/(len2+1),sqrt(pow2mn))if del1mn > 0 thenbsmaxmn = minusDMelsebsmaxmn = minusDM - kvmn*del1mnendifif del2mn < 0 thenbsminmn = minusDMelsebsminmn = minusDM - kvmn*del2mnendifif phs < -100 thenphaseratio = 0.5elsif phs > 100 thenphaseratio = 2.5elsephaseratio =phs/100+1.5endifbeta = 0.45 * (len - 1) / (0.45 * (len - 1) + 2)alphamn = pow(beta,pow2mn)Filt0mn = (1 - alphamn) * minusDM + alphamn * Filt0mn[1]Det0mn = (minusDM - Filt0mn[0]) * (1 - beta) + beta * Det0mn[1]Filt1mn = Filt0mn[0] + phaseratio * Det0mn[0]Det1mn = (Filt1mn[0] - jurikMinus[1]) * ((1 - alphamn) * (1 - alphamn)) + (alphamn * alphamn) * Det1mn[1]jurikMinus = jurikMinus[1] + Det1mn[0]ENDIFminus = 100*jurikMinus/trur/////////////////////////////////////////////////////////////////////Triggertrigger = plus-minus//////////////////////////////////////////////////////////////////signalsiglen = MAX(siglen, 1)len1 = max(log(sqrt(0.5*(siglen-1)))/log(2)+2,0)Pow1 = max(len1-2,0.5)avglen = 65IF BarIndex < avglen+1 THENFilt0 = 0Filt1 = 0signal = 0bsmax = 0bsmin = 0vsum = 0avolty = 0ELSEdel1 = trigger-bsmax[1]del2 = trigger-bsmin[1]div = 1/(10+10*(min(max(siglen-10,0),100))/100)if abs(del1)>abs(del2) thenvolty = abs(del1)elsevolty = abs(del2)endifvsum = vsum[1]+div*(volty-volty[10])tempavg = average[avglen](vsum)y= barindex+1if (y <= avglen+1) thenavolty = avolty[1]+2*(vsum-avolty[1])/(avglen+1)elseavolty = tempavgendifif avolty > 0 thendvolty = volty/avoltyelsedvolty = 0endifif dvolty > pow(len1,1/pow1) thendvolty = pow(len1,1/pow1)elsedvolty = dvoltyendifif dvolty < 1 thendvolty= 1elsedvolty = dvoltyendifpow2 = pow(dvolty,pow1)len2 = sqrt(0.5*(siglen-1))*len1kv = pow(len2/(len2+1),sqrt(pow2))if del1 > 0 thenbsmax = triggerelsebsmax = trigger - kv*del1endifif del2 < 0 thenbsmin = triggerelsebsmin = trigger - kv*del2endifif phs < -100 thenphaseratio = 0.5elsif phs > 100 thenphaseratio = 2.5elsephaseratio =phs/100+1.5endifbeta = 0.45 * (siglen - 1) / (0.45 * (siglen - 1) + 2)alpha = pow(beta,pow2)Filt0 = (1 - alpha) * trigger + alpha * Filt0[1]Det0 = (trigger - Filt0[0]) * (1 - beta) + beta * Det0[1]Filt1 = Filt0[0] + phaseratio * Det0[0]Det1 = (Filt1[0] - signal[1]) * ((1 - alpha) * (1 - alpha)) + (alpha * alpha) * Det1[1]signal = signal[1] + Det1[0]ENDIF//////////////////////////////////////////////////////////colorif trigger >=0 and trigger>=signal thenr=0g=120elsif trigger >=0 and trigger<signal thenr=0g=255elsif trigger <0 and trigger<signal thenr=120g=0elser=255g=0endifreturn trigger as "Histo DMX"coloured(r,g,0)style(histogram),trigger as "DMX" style(line), signal as "Signal"coloured("white")style(line,2)1 user thanked author for this post.
03/14/2024 at 7:12 AM #229742 -
AuthorPosts
Find exclusive trading pro-tools on