Conversion of indicator B3 Directional Trend Index from TradingView

Forums ProRealTime English forum ProBuilder support Conversion of indicator B3 Directional Trend Index from TradingView

Viewing 1 post (of 1 total)
  • #172065

    Hello,

    I had a look at the B3 Directional Trend Index – TradingView  indicator which seems very interesting.

    You will see live sample on https://www.tradingview.com/script/dASPQJ78-B3-Directional-Trend-Index/?utm_source=notification_email&utm_medium=email&utm_campaign=notification_pubscript_update

    Would you be interested in converting it to PRC?

    Thanks for your consideration.

     

    The code is

    //@version=4
    // B3 DTI
    study(“B3 Directional Trend Index”, shorttitle=”DTI”, overlay=false)
    // Constants:
    i1=input(2, “Momentum Period”, minval=1) //Keep at 2 usually
    i2=input(10, “Slow Period”, minval=1)
    i3=input(5, “Fast Period”, minval=1)
    i4=input(3, “Smoothing Period”, minval=1)
    i5=input(4, “Signal Period”, minval=1)
    c1=input(color.rgb(50,200,75,0), “Up Color”)
    c2=input(color.rgb(200,50,75,0), “Down Color”)
    i6=input(50, “Extreme Value”, minval=1)
    c3=input(color.rgb(150,0,200,0), “High Extreme Color”)
    c=input(color.rgb(150,150,150,0), “Center Zero Color”)
    c4=input(color.rgb(0,150,200,0), “Low Extreme Color”)
    fade=input(100, “Fade Effect 0-100”, minval=0, maxval=100, type=input.integer)
    bc=input(true, “Bar Coloring”)
    // Vars:
    hiDif = 0.0
    loDif = 0.0
    uDM = 0.0
    dDM = 0.0
    ATR = 0.0
    DIu = 0.0
    DId = 0.0
    HLM2 = 0.0
    DTI = 0.0
    signal = 0.0
    col = color.maroon
    col2 = color.red
    // TView help-forum-provided function to force new value for color.rgb() transp
    f_grad_transp(_c_col, _transp) =>
    _c_red = color.r(_c_col)
    _c_green = color.g(_c_col)
    _c_blue = color.b(_c_col)
    color.rgb(_c_red, _c_green, _c_blue, _transp)
    // DTI
    hiDif := high – high[1]
    loDif := low[1] – low
    uDM := hiDif > loDif and hiDif > 0 ? hiDif : 0
    dDM := loDif > hiDif and loDif > 0 ? loDif : 0
    ATR := rma(tr(true), i1)
    DIu := 100 * rma(uDM, i1) / ATR
    DId := 100 * rma(dDM, i1) / ATR
    HLM2 := DIu – DId
    DTI := (100 * ema(ema(ema(HLM2, i2), i3), i4)) / ema(ema(ema(abs(HLM2), i2), i3), i4)
    signal := ema(DTI, i5)
    // Colors
    col := DTI > DTI[1] ?c1 : c2
    col2 := DTI > signal ?c1 : c2
    transp1 = DTI>=0?((2*i6-DTI)/(2*i6))*100:((2*i6-(-DTI))/(2*i6))*100 // Gradient Formula
    transp2 = (fade/100)*transp1 // user sets effect
    transp3 = (fade/100)*(100-transp1) // Reverse
    cc_color = f_grad_transp(col, max(0,transp2)) // Total Fade (histogram + signal line)
    ccc_color = f_grad_transp(col2, max(0,transp3)) // Reverse Fade (ribbon)
    cccc_color = f_grad_transp(c3, max(0,transp2*0.90)) // Hi line – *0.x sets a max transparency value
    ccccc_color = f_grad_transp(c4, max(0,transp2*0.90)) // Lo Line – colors will never be totally transp
    cccccc_color = f_grad_transp(c, max(0,transp2*0.90)) // Zero-line
    bc_color = f_grad_transp(col, max(0,transp2*0.786)) // Bar-Color stay brighter than others
    // Plots
    p1=plot(DTI,title=”DTI”, color=cc_color, style=plot.style_area, linewidth=1)
    p2=plot(signal,title=”Signal”, color=ccc_color, style=plot.style_line, linewidth=2)
    p3=plot(0,title=”zero”, color=cccccc_color, linewidth=1)
    p4=plot(i6,title=”overbought”,color=cccc_color, linewidth=3)
    p5=plot(-i6,title=”oversold”,color=ccccc_color, linewidth=3)
    fill(p1, p2, ccc_color)
    barcolor(bc?bc_color:na)

Viewing 1 post (of 1 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login