ultra trend indicator conversion from mq4 to prt

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #138785 quote
    Andavan
    Participant
    New

    This indicator gives great signals please somebody can transform this code to PRT CODE format. it will be useful for me and many trader here

    #138812 quote
    Nicolas
    Keymaster
    Master

    Sorry but that code is a decompiled one and makes it far too complex to understand to be properly translated.

    #138844 quote
    Andavan
    Participant
    New

    thanks for trying to help sir, but i couldn’t find the original file maybe i will keep looking for that file

    #138850 quote
    robertogozzi
    Moderator
    Master

    I have found this, it should be the original source file.

    //+------------------------------------------------------------------
    #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 9
    
          if (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 period
    input int  inpProgression = 5;   // Step
    input int  inpInstances   = 30;  // Instances 
    input int  inpSmooth      = 5;   // Ultra trend smoothing period
    input int  inpSmoothPhase = 100; // Ultra trend smoothing phase
    
    //--- buffers declarations
    double fillu[],filld[],valp[],valpc[],valm[],valmc[];
    CJurikSmooth _iSmooth[];
    //+------------------------------------------------------------------+
    //| Custom indicator initialization function                         |
    //+------------------------------------------------------------------+
    int OnInit()
      {
    //--- indicator buffers mapping
       SetIndexBuffer(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 name
       IndicatorSetString(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);
      }
    //+------------------------------------------------------------------+
    #138963 quote
    Andavan
    Participant
    New

    wow, thanks for your selfless help for finding the this file,i think really it would help many traders, and sir any suggestion on indicator for finding trend strength that is possible continuation or reverssal

    #139046 quote
    Madrosat
    Participant
    Master

    ok Roberto but can you translate in prorealtime ???

    #139047 quote
    robertogozzi
    Moderator
    Master

    No, I can’t.

    #138964 quote
    Andavan
    Participant
    New

    hello, 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

    #225899 quote
    Madrosat
    Participant
    Master

    Bonjour Roberto meilleurs voeux pour 2024

    Avec 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?

    #225929 quote
    robertogozzi
    Moderator
    Master

    @Madrosat

    Only 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.

    #225938 quote
    JS
    Participant
    Senior

    Maybe as a starting point for a helping coder…

    //----------------------------//
    // JMA - Jurik Moving Average //
    //----------------------------//
    
    //IF MAType = 25 THEN
    
    Period=20
    Period = MAX(Period, 1)
    Series=Close
    
    // Pow = 5 ({ 1..10 })
    // R = 1.5 ({0.5..2.5})
    Pow1 = 4
    R = 1
    
    beta = 0.45 * (Period - 1) / (0.45 * (Period - 1) + 2)
    
    IF Pow1 = 1 THEN
    alpha = beta
    ELSIF Pow1 = 2 THEN
    alpha = beta * beta
    ELSIF Pow1 = 3 THEN
    alpha = beta * beta * beta
    ELSIF Pow1 = 4 THEN
    alpha = beta * beta * beta * beta
    ELSIF Pow1 = 5 THEN
    alpha = beta * beta * beta * beta * beta
    ELSIF Pow1 = 6 THEN
    alpha = beta * beta * beta * beta * beta * beta
    ELSIF Pow1 = 7 THEN
    alpha = beta * beta * beta * beta * beta * beta * beta
    ELSIF Pow1 = 8 THEN
    alpha = beta * beta * beta * beta * beta * beta * beta * beta
    ELSIF Pow1 = 9 THEN
    alpha = beta * beta * beta * beta * beta * beta * beta * beta * beta
    ELSIF Pow1 = 10 THEN
    alpha = beta * beta * beta * beta * beta * beta * beta * beta * beta
    ENDIF
    
    IF BarIndex = 0 THEN
    Filt0 = Series
    Filt1 = Series
    AFR = Series
    ELSE
    Filt0 = (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]
    ENDIF
    
    Return AFR Coloured("Red")
    
    #225942 quote
    Madrosat
    Participant
    Master

    Roberto
    Everything I read on this subject was written in French so I continued without my language.
    There must have been an automatic translation that I didn’t see?

    Thank JS

    May be someone will be apple to continue your work

    #225954 quote
    robertogozzi
    Moderator
    Master

    No, translation needs to be activated, it’s not automatically enabled.

    #232956 quote
    Iván González
    Moderator
    Master

    Hi,
    This is an aprox from the original code. I took jurik MA @JS in order to make the code faster.

    defparam calculateonlastbars = 300
    //-----Inputs--------------------------------------------------//
    utrPeriod = 3
    progression = 5
    instances = 30
    smooth = 5
    smoothPhase = 100
    pow1=6
    //-------------------------------------------------------------//
    if barindex > utrPeriod + progression * instances then
    valp = 0
    valpc = 0
    valm = 0
    valmc = 0
    valueUp = 0
    valueDn = 0
    FOR 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.5
    
    filt01=(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.5
    
    filt02 = (1 - alpha2) * src2 + alpha2 * filt02[1]
    det02 = (src2 - filt02) * (1 - beta2) + beta2 * det02[1]
    filt12 = filt02 + corr2 * det02
    det12 = (filt12 - jurik2[1]) * ((1 - alpha2) * (1 - alpha2)) + (alpha2 * alpha2) * det12[1]
    jurik2 = jurik2[1] + det12
    
    IF jurik1 < jurik2 THEN
    valueUp = valueUp + 1
    ELSE
    valueDn = valueDn + 1
    ENDIF
    NEXT
    //valp[i] = CalculateJurik(valueUp, smooth, smoothPhase)
    src3 = valueUp
    period3 = 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.5
    
    filt03 = (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 = valueDn
    period4 = 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.5
    
    filt04 = (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 THEN
    valpc = 1
    ELSE
    valpc = 2
    endif
    valmc = valpc
    endif
    //-------------------------------------------------------------//
    RETURN valp AS "Ultra trend +" COLOURED(0, 255, 0), valm AS "Ultra trend -" COLOURED(255, 165, 0)
    
    #233020 quote
    yas
    Participant
    Junior

    hi 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
    break

    add_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”)

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

ultra trend indicator conversion from mq4 to prt


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Andavan @andavan Participant
Summary

This topic contains 16 replies,
has 7 voices, and was last updated by yas
1 year, 8 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/08/2020
Status: Active
Attachments: 6 files
Logo Logo
Loading...