Donchian Channel Pivot High Low

Forums ProRealTime English forum ProBuilder support Donchian Channel Pivot High Low

Viewing 1 post (of 1 total)
  • #169444

    Hello,

    Is possible to  convert this Pinescript (from TradingView) code to PRT code  please?

    //@version=4
    study(“Donchian Channel – Pivot High-Low”, overlay=true)
    pvtLenR = input(4)
    pvtLenL = input(2)
    waitforclose = input(true)
    ShowHHLL = input(true)
    DCBase = input(title=”Channel Base”, defval=”Combined”, options=[“Price”, “Pivots”, “Combined”])
    DCLength = input(20)
    showChannel = input(true)
    donchian(highSource, lowSource, rangeLength)=>
    top = highest(highSource, rangeLength)
    bottom = lowest(lowSource, rangeLength)
    middle = (top+bottom)/2
    [middle, top, bottom]

    f_calculatePivots(Shunt)=>
    pvthi_ = pivothigh(high, pvtLenL, pvtLenR)
    pvtlo_ = pivotlow(low, pvtLenL, pvtLenR)

    pvthi = pvthi_[Shunt]
    pvtlo = pvtlo_[Shunt]

    pvthighline = pvthi
    pvthighline := na(pvthighline)? nz(pvthighline[1]): pvthighline

    pvtlowline = pvtlo
    pvtlowline := na(pvtlowline)? nz(pvtlowline[1]): pvtlowline

    higherhigh = na(pvthi) ? na : ( valuewhen(pvthi, high[pvtLenR+Shunt], 1) < valuewhen(pvthi, high[pvtLenR+Shunt], 0) ) ? pvthi : na
    lowerhigh = na(pvthi) ? na : ( valuewhen(pvthi, high[pvtLenR+Shunt], 1) > valuewhen(pvthi, high[pvtLenR+Shunt], 0) ) ? pvthi : na
    higherlow = na(pvtlo) ? na : ( valuewhen(pvtlo, low[pvtLenR+Shunt], 1) < valuewhen(pvtlo, low[pvtLenR+Shunt], 0) ) ? pvtlo : na
    lowerlow = na(pvtlo) ? na : ( valuewhen(pvtlo, low[pvtLenR+Shunt], 1) > valuewhen(pvtlo, low[pvtLenR+Shunt], 0) ) ? pvtlo : na

    [pvthighline, pvtlowline, higherhigh, lowerhigh, higherlow, lowerlow]

    Shunt = waitforclose? 1 : 0
    [pvthighline, pvtlowline, higherhigh, lowerhigh, higherlow, lowerlow] = f_calculatePivots(Shunt)

    [middleP, topP, bottomP] = donchian(pvthighline, pvtlowline, DCLength)
    [middleC, topC, bottomC] = donchian(high, low, DCLength)

    top = DCBase == “Combined”? max(topP,topC) : DCBase == “Pivots” ? topP : topC
    bottom = DCBase == “Combined”? min(bottomP,bottomC) : DCBase == “Pivots” ? bottomP : bottomC
    middle = DCBase == “Combined”? (middleP+middleC)/2 : DCBase == “Pivots” ? middleP : middleC

    //plotshape(ShowHHLL ? higherhigh : na, title=’HH’, style=shape.triangleup, location=location.abovebar, color=color.green, text=”HH”, offset=-pvtLenR-Shunt, transp=50)
    //plotshape(ShowHHLL ? higherlow : na, title=’HL’, style=shape.triangleup, location=location.belowbar, color=color.green, text=”HL”, offset=-pvtLenR-Shunt, transp=0)
    //plotshape(ShowHHLL ? lowerhigh : na, title=’LH’, style=shape.triangledown, location=location.abovebar, color=color.maroon, text=”LH”, offset=-pvtLenR-Shunt, transp=0)
    //plotshape(ShowHHLL ? lowerlow : na, title=’LL’, style=shape.triangledown, location=location.belowbar, color=color.maroon, text=”LL”, offset=-pvtLenR-Shunt, transp=50)

    BBup = plot(showChannel ? top: na, title=”Top”, color=color.red, linewidth=1, transp=50, style=plot.style_linebr)
    BBdown = plot(showChannel ? bottom: na, title=”Bottom”, color=color.green, linewidth=1, transp=50, style=plot.style_linebr)
    BBmid = plot(showChannel ? middle: na, title=”Middle”, color=color.blue, linewidth=1, transp=50, style=plot.style_linebr)
    fill(BBup, BBmid, title=”High Zone”, color=color.green, transp=90)
    fill(BBdown, BBmid, title=”Low Zone”, color=color.red, transp=90)

     

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