Machine learning RSI

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #261779 quote
    Iván González
    Moderator
    Legend

    Here we have a new interesting code by Zeiierman.

    This indicator has 2 parts (price and new pannel)

    // ============================================================
    // PRC_Machine Learning RSI (Zeiierman) - PORT ProBuilder
    // version = 0
    // 05.06.2026
    // Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    // ============================================================
    
    rsiBase     = 14
    memoryDepth = 400
    kNeighbors  = 8
    winLen      = 100
    spacingBars = 4
    horizonBars = 4
    atrFactor   = 0.5
    
    wVal = 1.0
    wSlp = 1.0
    wAcc = 1.0
    wMid = 1.0
    wPct = 1.0
    wChn = 1.0
    wSpr = 1.0
    wReg = 1.0
    
    stMultBase = 1.5
    stMlResp   = 1.0
    stAtrLen   = 10
    trendLen   = 50
    chopCut    = 0.5
    useChop    = 1
    smoothLen  = 10
    
    gateRank     = 60
    gateConf     = 50
    useTrendGate = 1
    useVolBand   = 1
    volBandLo    = 20
    volBandHi    = 85
    coolBars     = 5
    
    bankCap = round(memoryDepth / spacingBars)
    src     = close
    stSrc   = (high + low) / 2
    
    rOsc   = rsi[rsiBase](src)
    rfastL = max(2, round(rsiBase / 2))
    rOscF  = rsi[rfastL](src)
    rOscS  = rsi[rsiBase * 2](src)
    atrVal = averagetruerange[14]
    stepLen = 3
    
    fVal = rOsc / 100.0
    
    slopeRaw = rOsc - rOsc[stepLen]
    slLo = lowest[winLen](slopeRaw)
    slHi = highest[winLen](slopeRaw)
    if slHi = slLo then
       fSlp = 0.5
    else
       fSlp = (slopeRaw - slLo) / (slHi - slLo)
    endif
    
    accRaw = rOsc - rOsc[stepLen] - (rOsc[stepLen] - rOsc[2 * stepLen])
    acLo = lowest[winLen](accRaw)
    acHi = highest[winLen](accRaw)
    if acHi = acLo then
       fAcc = 0.5
    else
       fAcc = (accRaw - acLo) / (acHi - acLo)
    endif
    
    fMid = abs(rOsc - 50.0) / 50.0
    
    prCnt = 0
    for p = 1 to winLen do
       if rOsc[p] <= rOsc then
          prCnt = prCnt + 1
       endif
    next
    fPct = prCnt / winLen
    
    churnRaw = std[14](rOsc)
    chLo = lowest[winLen](churnRaw)
    chHi = highest[winLen](churnRaw)
    if chHi = chLo then
       fChn = 0.5
    else
       fChn = (churnRaw - chLo) / (chHi - chLo)
    endif
    
    spreadRaw = rOscF - rOscS
    spLo = lowest[winLen](spreadRaw)
    spHi = highest[winLen](spreadRaw)
    if spHi = spLo then
       fSpr = 0.5
    else
       fSpr = (spreadRaw - spLo) / (spHi - spLo)
    endif
    
    emaR20 = average[20, 1](rOsc)
    regRaw = emaR20 - 50.0
    rgLo = lowest[winLen](regRaw)
    rgHi = highest[winLen](regRaw)
    if rgHi = rgLo then
       fReg = 0.5
    else
       fReg = (regRaw - rgLo) / (rgHi - rgLo)
    endif
    
    moveFwd = src - src[horizonBars]
    bandFwd = atrFactor * atrVal[horizonBars]
    if moveFwd > 2 * bandFwd then
       outcome = 3
    elsif moveFwd > bandFwd then
       outcome = 2
    elsif moveFwd > 0 then
       outcome = 1
    elsif moveFwd < -2 * bandFwd then
       outcome = -3
    elsif moveFwd < -bandFwd then
       outcome = -2
    elsif moveFwd < 0 then
       outcome = -1
    else
       outcome = 0
    endif
    
    once bankPtr = 0
    once bankRows = 0
    once writeCnt = 0
    
    if barindex > horizonBars + winLen then
       writeCnt = writeCnt + 1
       if writeCnt >= spacingBars then
          writeCnt = 0
          $bVal[bankPtr] = fVal[horizonBars]
          $bSlp[bankPtr] = fSlp[horizonBars]
          $bAcc[bankPtr] = fAcc[horizonBars]
          $bMid[bankPtr] = fMid[horizonBars]
          $bPct[bankPtr] = fPct[horizonBars]
          $bChn[bankPtr] = fChn[horizonBars]
          $bSpr[bankPtr] = fSpr[horizonBars]
          $bReg[bankPtr] = fReg[horizonBars]
          $bOut[bankPtr] = outcome
          bankPtr = bankPtr + 1
          if bankPtr >= bankCap then
             bankPtr = 0
          endif
          if bankRows < bankCap then
             bankRows = bankRows + 1
          endif
       endif
    endif
    
    for n = 0 to kNeighbors - 1 do
       $kgap[n] = 10000000000
       $kcls[n] = 0
    next
    
    if bankRows > 1 then
       for idx = 0 to bankRows - 1 do
          dist = wVal * log(1 + abs(fVal - $bVal[idx])) + wSlp * log(1 + abs(fSlp - $bSlp[idx])) + wAcc * log(1 + abs(fAcc - $bAcc[idx])) + wMid * log(1 + abs(fMid - $bMid[idx])) + wPct * log(1 + abs(fPct - $bPct[idx])) + wChn * log(1 + abs(fChn - $bChn[idx])) + wSpr * log(1 + abs(fSpr - $bSpr[idx])) + wReg * log(1 + abs(fReg - $bReg[idx]))
          worst = 0
          worstGap = $kgap[0]
          for j = 1 to kNeighbors - 1 do
             if $kgap[j] > worstGap then
                worstGap = $kgap[j]
                worst = j
             endif
          next
          if dist < worstGap then
             $kgap[worst] = dist
             $kcls[worst] = $bOut[idx]
          endif
       next
    endif
    
    voteTotal = 0.0
    voteScore = 0.0
    voteBull  = 0.0
    voteBear  = 0.0
    kCount    = 0
    gapSum    = 0.0
    for n = 0 to kNeighbors - 1 do
       if $kgap[n] < 10000000000 then
          wgt = 1.0 / (1.0 + $kgap[n])
          voteTotal = voteTotal + wgt
          voteScore = voteScore + $kcls[n] * wgt
          if $kcls[n] > 0 then
             voteBull = voteBull + wgt
          elsif $kcls[n] < 0 then
             voteBear = voteBear + wgt
          endif
          gapSum = gapSum + $kgap[n]
          kCount = kCount + 1
       endif
    next
    
    if voteTotal > 0 then
       analogScore = voteScore / voteTotal
    else
       analogScore = 0.0
    endif
    
    if voteTotal > 0 and analogScore > 0.15 then
       biasDir = 1
    elsif voteTotal > 0 and analogScore < -0.15 then
       biasDir = -1
    else
       biasDir = 0
    endif
    
    if voteTotal > 0 and biasDir = 1 then
       agreeFrac = voteBull / voteTotal
    elsif voteTotal > 0 and biasDir = -1 then
       agreeFrac = voteBear / voteTotal
    else
       agreeFrac = 0.0
    endif
    
    if kCount > 0 then
       avgGap = gapSum / kCount
    else
       avgGap = 0.0
    endif
    wSum = wVal + wSlp + wAcc + wMid + wPct + wChn + wSpr + wReg
    gapScale = wSum * 0.45 + 0.000000001
    gapTight = max(0.0, min(1.0, 1.0 - avgGap / gapScale))
    
    emaTrend = average[trendLen, 1](src)
    emaQuick = average[5, 1](src)
    if atrVal > 0 then
       trendForce = abs(emaQuick - emaTrend) / atrVal
    else
       trendForce = 0
    endif
    chopRaw = trendForce < chopCut
    if useChop then
       chopNow = chopRaw
    else
       chopNow = 0
    endif
    
    convInst = max(-1.0, min(1.0, analogScore / 1.5))
    convSmoothed = average[smoothLen, 1](convInst)
    mlDriveBase = abs(convSmoothed) * 0.5 + gapTight * 0.3 + agreeFrac * 0.2
    mlDrive = max(0.0, min(1.0, mlDriveBase))
    if chopNow then
       mlDrive = mlDrive * 0.35
    endif
    
    adaptMult = stMultBase * (1.0 + stMlResp * (1.0 - mlDrive))
    stAtr  = averagetruerange[stAtrLen]
    upBand = stSrc - adaptMult * stAtr
    dnBand = stSrc + adaptMult * stAtr
    
    if barindex <= 1 then
       stLong = upBand
       stShort = dnBand
       stDir = 1
    else
       if close[1] > stLong[1] then
          stLong = max(upBand, stLong[1])
       else
          stLong = upBand
       endif
       if close[1] < stShort[1] then
          stShort = min(dnBand, stShort[1])
       else
          stShort = dnBand
       endif
       if stDir[1] = -1 and close > stShort[1] then
          stDir = 1
       elsif stDir[1] = 1 and close < stLong[1] then
          stDir = -1
       else
          stDir = stDir[1]
       endif
    endif
    
    if stDir = 1 then
       stLine = stLong
       r = 33
       g = 87
       b = 243
    else
       stLine = stShort
       r = 242
       g = 54
       b = 69
    endif
    
    atrPctCnt = 0
    for q = 1 to 100 do
       if atrVal[q] <= atrVal then
          atrPctCnt = atrPctCnt + 1
       endif
    next
    atrPct = atrPctCnt
    
    slopeUp = rOsc > rOsc[stepLen]
    oscReg  = emaR20
    volHealthy = atrPct >= volBandLo and atrPct <= volBandHi
    slopeFit = (biasDir = 1 and slopeUp) or (biasDir = -1 and slopeUp = 0)
    stretched = (biasDir = 1 and rOsc > 70) or (biasDir = -1 and rOsc < 30)
    emaR5 = average[5, 1](rOsc)
    oscSmoothUp = emaR5 > emaR5[1]
    trendAligned = (biasDir = 1 and stDir = 1) or (biasDir = -1 and stDir = -1)
    
    once stanceState = 0
    once stanceAge   = 0
    once lastEntryBar = -1000
    
    if useTrendGate then
       gateTrend = trendAligned
    else
       gateTrend = 1
    endif
    if useVolBand then
       gateVol = volHealthy
    else
       gateVol = 1
    endif
    gatesPass = gateTrend and gateVol and (chopNow = 0)
    
    if biasDir = 1 and gatesPass then
       stanceState = 1
    elsif biasDir = -1 and gatesPass then
       stanceState = -1
    else
       stanceState = stanceState[1]
    endif
    
    stanceChanged = stanceState <> stanceState[1]
    if stanceChanged then
       stanceAge = 0
    else
       stanceAge = stanceAge[1] + 1
    endif
    earlyFlip = stanceChanged and (stanceChanged[1] or stanceChanged[2] or stanceChanged[3])
    
    pAgree = 25.0 * agreeFrac
    pGap   = 15.0 * gapTight
    
    if slopeFit then
       pStructA = 10.0
    else
       pStructA = 0.0
    endif
    if stretched then
       pStructB = 0.0
    else
       pStructB = 5.0
    endif
    pStruct = pStructA + pStructB
    
    if trendAligned then
       pTrend = 10.0
    else
       pTrend = 0.0
    endif
    
    if volHealthy then
       pVol = 10.0
    elsif atrPct < volBandLo then
       pVol = 5.0
    else
       pVol = 3.0
    endif
    
    regFit = (biasDir = 1 and oscReg > 55) or (biasDir = -1 and oscReg < 45)
    if regFit then
       pReg = 10.0
    elsif oscReg >= 45 and oscReg <= 55 then
       pReg = 4.0
    else
       pReg = 6.0
    endif
    
    if (biasDir = 1 and oscSmoothUp) or (biasDir = -1 and oscSmoothUp = 0) then
       pSmooth = 5.0
    else
       pSmooth = 0.0
    endif
    
    pHold = min(5.0, stanceAge)
    
    penChop = 0.0
    if chopRaw then
       penChop = 8.0
    endif
    penStr = 0.0
    if stretched then
       penStr = 6.0
    endif
    penFlip = 0.0
    if earlyFlip then
       penFlip = 6.0
    endif
    penK = 0.0
    if kCount < kNeighbors then
       penK = 5.0 * (kNeighbors - kCount) / kNeighbors
    endif
    pPen = min(20.0, penChop + penStr + penFlip + penK)
    
    rawRank = pAgree + pGap + pStruct + pTrend + pVol + pReg + pSmooth + pHold - pPen
    if biasDir = 0 then
       rankVal = 0.0
    else
       rankVal = max(0.0, min(100.0, rawRank))
    endif
    
    if slopeFit then
       confSlope = 10.0
    else
       confSlope = 0.0
    endif
    confFlipPen = 0.0
    if earlyFlip then
       confFlipPen = 15.0
    endif
    confKPen = 0.0
    if kCount < kNeighbors then
       confKPen = 10.0 * (kNeighbors - kCount) / kNeighbors
    endif
    confRaw = 40.0 * agreeFrac + 25.0 * gapTight + 15.0 * min(1.0, stanceAge / 5.0) + confSlope - confFlipPen - confKPen
    if biasDir = 0 then
       confVal = 0.0
    else
       confVal = max(0.0, min(100.0, confRaw))
    endif
    
    flipLong  = stanceState = 1 and stanceState[1] <> 1
    flipShort = stanceState = -1 and stanceState[1] <> -1
    qualifies = rankVal >= gateRank and confVal >= gateConf
    coolOK    = barindex - lastEntryBar >= coolBars
    triggerLong  = flipLong and qualifies and coolOK
    triggerShort = flipShort and qualifies and coolOK
    if triggerLong or triggerShort then
       lastEntryBar = barindex
    endif
    
    placebuy  = lowest[5](low) - 0.25 * atrVal
    placesell = highest[5](high) + 0.25 * atrVal
    if triggerLong then
       drawtext("▲", barindex, placebuy) coloured(50, 205, 50)
    endif
    if triggerShort then
       drawtext("▼", barindex, placesell) coloured(242, 54, 69)
    endif
    
    return stLine as "ML Supertrend" coloured(r, g, b)
    


    // ============================================================
    // PRC_Machine Learning RSI (Zeiierman)
    // version = 0
    // 05.06.2026
    // Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    // ============================================================
    
    rsiBase     = 14
    memoryDepth = 400
    kNeighbors  = 8
    winLen      = 100
    spacingBars = 4
    horizonBars = 4
    atrFactor   = 0.5
    
    wVal = 1.0
    wSlp = 1.0
    wAcc = 1.0
    wMid = 1.0
    wPct = 1.0
    wChn = 1.0
    wSpr = 1.0
    wReg = 1.0
    
    stMultBase = 1.5
    stMlResp   = 1.0
    stAtrLen   = 10
    trendLen   = 50
    chopCut    = 0.5
    useChop    = 1
    smoothLen  = 10
    
    useTrendGate = 1
    useVolBand   = 1
    volBandLo    = 20
    volBandHi    = 85
    
    maType = 1     // 0=None, 1=SMA, 2=SMA+BB, 3=EMA, 4=SMMA, 5=WMA, 6=VWMA
    maLen  = 14
    bbMult = 2.0
    
    bullR = 41
    bullG = 98
    bullB = 255
    bearR = 255
    bearG = 93
    bearB = 0
    
    bankCap = round(memoryDepth / spacingBars)
    src     = close
    stSrc   = (high + low) / 2
    
    rOsc   = rsi[rsiBase](src)
    rfastL = max(2, round(rsiBase / 2))
    rOscF  = rsi[rfastL](src)
    rOscS  = rsi[rsiBase * 2](src)
    atrVal = averagetruerange[14]
    stepLen = 3
    
    fVal = rOsc / 100.0
    
    slopeRaw = rOsc - rOsc[stepLen]
    slLo = lowest[winLen](slopeRaw)
    slHi = highest[winLen](slopeRaw)
    if slHi = slLo then
       fSlp = 0.5
    else
       fSlp = (slopeRaw - slLo) / (slHi - slLo)
    endif
    
    accRaw = rOsc - rOsc[stepLen] - (rOsc[stepLen] - rOsc[2 * stepLen])
    acLo = lowest[winLen](accRaw)
    acHi = highest[winLen](accRaw)
    if acHi = acLo then
       fAcc = 0.5
    else
       fAcc = (accRaw - acLo) / (acHi - acLo)
    endif
    
    fMid = abs(rOsc - 50.0) / 50.0
    
    prCnt = 0
    for p = 1 to winLen do
       if rOsc[p] <= rOsc then
          prCnt = prCnt + 1
       endif
    next
    fPct = prCnt / winLen
    
    churnRaw = std[14](rOsc)
    chLo = lowest[winLen](churnRaw)
    chHi = highest[winLen](churnRaw)
    if chHi = chLo then
       fChn = 0.5
    else
       fChn = (churnRaw - chLo) / (chHi - chLo)
    endif
    
    spreadRaw = rOscF - rOscS
    spLo = lowest[winLen](spreadRaw)
    spHi = highest[winLen](spreadRaw)
    if spHi = spLo then
       fSpr = 0.5
    else
       fSpr = (spreadRaw - spLo) / (spHi - spLo)
    endif
    
    emaR20 = average[20, 1](rOsc)
    regRaw = emaR20 - 50.0
    rgLo = lowest[winLen](regRaw)
    rgHi = highest[winLen](regRaw)
    if rgHi = rgLo then
       fReg = 0.5
    else
       fReg = (regRaw - rgLo) / (rgHi - rgLo)
    endif
    
    moveFwd = src - src[horizonBars]
    bandFwd = atrFactor * atrVal[horizonBars]
    if moveFwd > 2 * bandFwd then
       outcome = 3
    elsif moveFwd > bandFwd then
       outcome = 2
    elsif moveFwd > 0 then
       outcome = 1
    elsif moveFwd < -2 * bandFwd then
       outcome = -3
    elsif moveFwd < -bandFwd then
       outcome = -2
    elsif moveFwd < 0 then
       outcome = -1
    else
       outcome = 0
    endif
    
    once bankPtr = 0
    once bankRows = 0
    once writeCnt = 0
    
    if barindex > horizonBars + winLen then
       writeCnt = writeCnt + 1
       if writeCnt >= spacingBars then
          writeCnt = 0
          $bVal[bankPtr] = fVal[horizonBars]
          $bSlp[bankPtr] = fSlp[horizonBars]
          $bAcc[bankPtr] = fAcc[horizonBars]
          $bMid[bankPtr] = fMid[horizonBars]
          $bPct[bankPtr] = fPct[horizonBars]
          $bChn[bankPtr] = fChn[horizonBars]
          $bSpr[bankPtr] = fSpr[horizonBars]
          $bReg[bankPtr] = fReg[horizonBars]
          $bOut[bankPtr] = outcome
          bankPtr = bankPtr + 1
          if bankPtr >= bankCap then
             bankPtr = 0
          endif
          if bankRows < bankCap then
             bankRows = bankRows + 1
          endif
       endif
    endif
    
    for n = 0 to kNeighbors - 1 do
       $kgap[n] = 10000000000
       $kcls[n] = 0
    next
    
    if bankRows > 1 then
       for idx = 0 to bankRows - 1 do
          dist = wVal * log(1 + abs(fVal - $bVal[idx])) + wSlp * log(1 + abs(fSlp - $bSlp[idx])) + wAcc * log(1 + abs(fAcc - $bAcc[idx])) + wMid * log(1 + abs(fMid - $bMid[idx])) + wPct * log(1 + abs(fPct - $bPct[idx])) + wChn * log(1 + abs(fChn - $bChn[idx])) + wSpr * log(1 + abs(fSpr - $bSpr[idx])) + wReg * log(1 + abs(fReg - $bReg[idx]))
          worst = 0
          worstGap = $kgap[0]
          for j = 1 to kNeighbors - 1 do
             if $kgap[j] > worstGap then
                worstGap = $kgap[j]
                worst = j
             endif
          next
          if dist < worstGap then
             $kgap[worst] = dist
             $kcls[worst] = $bOut[idx]
          endif
       next
    endif
    
    voteTotal = 0.0
    voteScore = 0.0
    voteBull  = 0.0
    voteBear  = 0.0
    kCount    = 0
    gapSum    = 0.0
    for n = 0 to kNeighbors - 1 do
       if $kgap[n] < 10000000000 then
          wgt = 1.0 / (1.0 + $kgap[n])
          voteTotal = voteTotal + wgt
          voteScore = voteScore + $kcls[n] * wgt
          if $kcls[n] > 0 then
             voteBull = voteBull + wgt
          elsif $kcls[n] < 0 then
             voteBear = voteBear + wgt
          endif
          gapSum = gapSum + $kgap[n]
          kCount = kCount + 1
       endif
    next
    
    if voteTotal > 0 then
       analogScore = voteScore / voteTotal
    else
       analogScore = 0.0
    endif
    
    if voteTotal > 0 and analogScore > 0.15 then
       biasDir = 1
    elsif voteTotal > 0 and analogScore < -0.15 then
       biasDir = -1
    else
       biasDir = 0
    endif
    
    if voteTotal > 0 and biasDir = 1 then
       agreeFrac = voteBull / voteTotal
    elsif voteTotal > 0 and biasDir = -1 then
       agreeFrac = voteBear / voteTotal
    else
       agreeFrac = 0.0
    endif
    
    if kCount > 0 then
       avgGap = gapSum / kCount
    else
       avgGap = 0.0
    endif
    wSum = wVal + wSlp + wAcc + wMid + wPct + wChn + wSpr + wReg
    gapScale = wSum * 0.45 + 0.000000001
    gapTight = max(0.0, min(1.0, 1.0 - avgGap / gapScale))
    
    emaTrend = average[trendLen, 1](src)
    emaQuick = average[5, 1](src)
    if atrVal > 0 then
       trendForce = abs(emaQuick - emaTrend) / atrVal
    else
       trendForce = 0
    endif
    chopRaw = trendForce < chopCut
    if useChop then
       chopNow = chopRaw
    else
       chopNow = 0
    endif
    
    convInst = max(-1.0, min(1.0, analogScore / 1.5))
    convSmoothed = average[smoothLen, 1](convInst)
    mlDriveBase = abs(convSmoothed) * 0.5 + gapTight * 0.3 + agreeFrac * 0.2
    mlDrive = max(0.0, min(1.0, mlDriveBase))
    if chopNow then
       mlDrive = mlDrive * 0.35
    endif
    
    adaptMult = stMultBase * (1.0 + stMlResp * (1.0 - mlDrive))
    stAtr  = averagetruerange[stAtrLen]
    upBand = stSrc - adaptMult * stAtr
    dnBand = stSrc + adaptMult * stAtr
    
    if barindex <= 1 then
       stLong = upBand
       stShort = dnBand
       stDir = 1
    else
       if close[1] > stLong[1] then
          stLong = max(upBand, stLong[1])
       else
          stLong = upBand
       endif
       if close[1] < stShort[1] then
          stShort = min(dnBand, stShort[1])
       else
          stShort = dnBand
       endif
       if stDir[1] = -1 and close > stShort[1] then
          stDir = 1
       elsif stDir[1] = 1 and close < stLong[1] then
          stDir = -1
       else
          stDir = stDir[1]
       endif
    endif
    
    atrPctCnt = 0
    for q = 1 to 100 do
       if atrVal[q] <= atrVal then
          atrPctCnt = atrPctCnt + 1
       endif
    next
    atrPct = atrPctCnt
    
    slopeUp = rOsc > rOsc[stepLen]
    oscReg  = emaR20
    volHealthy = atrPct >= volBandLo and atrPct <= volBandHi
    slopeFit = (biasDir = 1 and slopeUp) or (biasDir = -1 and slopeUp = 0)
    stretched = (biasDir = 1 and rOsc > 70) or (biasDir = -1 and rOsc < 30)
    emaR5 = average[5, 1](rOsc)
    oscSmoothUp = emaR5 > emaR5[1]
    trendAligned = (biasDir = 1 and stDir = 1) or (biasDir = -1 and stDir = -1)
    
    once stanceState = 0
    once stanceAge   = 0
    
    if useTrendGate then
       gateTrend = trendAligned
    else
       gateTrend = 1
    endif
    if useVolBand then
       gateVol = volHealthy
    else
       gateVol = 1
    endif
    gatesPass = gateTrend and gateVol and (chopNow = 0)
    
    if biasDir = 1 and gatesPass then
       stanceState = 1
    elsif biasDir = -1 and gatesPass then
       stanceState = -1
    else
       stanceState = stanceState[1]
    endif
    
    stanceChanged = stanceState <> stanceState[1]
    if stanceChanged then
       stanceAge = 0
    else
       stanceAge = stanceAge[1] + 1
    endif
    earlyFlip = stanceChanged and (stanceChanged[1] or stanceChanged[2] or stanceChanged[3])
    
    pAgree = 25.0 * agreeFrac
    pGap   = 15.0 * gapTight
    
    if slopeFit then
       pStructA = 10.0
    else
       pStructA = 0.0
    endif
    if stretched then
       pStructB = 0.0
    else
       pStructB = 5.0
    endif
    pStruct = pStructA + pStructB
    
    if trendAligned then
       pTrend = 10.0
    else
       pTrend = 0.0
    endif
    
    if volHealthy then
       pVol = 10.0
    elsif atrPct < volBandLo then
       pVol = 5.0
    else
       pVol = 3.0
    endif
    
    regFit = (biasDir = 1 and oscReg > 55) or (biasDir = -1 and oscReg < 45)
    if regFit then
       pReg = 10.0
    elsif oscReg >= 45 and oscReg <= 55 then
       pReg = 4.0
    else
       pReg = 6.0
    endif
    
    if (biasDir = 1 and oscSmoothUp) or (biasDir = -1 and oscSmoothUp = 0) then
       pSmooth = 5.0
    else
       pSmooth = 0.0
    endif
    
    pHold = min(5.0, stanceAge)
    
    penChop = 0.0
    if chopRaw then
       penChop = 8.0
    endif
    penStr = 0.0
    if stretched then
       penStr = 6.0
    endif
    penFlip = 0.0
    if earlyFlip then
       penFlip = 6.0
    endif
    penK = 0.0
    if kCount < kNeighbors then
       penK = 5.0 * (kNeighbors - kCount) / kNeighbors
    endif
    pPen = min(20.0, penChop + penStr + penFlip + penK)
    
    rawRank = pAgree + pGap + pStruct + pTrend + pVol + pReg + pSmooth + pHold - pPen
    if biasDir = 0 then
       rankVal = 0.0
    else
       rankVal = max(0.0, min(100.0, rawRank))
    endif
    
    intensity = max(0.0, min(1.0, average[3, 1](rankVal) / 100.0))
    mlTilt = max(-1.0, min(1.0, convSmoothed)) * intensity * 18.0
    mlRSI = average[3, 1](max(0.0, min(100.0, rOsc + mlTilt)))
    
    gradPos = max(0.0, min(1.0, (mlRSI - 28.0) / 44.0))
    rCol = round(bearR + (bullR - bearR) * gradPos)
    gCol = round(bearG + (bullG - bearG) * gradPos)
    bCol = round(bearB + (bullB - bearB) * gradPos)
    
    if maType = 1 or maType = 2 then
       sigLine = average[maLen](mlRSI)
    elsif maType = 3 then
       sigLine = average[maLen, 1](mlRSI)
    elsif maType = 4 then
       sigLine = average[maLen, 3](mlRSI)
    elsif maType = 5 then
       sigLine = average[maLen, 2](mlRSI)
    elsif maType = 6 then
       volSum = summation[maLen](volume)
       if volSum > 0 then
          sigLine = summation[maLen](mlRSI * volume) / volSum
       else
          sigLine = undefined
       endif
    else
       sigLine = undefined
    endif
    
    if maType = 2 then
       bbDev = std[maLen](mlRSI) * bbMult
       bbUp = sigLine + bbDev
       bbDn = sigLine - bbDev
    else
       bbUp = undefined
       bbDn = undefined
    endif
    
    return mlRSI as "ML RSI" coloured(rCol, gCol, bCol) style(line, 2), sigLine as "Signal" coloured(227, 177, 58), bbUp as "BB Up" coloured(150, 150, 150), bbDn as "BB Dn" coloured(150, 150, 150), 70 as "OB", 50 as "Mid", 30 as "OS"
    



    robertogozzi thanked this post
    TSLA-1-hora.png TSLA-1-hora.png
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

TradingView to ProRealTime Translation Center

New Reply
Author
Summary

This topic contains 1 voice and has 0 replies.

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