Support Resistance OB

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #262223 quote
    Maricarmen
    Participant
    Veteran

    Buenas Tardes:

    Sería posible hacer la traducción a esta plataforma para este indicador de Tradingview:

    https://es.tradingview.com/script/p7khSBLf-KN-Support-Resistance-OB/

    Un saludo,

    #262232 quote
    Iván González
    Moderator
    Legend

    Aquí tienes:

    //--------------------------------------------------------//
    // PRC_KN Support Resistance OB (by LuxAlgo / phamhaihoclt)
    // version = 0
    // 29.06.2026
    // Ivan Gonzalez @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    //--------------------------------------------------------//
    defparam drawonlastbaronly = true
    
    
    //=== INPUTS ===
    internalLength = 5      // Internal Structure Length (>= 2)
    swingLength    = 50     // Swing Structure Length (>= 10)
    internalOBSize = 3      // Internal Order Blocks shown (1..20)
    swingOBSize    = 5      // Swing Order Blocks shown (1..20)
    obFilter       = 1      // Volatility filter: 1 = ATR, 0 = Cumulative Mean Range
    obMitigation   = 0      // Mitigation source: 1 = Close, 0 = High/Low
    obExtend       = 20     // Right projection (bars)
    maxStored      = 100    // Active OB window (mirrors original 100 cap)
    maxLife        = 500    // Max bars swept per OB (mitigation horizon)
    
    
    //=== COLORS (R, G, B) ===
    // internal bullish #3179f5
    ibR = 49
    ibG = 121
    ibB = 245
    // internal bearish #f77c80
    irR = 247
    irG = 124
    irB = 128
    // swing bullish #1848cc
    sbR = 24
    sbG = 72
    sbB = 204
    // swing bearish #b22833
    srR = 178
    srG = 40
    srB = 51
    fillAlpha = 60      // fill opacity (0..255); original Pine transparency 80 ~ 51
    
    
    //=== VOLATILITY MEASURES ===
    atr = averagetruerange[200](close)
    if barindex = 0 then
        myTR  = high - low
        cumTR = myTR
    else
        myTR  = max(high - low, max(abs(high - close[1]), abs(low - close[1])))
        cumTR = cumTR[1] + myTR
    endif
    cmeanRange = cumTR / max(1, barindex)
    
    
    //=== PERSISTENT STATE INIT ===
    once swingHighLevel    = 0
    once swingLowLevel     = 0
    once internalHighLevel = 0
    once internalLowLevel  = 0
    once swingHighBar      = 0
    once swingLowBar       = 0
    once internalHighBar   = 0
    once internalLowBar    = 0
    once swingHighCrossed    = 1
    once swingLowCrossed     = 1
    once internalHighCrossed = 1
    once internalLowCrossed  = 1
    once sob = 0
    once iob = 0
    
    
    //=== SWING LEG + PIVOTS ===
    if barindex <= swingLength then
        legSwing = 0
    elsif high[swingLength] > highest[swingLength](high) then
        legSwing = 0
    elsif low[swingLength] < lowest[swingLength](low) then
        legSwing = 1
    else
        legSwing = legSwing[1]
    endif
    
    
    if legSwing <> legSwing[1] then
        if legSwing = 1 then
            swingLowLevel   = low[swingLength]
            swingLowBar     = barindex - swingLength
            swingLowCrossed = 0
        else
            swingHighLevel   = high[swingLength]
            swingHighBar     = barindex - swingLength
            swingHighCrossed = 0
        endif
    endif
    
    
    //=== INTERNAL LEG + PIVOTS ===
    if barindex <= internalLength then
        legInternal = 0
    elsif high[internalLength] > highest[internalLength](high) then
        legInternal = 0
    elsif low[internalLength] < lowest[internalLength](low) then
        legInternal = 1
    else
        legInternal = legInternal[1]
    endif
    
    
    if legInternal <> legInternal[1] then
        if legInternal = 1 then
            internalLowLevel   = low[internalLength]
            internalLowBar     = barindex - internalLength
            internalLowCrossed = 0
        else
            internalHighLevel   = high[internalLength]
            internalHighBar     = barindex - internalLength
            internalHighCrossed = 0
        endif
    endif
    
    
    //=== SWING BULLISH BREAK -> BULLISH OB ===
    if (close crosses over swingHighLevel) and swingHighCrossed = 0 then
        swingHighCrossed = 1
        minVal = 1000000000
        blockOff = 1
        maxOff = barindex - swingHighBar
        for off = maxOff downto 1 do
            if obFilter = 1 then
                volOff = atr[off]
            else
                volOff = cmeanRange[off]
            endif
            if (high[off] - low[off]) >= 2 * volOff then
                plOff = high[off]
            else
                plOff = low[off]
            endif
            if plOff < minVal then
                minVal = plOff
                blockOff = off
            endif
        next
        if obFilter = 1 then
            volBlk = atr[blockOff]
        else
            volBlk = cmeanRange[blockOff]
        endif
        if (high[blockOff] - low[blockOff]) >= 2 * volBlk then
            blkHigh = low[blockOff]
            blkLow  = high[blockOff]
        else
            blkHigh = high[blockOff]
            blkLow  = low[blockOff]
        endif
        $sobTop[sob]   = blkHigh
        $sobBot[sob]   = blkLow
        $sobLeft[sob]  = barindex - blockOff
        $sobBias[sob]  = 1
        $sobBirth[sob] = barindex
        sob = sob + 1
    endif
    
    
    //=== SWING BEARISH BREAK -> BEARISH OB ===
    if (close crosses under swingLowLevel) and swingLowCrossed = 0 then
        swingLowCrossed = 1
        maxV = -1000000000
        blockOff = 1
        maxOff = barindex - swingLowBar
        for off = maxOff downto 1 do
            if obFilter = 1 then
                volOff = atr[off]
            else
                volOff = cmeanRange[off]
            endif
            if (high[off] - low[off]) >= 2 * volOff then
                phOff = low[off]
            else
                phOff = high[off]
            endif
            if phOff > maxV then
                maxV = phOff
                blockOff = off
            endif
        next
        if obFilter = 1 then
            volBlk = atr[blockOff]
        else
            volBlk = cmeanRange[blockOff]
        endif
        if (high[blockOff] - low[blockOff]) >= 2 * volBlk then
            blkHigh = low[blockOff]
            blkLow  = high[blockOff]
        else
            blkHigh = high[blockOff]
            blkLow  = low[blockOff]
        endif
        $sobTop[sob]   = blkHigh
        $sobBot[sob]   = blkLow
        $sobLeft[sob]  = barindex - blockOff
        $sobBias[sob]  = -1
        $sobBirth[sob] = barindex
        sob = sob + 1
    endif
    
    
    //=== INTERNAL BULLISH BREAK -> BULLISH OB ===
    if (close crosses over internalHighLevel) and internalHighCrossed = 0 and internalHighLevel <> swingHighLevel then
        internalHighCrossed = 1
        minVal = 1000000000
        blockOff = 1
        maxOff = barindex - internalHighBar
        for off = maxOff downto 1 do
            if obFilter = 1 then
                volOff = atr[off]
            else
                volOff = cmeanRange[off]
            endif
            if (high[off] - low[off]) >= 2 * volOff then
                plOff = high[off]
            else
                plOff = low[off]
            endif
            if plOff < minVal then
                minVal = plOff
                blockOff = off
            endif
        next
        if obFilter = 1 then
            volBlk = atr[blockOff]
        else
            volBlk = cmeanRange[blockOff]
        endif
        if (high[blockOff] - low[blockOff]) >= 2 * volBlk then
            blkHigh = low[blockOff]
            blkLow  = high[blockOff]
        else
            blkHigh = high[blockOff]
            blkLow  = low[blockOff]
        endif
        $iobTop[iob]   = blkHigh
        $iobBot[iob]   = blkLow
        $iobLeft[iob]  = barindex - blockOff
        $iobBias[iob]  = 1
        $iobBirth[iob] = barindex
        iob = iob + 1
    endif
    
    
    //=== INTERNAL BEARISH BREAK -> BEARISH OB ===
    if (close crosses under internalLowLevel) and internalLowCrossed = 0 and internalLowLevel <> swingLowLevel then
        internalLowCrossed = 1
        maxV = -1000000000
        blockOff = 1
        maxOff = barindex - internalLowBar
        for off = maxOff downto 1 do
            if obFilter = 1 then
                volOff = atr[off]
            else
                volOff = cmeanRange[off]
            endif
            if (high[off] - low[off]) >= 2 * volOff then
                phOff = low[off]
            else
                phOff = high[off]
            endif
            if phOff > maxV then
                maxV = phOff
                blockOff = off
            endif
        next
        if obFilter = 1 then
            volBlk = atr[blockOff]
        else
            volBlk = cmeanRange[blockOff]
        endif
        if (high[blockOff] - low[blockOff]) >= 2 * volBlk then
            blkHigh = low[blockOff]
            blkLow  = high[blockOff]
        else
            blkHigh = high[blockOff]
            blkLow  = low[blockOff]
        endif
        $iobTop[iob]   = blkHigh
        $iobBot[iob]   = blkLow
        $iobLeft[iob]  = barindex - blockOff
        $iobBias[iob]  = -1
        $iobBirth[iob] = barindex
        iob = iob + 1
    endif
    
    
    //=== MITIGATION SWEEP + DRAW (last bar only) ===
    if islastbarupdate then
        rightX = barindex + obExtend
    
    
        // --- Swing OBs: most recent swingOBSize survivors ---
        countS = 0
        floorS = max(0, sob - maxStored)
        if sob > 0 then
            for k = sob - 1 downto floorS do
                life = min(barindex - $sobBirth[k], maxLife)
                broke = 0
                for j = 0 to life do
                    if obMitigation = 1 then
                        mb = close[j]
                        ml = close[j]
                    else
                        mb = high[j]
                        ml = low[j]
                    endif
                    if $sobBias[k] = -1 and mb > $sobTop[k] then
                        broke = 1
                    endif
                    if $sobBias[k] = 1 and ml < $sobBot[k] then
                        broke = 1
                    endif
                    if broke = 1 then
                        break
                    endif
                next
                if broke = 0 then
                    if $sobBias[k] = 1 then
                        drawrectangle($sobLeft[k], $sobTop[k], rightX, $sobBot[k]) coloured(sbR, sbG, sbB, 200) fillcolor(sbR, sbG, sbB, fillAlpha)
                    else
                        drawrectangle($sobLeft[k], $sobTop[k], rightX, $sobBot[k]) coloured(srR, srG, srB, 200) fillcolor(srR, srG, srB, fillAlpha)
                    endif
                    countS = countS + 1
                    if countS >= swingOBSize then
                        break
                    endif
                endif
            next
        endif
    
    
        // --- Internal OBs: most recent internalOBSize survivors (no border) ---
        countI = 0
        floorI = max(0, iob - maxStored)
        if iob > 0 then
            for k = iob - 1 downto floorI do
                life = min(barindex - $iobBirth[k], maxLife)
                broke = 0
                for j = 0 to life do
                    if obMitigation = 1 then
                        mb = close[j]
                        ml = close[j]
                    else
                        mb = high[j]
                        ml = low[j]
                    endif
                    if $iobBias[k] = -1 and mb > $iobTop[k] then
                        broke = 1
                    endif
                    if $iobBias[k] = 1 and ml < $iobBot[k] then
                        broke = 1
                    endif
                    if broke = 1 then
                        break
                    endif
                next
                if broke = 0 then
                    if $iobBias[k] = 1 then
                        drawrectangle($iobLeft[k], $iobTop[k], rightX, $iobBot[k]) coloured(ibR, ibG, ibB, 0) fillcolor(ibR, ibG, ibB, fillAlpha)
                    else
                        drawrectangle($iobLeft[k], $iobTop[k], rightX, $iobBot[k]) coloured(irR, irG, irB, 0) fillcolor(irR, irG, irB, fillAlpha)
                    endif
                    countI = countI + 1
                    if countI >= internalOBSize then
                        break
                    endif
                endif
            next
        endif
    endif
    
    
    return
    


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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

TradingView to ProRealTime Translation Center

New Reply
Author
author-avatar
Maricarmen @maricarmen Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
2 months, 2 weeks ago.

Topic Details
Forum: TradingView to ProRealTime Translation Center Forum
Started: 06/27/2026
Status: Active
Attachments: No files
Logo Logo
Loading...