BOSS MODE S/R

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #260733 quote
    Ciccarelli FrancoCiccarelli Franco
    Participant
    Senior

    Chiedo se è possibile tradurre questo indicatore di Tradingview.


    Grazie


    https://it.tradingview.com/script/oA9rDnQB-Luxy-BOSS-MODE-Support-Resistance/

    #260745 quote
    Iván GonzálezIván González
    Moderator
    Legend

    ecco qui:

    //-----------------------------------------------//
    // PRC_Boss Mode S/R
    // Multi-source S/R zone detector with composite scoring
    // Sources: Swing pivots, Order Blocks, Fair Value Gaps, Liquidity Pools
    // Inspired by "Boss Mode S/R" by OrenLuxy (TradingView, MPL 2.0)
    // version = 1
    // 30.04.2026
    // Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    //-----------------------------------------------//
    //-----INPUTS-----------------------------------//
    prdLeft = 5          // Bars left for pivot
    prdRight = 5         // Bars right for pivot (no-repaint delay)
    zoneAtrPct = 0.5     // Zone half-width as fraction of ATR
    
    maxZones = 30        // Max zones in memory
    topN = 10            // Render only top N by score
    
    obMinMovePct = 1.5   // Min impulse % to qualify Order Block
    obVolMult = 1.5      // Min volume ratio at OB formation
    
    fvgMinPct = 0.3      // Min gap size % of price for FVG
    
    liqLength = 20       // Lookback for equal highs/lows
    liqTolPct = 0.1      // Equal-tolerance % for Liquidity
    
    // Scoring weights
    wTouch = 12
    wTouchVol = 18
    wCreateVol = 12
    wConf = 18
    wFresh = 8
    wRegime = 12
    
    // Source toggles
    useSwing = 1
    useOB = 1
    useFVG = 1
    useLiq = 1
    
    // Filters
    showGradeC = 1       // 0 = render only Grade A and B
    warnAtrDist = 0.5    // ATR distance for zone-approach warning
    
    //-----STATE-----------------------------------//
    once zCount = 0
    
    prdTotal = prdLeft + prdRight + 1
    
    atrV = averagetruerange[14]
    avgVol20 = average[20](volume)
    avgVol60 = average[60](volume)
    avgVolLiq = average[liqLength](volume)
    zoneW = atrV * zoneAtrPct
    
    //-----REGIME CLASSIFIER-----------------------//
    adxV = ADX[14]
    ema50 = exponentialaverage[50](close)
    emaSlope5 = 0
    if barindex >= 5 and ema50[5] <> 0 then
       emaSlope5 = (ema50 - ema50[5]) / ema50[5] * 100
    endif
    
    // regime: 1=STRONG_BULL  2=WEAK_BULL  -1=STRONG_BEAR  -2=WEAK_BEAR  0=RANGE
    regime = 0
    if adxV > 25 and emaSlope5 > 0.5 then
       regime = 1
    elsif adxV > 18 and emaSlope5 > 0.1 then
       regime = 2
    elsif adxV > 25 and emaSlope5 < -0.5 then
       regime = -1
    elsif adxV > 18 and emaSlope5 < -0.1 then
       regime = -2
    endif
    
    //-----CANDIDATE COLLECTOR---------------------//
    // Each detector pushes 0..1 candidates into $cand* arrays
    // A single processor pass at the end resolves overlap and stores the zone
    candCount = 0
    
    // --- Detector 1: SWING pivots ---
    if useSwing and barindex >= prdTotal then
       if high[prdRight] >= highest[prdTotal](high) then
          $candTop[candCount] = high[prdRight] + zoneW * 0.5
          $candBot[candCount] = high[prdRight] - zoneW * 0.5
          $candIsSup[candCount] = 0
          $candSrc[candCount] = 1
          $candVol[candCount] = volume[prdRight]
          candCount = candCount + 1
       endif
       if low[prdRight] <= lowest[prdTotal](low) then
          $candTop[candCount] = low[prdRight] + zoneW * 0.5
          $candBot[candCount] = low[prdRight] - zoneW * 0.5
          $candIsSup[candCount] = 1
          $candSrc[candCount] = 1
          $candVol[candCount] = volume[prdRight]
          candCount = candCount + 1
       endif
    endif
    
    // --- Detector 2: ORDER BLOCKS ---
    if useOB and barindex >= 6 then
       isBearPrev = close[1] < open[1]
       bullMove = (close - open[1]) / open[1] * 100
       bullDisp = close > max(high[2], max(high[3], max(high[4], high[5])))
       if isBearPrev and bullMove >= obMinMovePct and volume >= avgVol60 * obVolMult and bullDisp then
          obT = max(open[1], close[1])
          obB = min(open[1], close[1])
          $candTop[candCount] = obT
          $candBot[candCount] = obB
          $candIsSup[candCount] = 1
          $candSrc[candCount] = 2
          $candVol[candCount] = volume[1]
          candCount = candCount + 1
       endif
       isBullPrev = close[1] > open[1]
       bearMove = (open[1] - close) / open[1] * 100
       bearDisp = close < min(low[2], min(low[3], min(low[4], low[5])))
       if isBullPrev and bearMove >= obMinMovePct and volume >= avgVol60 * obVolMult and bearDisp then
          obT = max(open[1], close[1])
          obB = min(open[1], close[1])
          $candTop[candCount] = obT
          $candBot[candCount] = obB
          $candIsSup[candCount] = 0
          $candSrc[candCount] = 2
          $candVol[candCount] = volume[1]
          candCount = candCount + 1
       endif
    endif
    
    // --- Detector 3: FAIR VALUE GAPS ---
    if useFVG and barindex >= 2 then
       minGap = close * fvgMinPct / 100
       bullMidImp = close[1] > open[1] and (close[1] - open[1]) >= atrV * 0.3
       if low > high[2] and (low - high[2]) >= minGap and bullMidImp then
          $candTop[candCount] = low
          $candBot[candCount] = high[2]
          $candIsSup[candCount] = 1
          $candSrc[candCount] = 3
          $candVol[candCount] = volume[1]
          candCount = candCount + 1
       endif
       bearMidImp = close[1] < open[1] and (open[1] - close[1]) >= atrV * 0.3
       if low[2] > high and (low[2] - high) >= minGap and bearMidImp then
          $candTop[candCount] = low[2]
          $candBot[candCount] = high
          $candIsSup[candCount] = 0
          $candSrc[candCount] = 3
          $candVol[candCount] = volume[1]
          candCount = candCount + 1
       endif
    endif
    
    // --- Detector 4: LIQUIDITY POOLS ---
    if useLiq and barindex >= liqLength then
       tol = close * liqTolPct / 100
       liqH = highest[liqLength](high)
       liqL = lowest[liqLength](low)
       eqHcount = 0
       eqLcount = 0
       for k = 0 to liqLength - 1 do
          if abs(high[k] - liqH) <= tol then
             eqHcount = eqHcount + 1
          endif
          if abs(low[k] - liqL) <= tol then
             eqLcount = eqLcount + 1
          endif
       next
       if eqHcount >= 2 then
          $candTop[candCount] = liqH + tol
          $candBot[candCount] = liqH - tol
          $candIsSup[candCount] = 0
          $candSrc[candCount] = 4
          $candVol[candCount] = avgVolLiq
          candCount = candCount + 1
       endif
       if eqLcount >= 2 then
          $candTop[candCount] = liqL + tol
          $candBot[candCount] = liqL - tol
          $candIsSup[candCount] = 1
          $candSrc[candCount] = 4
          $candVol[candCount] = avgVolLiq
          candCount = candCount + 1
       endif
    endif
    
    //-----PROCESS CANDIDATES (overlap + add)------//
    if candCount > 0 then
       for c = 0 to candCount - 1 do
          cTop = $candTop[c]
          cBot = $candBot[c]
          cMid = (cTop + cBot) / 2
          cWidth = cTop - cBot
          cIsSup = $candIsSup[c]
          cSrc = $candSrc[c]
          cVol = $candVol[c]
          
          // Overlap with existing zones?
          overlap = 0
          if zCount > 0 then
             for q = 0 to zCount - 1 do
                if abs($zoneMid[q] - cMid) < cWidth * 2 then
                   overlap = 1
                endif
             next
          endif
          
          if overlap = 0 then
             // Slot: append, or evict lowest score
             if zCount < maxZones then
                idx = zCount
                zCount = zCount + 1
             else
                minS = 999
                minIdx = 0
                for q = 0 to maxZones - 1 do
                   if $zoneScore[q] < minS then
                      minS = $zoneScore[q]
                      minIdx = q
                   endif
                next
                idx = minIdx
             endif
             
             $zoneTop[idx] = cTop
             $zoneBot[idx] = cBot
             $zoneMid[idx] = cMid
             $zoneIsSup[idx] = cIsSup
             $zoneSrc[idx] = cSrc
             $zoneCreated[idx] = barindex
             $zoneLastTouch[idx] = barindex
             $zoneTouches[idx] = 0
             $zoneViol[idx] = 0
             $zoneFresh[idx] = 1
             cv = 1
             if avgVol20 > 0 then
                cv = cVol / avgVol20
             endif
             $zoneCreateVol[idx] = cv
             $zoneTouchVol[idx] = 0
             $zoneConf[idx] = 1
             $zoneScore[idx] = 50
          endif
       next
    endif
    
    //-----TOUCH & VIOLATION TRACKER---------------//
    if zCount > 0 then
       for q = 0 to zCount - 1 do
          zT = $zoneTop[q]
          zB = $zoneBot[q]
          zIs = $zoneIsSup[q]
          // Touch (bar entered the zone)
          if low <= zT and high >= zB and barindex > $zoneCreated[q] then
             $zoneFresh[q] = 0
             tc = $zoneTouches[q] + 1
             $zoneTouches[q] = tc
             tvr = 1
             if avgVol20 > 0 then
                tvr = volume / avgVol20
             endif
             if tc = 1 then
                $zoneTouchVol[q] = tvr
             else
                $zoneTouchVol[q] = ($zoneTouchVol[q] * (tc - 1) + tvr) / tc
             endif
             $zoneLastTouch[q] = barindex
          endif
          // Violation: close beyond the zone in the wrong direction
          viol = 0
          if zIs = 1 and close < zB then
             viol = 1
          endif
          if zIs = 0 and close > zT then
             viol = 1
          endif
          if viol = 1 then
             $zoneViol[q] = $zoneViol[q] + 1
          endif
       next
    endif
    
    //-----CONFLUENCE COUNT------------------------//
    if zCount > 0 then
       for q = 0 to zCount - 1 do
          cnt = 1
          for r = 0 to zCount - 1 do
             if r <> q then
                if $zoneTop[q] >= $zoneBot[r] and $zoneBot[q] <= $zoneTop[r] then
                   cnt = cnt + 1
                endif
             endif
          next
          $zoneConf[q] = cnt
       next
    endif
    
    //-----COMPOSITE SCORE ENGINE------------------//
    totalW = wTouch + wTouchVol + wCreateVol + wConf + wFresh + wRegime
    if zCount > 0 then
       for q = 0 to zCount - 1 do
          touchN = min($zoneTouches[q], 5) / 5
          volConv = min($zoneTouchVol[q], 3) / 3
          createVn = min($zoneCreateVol[q], 3) / 3
          confN = min($zoneConf[q], 5) / 5
          freshN = 0
          if $zoneFresh[q] = 1 then
             freshN = 1
          else
             decay = 1 - (barindex - $zoneLastTouch[q]) / 300
             if decay > 0 then
                freshN = decay
             endif
          endif
          violPen = min($zoneViol[q] * 0.25, 1)
          rf = 0.5
          if $zoneIsSup[q] = 1 then
             if regime = 1 then
                rf = 1
             elsif regime = 2 then
                rf = 0.8
             elsif regime = 0 then
                rf = 0.5
             elsif regime = -2 then
                rf = 0.3
             else
                rf = 0.2
             endif
          else
             if regime = -1 then
                rf = 1
             elsif regime = -2 then
                rf = 0.8
             elsif regime = 0 then
                rf = 0.5
             elsif regime = 2 then
                rf = 0.3
             else
                rf = 0.2
             endif
          endif
          raw = (touchN * wTouch + volConv * wTouchVol + createVn * wCreateVol + confN * wConf + freshN * wFresh + rf * wRegime - violPen * 6) / totalW * 100
          sc = max(0, min(100, raw))
          $zoneScore[q] = sc
       next
    endif
    
    //-----WARNINGS--------------------------------//
    // 0=none  1=approach A  2=approach B  3=trap suspected
    warning = 0
    if zCount > 0 then
       for q = 0 to zCount - 1 do
          zScore = $zoneScore[q]
          zMid2 = $zoneMid[q]
          zViol2 = $zoneViol[q]
          dist = abs(zMid2 - close)
          if zScore >= 80 and dist < atrV * warnAtrDist then
             warning = 1
          elsif zScore >= 65 and dist < atrV * warnAtrDist and warning = 0 then
             warning = 2
          endif
          if zViol2 >= 1 and dist < atrV * 0.3 and volume < avgVol20 * 0.7 and warning < 3 then
             warning = 3
          endif
       next
    endif
    
    //-----LAST-BAR RENDERING----------------------//
    if islastbarupdate then
       if zCount > 0 then
          // Top-N selection (partial selection sort)
          for q = 0 to zCount - 1 do
             $drawFlag[q] = 0
          next
          for k = 0 to topN - 1 do
             bestS = -1
             bestIdx = -1
             for q = 0 to zCount - 1 do
                if $drawFlag[q] = 0 and $zoneScore[q] > bestS then
                   bestS = $zoneScore[q]
                   bestIdx = q
                endif
             next
             if bestIdx >= 0 then
                $drawFlag[bestIdx] = 1
             endif
          next
          
          // Draw selected zones
          for q = 0 to zCount - 1 do
             if $drawFlag[q] = 1 then
                zScoreD = $zoneScore[q]
                zIsD = $zoneIsSup[q]
                if zScoreD >= 50 or showGradeC = 1 then
                   if zIsD = 1 then
                      if zScoreD >= 80 then
                         r = 0
                         g = 200
                         b = 100
                         a = 90
                      elsif zScoreD >= 65 then
                         r = 30
                         g = 180
                         b = 90
                         a = 60
                      else
                         r = 80
                         g = 160
                         b = 100
                         a = 35
                      endif
                   else
                      if zScoreD >= 80 then
                         r = 230
                         g = 30
                         b = 30
                         a = 90
                      elsif zScoreD >= 65 then
                         r = 220
                         g = 90
                         b = 50
                         a = 60
                      else
                         r = 200
                         g = 130
                         b = 130
                         a = 35
                      endif
                   endif
                   drawrectangle($zoneCreated[q], $zoneBot[q], barindex + 5, $zoneTop[q]) coloured(r, g, b, 200) fillcolor(r, g, b, a)
                endif
             endif
          next
          
          // Nearest support and resistance
          nsLow = 0
          nsScore = 0
          nrHigh = 0
          nrScore = 0
          bestSupDist = 999999
          bestResDist = 999999
          for q = 0 to zCount - 1 do
             if $zoneIsSup[q] = 1 and $zoneTop[q] < close then
                dS = close - $zoneTop[q]
                if dS < bestSupDist then
                   bestSupDist = dS
                   nsLow = $zoneTop[q]
                   nsScore = $zoneScore[q]
                endif
             endif
             if $zoneIsSup[q] = 0 and $zoneBot[q] > close then
                dR = $zoneBot[q] - close
                if dR < bestResDist then
                   bestResDist = dR
                   nrHigh = $zoneBot[q]
                   nrScore = $zoneScore[q]
                endif
             endif
          next
          
          // Highlighted nearest S/R: saturated horizontal segment + price label at the level
          srLeft = barindex - 30
          srRight = barindex + 30
          if nsLow <> 0 then
             drawsegment(srLeft, nsLow, srRight, nsLow) coloured(0, 230, 100, 255)
             drawtext("#nsLow#", srRight + 2, nsLow+0.15*atrV, sansserif, bold, 11) coloured(0, 230, 100)
          endif
          if nrHigh <> 0 then
             drawsegment(srLeft, nrHigh, srRight, nrHigh) coloured(230, 30, 30, 255)
             drawtext("#nrHigh#", srRight + 2, nrHigh+0.15*atrV, sansserif, bold, 11) coloured(230, 30, 30)
          endif
          
          // Compact panel: regime + warning only
          panelX = -200
          topY = -100
          if regime = 1 then
             drawtext("Regime: STRONG BULL", panelX, topY, sansserif, bold, 11) coloured(0, 200, 100)anchor(topright,xshift,yshift)
          elsif regime = 2 then
             drawtext("Regime: WEAK BULL", panelX, topY, sansserif, bold, 11) coloured(80, 180, 120)anchor(topright,xshift,yshift)
          elsif regime = -1 then
             drawtext("Regime: STRONG BEAR", panelX, topY, sansserif, bold, 11) coloured(220, 50, 50)anchor(topright,xshift,yshift)
          elsif regime = -2 then
             drawtext("Regime: WEAK BEAR", panelX, topY, sansserif, bold, 11) coloured(220, 120, 80)anchor(topright,xshift,yshift)
          else
             drawtext("Regime: RANGE", panelX, topY, sansserif, bold, 11) coloured(150, 150, 150)anchor(topright,xshift,yshift)
          endif
          if warning = 1 then
             drawtext("Approaching A-zone", panelX, topY - 30, sansserif, bold, 11) coloured(255, 100, 0)anchor(topright,xshift,yshift)
          elsif warning = 2 then
             drawtext("Approaching B-zone", panelX, topY - 30, sansserif, standard, 10) coloured(220, 150, 60)anchor(topright,xshift,yshift)
          elsif warning = 3 then
             drawtext("Trap suspected", panelX, topY - 30, sansserif, bold, 11) coloured(255, 50, 50)anchor(topright,xshift,yshift)
          endif
       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
Summary

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

Topic Details
Forum: TradingView to ProRealTime Translation Center Forum
Started: 04/30/2026
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...