SuperTrend + Relative Volume – FluxChart – Conversion Required

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #258340 quote
    adeelq79adeelq79
    Participant
    Senior
    #258348 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Here it is:

    //---------------------------------------------------------------//
    // PRC_SuperTrend + Relative Volume (Percentile) (by FluxCharts)
    // 20.02.2026
    // version = 0
    // Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    //---------------------------------------------------------------//
    //-----Inputs----------------------------------------------------//
    //---------------------------------------------------------------//
    atrLength = 10        // ATR Length
    atrMult = 3           // ATR Multiplier
    maxSamples = 100      // Max break samples (bins in original)
    barLength = 25        // Relative Volume EMA Length
    actThreshold = 70     // Activation Threshold % (0-100)
    actEnabled = 0        // 1=Enable Threshold Gate
    showLabels = 1        // 1=Show Vol% labels on breaks
    //---------------------------------------------------------------//
    //-----ATR & SuperTrend (ML Adaptive pattern)--------------------//
    //---------------------------------------------------------------//
    myATR = averagetruerange[atrLength](close)
    src = (high + low) / 2
    candUp = src + atrMult * myATR
    candDn = src - atrMult * myATR
    
    ONCE upperST = candUp
    ONCE lowerST = candDn
    prevUpper = upperST[1]
    prevLower = lowerST[1]
    
    IF (candDn <= prevLower AND close[1] >= prevLower) THEN
       lowerST = prevLower
    ELSE
       lowerST = candDn
    ENDIF
    
    IF (candUp >= prevUpper AND close[1] <= prevUpper) THEN
       upperST = prevUpper
    ELSE
       upperST = candUp
    ENDIF
    
    ONCE stValue = src
    prevST = stValue[1]
    
    IF barindex = 0 THEN
       stDir = 1
    ELSE
       IF prevST = prevUpper THEN
          IF close > upperST THEN
             stDir = -1
          ELSE
             stDir = 1
          ENDIF
       ELSE
          IF close < lowerST THEN
             stDir = 1
          ELSE
             stDir = -1
          ENDIF
       ENDIF
    ENDIF
    
    IF stDir = -1 THEN
       stValue = lowerST
    ELSE
       stValue = upperST
    ENDIF
    
    // Trend flags & breaks
    bull = stDir = -1
    bear = stDir = 1
    bullBreak = bull AND bull[1] = 0
    bearBreak = bear AND bear[1] = 0
    //---------------------------------------------------------------//
    //-----Buy/Sell Relative Volume----------------------------------//
    //---------------------------------------------------------------//
    IF high <> low THEN
       buyVolRaw = volume * (close - low) / (high - low)
       sellVolRaw = volume * (high - close) / (high - low)
    ELSE
       buyVolRaw = volume * 0.5
       sellVolRaw = volume * 0.5
    ENDIF
    
    buyVolAvg = average[barLength,1](buyVolRaw)
    buyVolShort = average[10,1](buyVolRaw)
    sellVolAvg = average[barLength,1](sellVolRaw)
    sellVolShort = average[10,1](sellVolRaw)
    
    IF buyVolAvg > 0 THEN
       buyVol = buyVolShort / buyVolAvg
    ELSE
       buyVol = 1
    ENDIF
    
    IF sellVolAvg > 0 THEN
       sellVol = sellVolShort / sellVolAvg
    ELSE
       sellVol = 1
    ENDIF
    //---------------------------------------------------------------//
    //-----FIFO Arrays (volume on breaks)----------------------------//
    //---------------------------------------------------------------//
    ONCE bullCount = 0
    ONCE bearCount = 0
    
    IF bullBreak AND volume > 0 THEN
       IF bullCount >= maxSamples THEN
          FOR i = 1 TO maxSamples - 1 DO
             $bullVols[i] = $bullVols[i + 1]
          NEXT
          $bullVols[maxSamples] = buyVol
       ELSE
          bullCount = bullCount + 1
          $bullVols[bullCount] = buyVol
       ENDIF
    ENDIF
    
    IF bearBreak AND volume > 0 THEN
       IF bearCount >= maxSamples THEN
          FOR i = 1 TO maxSamples - 1 DO
             $bearVols[i] = $bearVols[i + 1]
          NEXT
          $bearVols[maxSamples] = sellVol
       ELSE
          bearCount = bearCount + 1
          $bearVols[bearCount] = sellVol
       ENDIF
    ENDIF
    //---------------------------------------------------------------//
    //-----Percentile Ranking (replaces KDE)-------------------------//
    //---------------------------------------------------------------//
    volumeProb = 0.5
    
    IF bull AND bullCount > 0 THEN
       pctCount = 0
       FOR i = 1 TO bullCount DO
          IF $bullVols[i] <= buyVol THEN
             pctCount = pctCount + 1
          ENDIF
       NEXT
       volumeProb = pctCount / bullCount
    ENDIF
    
    IF bear AND bearCount > 0 THEN
       pctCount = 0
       FOR i = 1 TO bearCount DO
          IF $bearVols[i] <= sellVol THEN
             pctCount = pctCount + 1
          ENDIF
       NEXT
       volumeProb = pctCount / bearCount
    ENDIF
    //---------------------------------------------------------------//
    //-----Threshold & Final Direction-------------------------------//
    //---------------------------------------------------------------//
    IF actEnabled THEN
       thresholdOK = volumeProb >= actThreshold / 100
    ELSE
       thresholdOK = 1
    ENDIF
    
    bullCond = bullBreak AND thresholdOK
    bearCond = bearBreak AND thresholdOK
    
    IF bullCond THEN
       finalDir = 1
    ELSIF bearCond THEN
       finalDir = 0
    ELSE
       finalDir = finalDir
    ENDIF
    //---------------------------------------------------------------//
    //-----Colors----------------------------------------------------//
    //---------------------------------------------------------------//
    IF finalDir AND bull THEN
       sr = 0
       sg = 209
       sb = 66
       lineAlpha = 255
    ELSIF finalDir = 0 AND bear THEN
       sr = 242
       sg = 54
       sb = 70
       lineAlpha = 255
    ELSE
       sr = 128
       sg = 128
       sb = 128
       lineAlpha = 50
    ENDIF
    
    // Alpha: volumeProb 0->transparent, 1->visible
    stAlpha = round(3 + volumeProb * 117)
    //---------------------------------------------------------------//
    //-----Drawing---------------------------------------------------//
    //---------------------------------------------------------------//
    midPrice = (open + close) / 2
    colorbetween(midPrice, stValue, sr, sg, sb, stAlpha)
    
    IF showLabels THEN
       volPct = round(volumeProb * 100, 1)
       IF bullCond THEN
          drawtext("Vol:#volPct#%", barindex, stValue - myATR* 0.35) coloured("fuchsia")
       ENDIF
       IF bearCond THEN
          drawtext("Vol:#volPct#%", barindex, stValue + myATR* 0.35) coloured("fuchsia")
       ENDIF
    ENDIF
    
    //---------------------------------------------------------------//
    RETURN stValue as "SuperTrend" coloured(sr, sg, sb) style(line, 2)
    
    danskfilou thanked this post
    BTCUSD-Daily.png BTCUSD-Daily.png
    #258351 quote
    adeelq79adeelq79
    Participant
    Senior

    Thank you Ivan. I find this works well on the 15min timeframe.

    Iván González thanked this post
Viewing 3 posts - 1 through 3 (of 3 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
adeelq79 @adeelq79 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by adeelq79adeelq79
6 months, 4 weeks ago.

Topic Details
Forum: TradingView to ProRealTime Translation Center Forum
Started: 02/19/2026
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...