ultra trend indicator conversion from mq4 to prt
Forums › ProRealTime English forum › ProBuilder support › ultra trend indicator conversion from mq4 to prt
- This topic has 16 replies, 7 voices, and was last updated 6 months ago by yas.
-
-
07/08/2020 at 8:34 PM #13878507/09/2020 at 8:55 AM #13881207/09/2020 at 1:59 PM #13884407/09/2020 at 2:48 PM #138850
I have found this, it should be the original source file.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181//+------------------------------------------------------------------#property copyright "mladen"#property link "mladenfx@gmail.com"#property description "Ultra trend"//+------------------------------------------------------------------#property indicator_separate_window#property indicator_buffers 6#property indicator_plots 3#property indicator_label1 "Filling"#property indicator_type1 DRAW_FILLING#property indicator_color1 clrLightGreen,clrWheat#property indicator_label2 "Ultra trend +"#property indicator_type2 DRAW_COLOR_LINE#property indicator_color2 clrDarkGray,clrLimeGreen,clrOrange#property indicator_width2 3#property indicator_label3 "Ultra trend -"#property indicator_type3 DRAW_COLOR_LINE#property indicator_color3 clrDarkGray,clrLimeGreen,clrOrange#property indicator_width3 1//+------------------------------------------------------------------+//| Custom classes |//+------------------------------------------------------------------+class CJurikSmooth{private:int m_size;double m_wrk[][10];////---//public :CJurikSmooth(void) : m_size(0) { return; }~CJurikSmooth(void) { return; }double CalculateValue(double price,double length,double phase,int r,int bars){#define bsmax 5#define bsmin 6#define volty 7#define vsum 8#define avolty 9if (m_size!=bars) ArrayResize(m_wrk,bars); if (ArrayRange(m_wrk,0)!=bars) return(price); m_size=bars;if(r==0 || length<=1) { int k=0; for(; k<7; k++) m_wrk[r][k]=price; for(; k<10; k++) m_wrk[r][k]=0; return(price); }////---//double len1 = MathMax(MathLog(MathSqrt(0.5*(length-1)))/MathLog(2.0)+2.0,0);double pow1 = MathMax(len1-2.0,0.5);double del1 = price - m_wrk[r-1][bsmax];double del2 = price - m_wrk[r-1][bsmin];int forBar = MathMin(r,10);m_wrk[r][volty]=0;if(MathAbs(del1) > MathAbs(del2)) m_wrk[r][volty] = MathAbs(del1);if(MathAbs(del1) < MathAbs(del2)) m_wrk[r][volty] = MathAbs(del2);m_wrk[r][vsum]=m_wrk[r-1][vsum]+(m_wrk[r][volty]-m_wrk[r-forBar][volty])*0.1;////---//m_wrk[r][avolty]=m_wrk[r-1][avolty]+(2.0/(MathMax(4.0*length,30)+1.0))*(m_wrk[r][vsum]-m_wrk[r-1][avolty]);double dVolty=(m_wrk[r][avolty]>0) ? m_wrk[r][volty]/m_wrk[r][avolty]: 0;if(dVolty > MathPow(len1,1.0/pow1)) dVolty = MathPow(len1,1.0/pow1);if(dVolty < 1) dVolty = 1.0;////---//double pow2 = MathPow(dVolty, pow1);double len2 = MathSqrt(0.5*(length-1))*len1;double Kv = MathPow(len2/(len2+1), MathSqrt(pow2));if(del1 > 0) m_wrk[r][bsmax] = price; else m_wrk[r][bsmax] = price - Kv*del1;if(del2 < 0) m_wrk[r][bsmin] = price; else m_wrk[r][bsmin] = price - Kv*del2;////---//double corr = MathMax(MathMin(phase,100),-100)/100.0 + 1.5;double beta = 0.45*(length-1)/(0.45*(length-1)+2);double alpha = MathPow(beta,pow2);m_wrk[r][0] = price + alpha*(m_wrk[r-1][0]-price);m_wrk[r][1] = (price - m_wrk[r][0])*(1-beta) + beta*m_wrk[r-1][1];m_wrk[r][2] = (m_wrk[r][0] + corr*m_wrk[r][1]);m_wrk[r][3] = (m_wrk[r][2] - m_wrk[r-1][4])*MathPow((1-alpha),2) + MathPow(alpha,2)*m_wrk[r-1][3];m_wrk[r][4] = (m_wrk[r-1][4] + m_wrk[r][3]);////---//return(m_wrk[r][4]);#undef bsmax#undef bsmin#undef volty#undef vsum#undef avolty}};////--- input parameters//input int inpUtrPeriod = 3; // Start periodinput int inpProgression = 5; // Stepinput int inpInstances = 30; // Instancesinput int inpSmooth = 5; // Ultra trend smoothing periodinput int inpSmoothPhase = 100; // Ultra trend smoothing phase//--- buffers declarationsdouble fillu[],filld[],valp[],valpc[],valm[],valmc[];CJurikSmooth _iSmooth[];//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+int OnInit(){//--- indicator buffers mappingSetIndexBuffer(0,fillu,INDICATOR_DATA);SetIndexBuffer(1,filld,INDICATOR_DATA);SetIndexBuffer(2,valp,INDICATOR_DATA);SetIndexBuffer(3,valpc,INDICATOR_COLOR_INDEX);SetIndexBuffer(4,valm,INDICATOR_DATA);SetIndexBuffer(5,valmc,INDICATOR_COLOR_INDEX);ArrayResize(_iSmooth,inpInstances+3);PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);//--- indicator short nameIndicatorSetString(INDICATOR_SHORTNAME,"Ultra trend ("+(string)inpUtrPeriod+","+(string)inpProgression+","+(string)inpInstances+")");//---return (INIT_SUCCEEDED);}//+------------------------------------------------------------------+//| Custom indicator de-initialization function |//+------------------------------------------------------------------+void OnDeinit(const int reason){}//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[],const double &open[],const double &high[],const double &low[],const double &close[],const long &tick_volume[],const long &volume[],const int &spread[]){if(Bars(_Symbol,_Period)<rates_total) return(prev_calculated);int endLength=inpUtrPeriod+inpProgression*inpInstances;int i=(int)MathMax(prev_calculated-1,1); for(; i<rates_total && !_StopFlag; i++){double valueUp=0;double valueDn=0;for(int k=inpUtrPeriod,instance=2; k<=endLength && i>0; k+=inpProgression,instance++)if(_iSmooth[instance].CalculateValue(close[i-1],k,inpSmoothPhase,i-1,rates_total)<_iSmooth[instance].CalculateValue(close[i],k,inpSmoothPhase,i,rates_total))valueUp++;else valueDn++;valp[i] = _iSmooth[0].CalculateValue(valueUp,inpSmooth,inpSmoothPhase,i,rates_total);valm[i] = _iSmooth[1].CalculateValue(valueDn,inpSmooth,inpSmoothPhase,i,rates_total);valpc[i] = (valp[i]>valm[i]) ? 1 : 2;valmc[i] = valpc[i];fillu[i] = valp[i];filld[i] = valm[i];}return (i);}//+------------------------------------------------------------------+07/10/2020 at 3:56 PM #13896307/12/2020 at 8:10 AM #13904607/12/2020 at 8:58 AM #13904707/15/2020 at 9:07 AM #138964hello, mr.robertogozzi found this indicator ,that you asked for, in my suggestion jurik ma is used, can it be coded using hma or other ma’s for better usage
01/02/2024 at 9:28 AM #225899Bonjour Roberto meilleurs voeux pour 2024Avec toutes les nouveautés et progrès qu’il y a eu depuis ce temps .Peux-tu maintenant traduire ce code ?sinon existe t il un indicateur similaire??Hello Roberto best wishes for 2024 With all the new features and progress that has happened since then. Can you now translate this code? if not is there a similar indicator?
01/03/2024 at 12:30 PM #225929Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums. Thanks 🙂
Sorry, I still cannot and I don’t plan to study that language in the future.
01/03/2024 at 4:05 PM #225938Maybe as a starting point for a helping coder…
Jurik MA12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152//----------------------------//// JMA - Jurik Moving Average ////----------------------------////IF MAType = 25 THENPeriod=20Period = MAX(Period, 1)Series=Close// Pow = 5 ({ 1..10 })// R = 1.5 ({0.5..2.5})Pow1 = 4R = 1beta = 0.45 * (Period - 1) / (0.45 * (Period - 1) + 2)IF Pow1 = 1 THENalpha = betaELSIF Pow1 = 2 THENalpha = beta * betaELSIF Pow1 = 3 THENalpha = beta * beta * betaELSIF Pow1 = 4 THENalpha = beta * beta * beta * betaELSIF Pow1 = 5 THENalpha = beta * beta * beta * beta * betaELSIF Pow1 = 6 THENalpha = beta * beta * beta * beta * beta * betaELSIF Pow1 = 7 THENalpha = beta * beta * beta * beta * beta * beta * betaELSIF Pow1 = 8 THENalpha = beta * beta * beta * beta * beta * beta * beta * betaELSIF Pow1 = 9 THENalpha = beta * beta * beta * beta * beta * beta * beta * beta * betaELSIF Pow1 = 10 THENalpha = beta * beta * beta * beta * beta * beta * beta * beta * betaENDIFIF BarIndex = 0 THENFilt0 = SeriesFilt1 = SeriesAFR = SeriesELSEFilt0 = (1 - alpha) * Series + alpha * Filt0[1]Det0 = (Series - Filt0[0]) * (1 - beta) + beta * Det0[1]Filt1 = Filt0[0] + R * Det0[0]Det1 = (Filt1[0] - AFR[1]) * ((1 - alpha) * (1 - alpha)) + (alpha * alpha) * Det1[1]AFR = AFR[1] + Det1[0]ENDIFReturn AFR Coloured("Red")01/03/2024 at 7:09 PM #22594201/04/2024 at 4:12 PM #225954No, translation needs to be activated, it’s not automatically enabled.
05/23/2024 at 11:53 AM #232956Hi,
This is an aprox from the original code. I took jurik MA @JS in order to make the code faster.1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283defparam calculateonlastbars = 300//-----Inputs--------------------------------------------------//utrPeriod = 3progression = 5instances = 30smooth = 5smoothPhase = 100pow1=6//-------------------------------------------------------------//if barindex > utrPeriod + progression * instances thenvalp = 0valpc = 0valm = 0valmc = 0valueUp = 0valueDn = 0FOR k = utrPeriod TO (utrPeriod + progression * instances) DO//CalculateJurik(close[i-1], k, smoothPhase)src1=close[1]period1=max(k,1)beta1=0.45 * (Period1 - 1) / (0.45 * (Period1 - 1) + 2)alpha1=pow(beta1,pow1)corr1=max(min(smoothPhase,100),-100)/100+1.5filt01=(1-alpha1)*src1+alpha1*filt01[1]det01=(src1-filt01[0])*(1-beta1)+beta1*Det01[1]filt11=Filt01[0]+corr1*Det01[0]Det11=(Filt11[0]-jurik1[1])*((1-alpha1)*(1-alpha1))+(alpha1*alpha1)*Det11[1]jurik1=jurik1[1]+Det11[0]//CalculateJurik(close[i], k, smoothPhase)src2=close[0]period2 = MAX(k, 1)beta2 = 0.45 * (period2 - 1) / (0.45 * (period2 - 1) + 2)alpha2 = POW(beta2, pow1)corr2 = MAX(MIN(smoothPhase, 100), -100) / 100.0 + 1.5filt02 = (1 - alpha2) * src2 + alpha2 * filt02[1]det02 = (src2 - filt02) * (1 - beta2) + beta2 * det02[1]filt12 = filt02 + corr2 * det02det12 = (filt12 - jurik2[1]) * ((1 - alpha2) * (1 - alpha2)) + (alpha2 * alpha2) * det12[1]jurik2 = jurik2[1] + det12IF jurik1 < jurik2 THENvalueUp = valueUp + 1ELSEvalueDn = valueDn + 1ENDIFNEXT//valp[i] = CalculateJurik(valueUp, smooth, smoothPhase)src3 = valueUpperiod3 = MAX(smooth, 1)beta3 = 0.45 * (period3 - 1) / (0.45 * (period3 - 1) + 2)alpha3 = POW(beta3, pow1)corr3 = MAX(MIN(smoothPhase, 100), -100) / 100.0 + 1.5filt03 = (1 - alpha3) * src3 + alpha3 * filt03[1]det03 = (src3 - filt03[0]) * (1 - beta3) + beta3 * det03[1]filt13 = filt03[0] + corr3 * det03[0]det13 = (filt13[0] - valp[1]) * ((1 - alpha3) * (1 - alpha3)) + (alpha3 * alpha3) * det13[1]valp = valp[1] + det13[0]//valm[i] = CalculateJurik(valueDn, smooth, smoothPhase)src4 = valueDnperiod4 = MAX(smooth, 1)beta4 = 0.45 * (period4 - 1) / (0.45 * (period4 - 1) + 2)alpha4 = POW(beta4, pow1)corr4 = MAX(MIN(smoothPhase, 100), -100) / 100.0 + 1.5filt04 = (1 - alpha4) * src4 + alpha4 * filt04[1]det04 = (src4 - filt04[0]) * (1 - beta4) + beta4 * det04[1]filt14 = filt04[0] + corr4 * det04[0]det14 = (filt14[0] - valm[1]) * ((1 - alpha4) * (1 - alpha4)) + (alpha4 * alpha4) * det14[1]valm = valm[1] + det14[0]//-------------------------------------------------------------//if valp > valm THENvalpc = 1ELSEvalpc = 2endifvalmc = valpcendif//-------------------------------------------------------------//RETURN valp AS "Ultra trend +" COLOURED(0, 255, 0), valm AS "Ultra trend -" COLOURED(255, 165, 0)05/24/2024 at 2:34 PM #233020hi Guys if you can convert the Tradingview code below for pro real time please
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ClayeWeight//@version=5
indicator(“Market Structure RSI”)rsiLength = input.int(20, “RSI Length”, minval = 1, group=”Market Structure RSI”)
OBlvl = input.int(80, “Overbought Level”, minval = 1, maxval=100, group=”Market Structure RSI”)
OSlvl = input.int(20, “Oversold Level”, minval = 1, maxval=100, group=”Market Structure RSI”)strCloseType = input.string(“High/Low”, “Close Type”, [“Close”, “High/Low”], tooltip=”Choose whether the structure is deemed broken with either a Close or the Candle High/Low”, group=”Market Structure RSI”)
closeTypeBull = strCloseType == “Close” ? close[1] : high[1]
closeTypeBear = strCloseType == “Close” ? close[1] : low[1]maBool = input.bool(true, “Show Moving Average”, group=”Moving Average”)
maSelection = input.string(“EMA”, “MA Type”, [“EMA”, “SMA”, “WMA”], group=”Moving Average”)
maLength = input.int(8, “MA Length”, minval = 1, group=”Moving Average”)// Get Pivots
pH = high[3] < high[2] and high[2] > high[1]
pL = low[3] > low[2] and low[2] < low[1]var highPrice = array.new_float()
var lowPrice = array.new_float()
var count = array.new_int()if pH
highPrice.push(high[2])
if pL
lowPrice.push(low[2])add_to_total(dir, priceArray, countArray, closeType, add) =>
if array.size(priceArray) > 0
for l = array.size(priceArray)-1 to 0
if (dir == 1 and closeType > array.get(priceArray, l)) or (dir == 0 and closeType < array.get(priceArray, l))
array.remove(priceArray, l)
array.push(countArray, add)
else
breakadd_to_total(1, highPrice, count, closeTypeBull, 1)
add_to_total(0, lowPrice, count, closeTypeBear, -1)// Get Total
total = array.sum(count)
rsiTotal = ta.rsi(total, rsiLength)float rsmMATotal = switch maSelection
“EMA” => ta.ema(rsiTotal, maLength)
“SMA” => ta.sma(rsiTotal, maLength)
“WMA” => ta.wma(rsiTotal, maLength)// Plot RSI
rsiPlot = plot(rsiTotal, color=na, linewidth = 2, title= “RSI Line”, editable = false)
plot(maBool ? rsmMATotal : na, color=#0075ff, title= “RSI Moving Average”, linewidth = 2)// Plot Signals
structureOB = ta.crossunder(rsiTotal, OBlvl)
structureOS = ta.crossover(rsiTotal, OSlvl)
plotshape(structureOB ? OBlvl : na, size = size.tiny, style = shape.circle, location = location.absolute, color = color.red, title = “Bearish Signal”)
plotshape(structureOS ? OSlvl : na, size = size.tiny, style = shape.circle, location = location.absolute, color = color.green, title = “Bullish Signal”)// Plot High and Low lines
hline(OBlvl, title = “Overbought Level”)
hline(OSlvl, title = “Oversold Level”)// Gradient Fill
midPlot = plot(50, color=rsiTotal>50?color.lime:color.red) //, color = na, editable = false, display = display.none)
fill(rsiPlot, midPlot, 150, 50, top_color = color.new(color.lime, 0), bottom_color = color.new(color.lime, 100), title = “Overbought Gradient Fill”)
fill(rsiPlot, midPlot, 50, -50, top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0), title = “Oversold Gradient Fill”)// Alerts
alertcondition(structureOB, “Bearish Signal”, “Structure RSI is crossing under the Overbought level”)
alertcondition(structureOS, “Bullish Signal”, “Structure RSI is crossing over the Oversold level”) -
AuthorPosts
Find exclusive trading pro-tools on