script("Prime / MVP Oscillators - independent", kind="indicator") input mode = 0 input oscillatorLength = 14 input fastLength = 5 input slowLength = 21 input flowLength = 14 input signalLength = 5 input panelHeight = 35 input upperZone = 70 input lowerZone = -70 input pivotStrength = 3 input divergenceMinBars = 5 input divergenceMaxBars = 70 input useVolume = 1 input showMoneyFlow = 1 input showVolumeMatrix = 1 input showPowerBars = 1 input showRank = 1 input rankEveryBars = 8 input showDivergences = 1 input showShifts = 1 input showReversals = 1 input ribbonOpacity = 0.32 input bullColor = "#76F7B8" input bearColor = "#FF4422" input mvpBullColor = "#24B8FF" input mvpBearColor = "#B06CFF" oscPeriod = math.clamp(math.floor(oscillatorLength), 1, 500) fastPeriod = math.clamp(math.floor(fastLength), 1, 500) slowPeriod = math.clamp(math.floor(slowLength), 1, 500) flowPeriod = math.clamp(math.floor(flowLength), 1, 500) signalPeriod = math.clamp(math.floor(signalLength), 1, 500) strength = math.clamp(math.floor(pivotStrength), 1, 50) rankStride = math.clamp(math.floor(rankEveryBars), 1, 100) upper = math.clamp(upperZone, 20, 95) lower = math.clamp(lowerZone, -95, -20) volumeMissing = na(volume) or volume <= 0 typical = (high + low + close) / 3 rsi = ta.rsi(close, oscPeriod) wave = ta.wt(typical, fastPeriod, slowPeriod) fastTrend = ta.ema(close, fastPeriod) slowTrend = ta.ema(close, slowPeriod) range = ta.atr(14) priceChange = barIndex > 0 ? math.abs(close - close[1]) : 0 priceMotion = ta.sum(priceChange, oscPeriod) rawPrime = not na(rsi) and not na(wave) and not na(priceMotion) ? (priceMotion > 0 ? (rsi - 50) * 1.4 + wave * 1.2 : 0) : na firstPrime = ta.ema(rawPrime, fastPeriod) secondPrime = ta.ema(firstPrime, fastPeriod) prime = na(rawPrime) ? na : math.clamp(2 * firstPrime - secondPrime, -100, 100) mfi = ta.mfi(flowPeriod) weightedPrice = ta.vwma(close, flowPeriod) flowInput = not volumeMissing and not na(mfi) ? (mfi - 50) * 2 : na flowAverage = ta.ema(flowInput, fastPeriod) flowSecond = ta.ema(flowAverage, fastPeriod) flowAvailable = useVolume and not volumeMissing and not na(mfi) and not na(weightedPrice) flow = flowAvailable ? math.clamp(2 * flowAverage - flowSecond, -100, 100) : na upVolume = not volumeMissing ? (barIndex > 0 and close > close[1] ? volume : 0) : na downVolume = not volumeMissing ? (barIndex > 0 and close < close[1] ? volume : 0) : na smoothedUpVolume = ta.ema(upVolume, flowPeriod) smoothedDownVolume = ta.ema(downVolume, flowPeriod) volumeTotal = smoothedUpVolume + smoothedDownVolume matrix = flowAvailable ? (volumeTotal > 0 ? (smoothedUpVolume - smoothedDownVolume) / volumeTotal * 100 : 0) : na fairness = flowAvailable ? (range > 0 ? math.clamp((close - weightedPrice) / range * 35, -100, 100) : 0) : na rawMvp = flowAvailable ? flow * 0.65 + fairness * 0.35 : na mvpAverage = ta.ema(rawMvp, fastPeriod) mvpSecond = ta.ema(mvpAverage, fastPeriod) mvp = flowAvailable ? math.clamp(2 * mvpAverage - mvpSecond, -100, 100) : na main = mode == 1 and flowAvailable ? mvp : prime signal = ta.ema(main, signalPeriod) rising = main > main[1] confidence = na(main) ? 0 : math.clamp(math.abs(main) / 100, 0, 1) primeShade = rising ? math.colorGradient(confidence, 0, 1, "#557569", bullColor) : math.colorGradient(confidence, 0, 1, "#795C55", bearColor) mvpShade = rising ? math.colorGradient(confidence, 0, 1, "#446879", mvpBullColor) : math.colorGradient(confidence, 0, 1, "#68547C", mvpBearColor) mainShade = na(main) ? na : (mode == 1 and flowAvailable ? mvpShade : primeShade) flowShade = not flowAvailable ? na : flow >= 0 ? math.colorGradient(math.abs(flow), 0, 100, "#345547", bullColor) : math.colorGradient(math.abs(flow), 0, 100, "#553F38", bearColor) matrixShade = not flowAvailable ? na : matrix >= 0 ? math.colorGradient(math.abs(matrix), 0, 100, "#345547", bullColor) : math.colorGradient(math.abs(matrix), 0, 100, "#553F38", bearColor) volumeUnavailable = not flowAvailable rankReady = not na(prime) and not na(main[1]) and priceMotion > 0 condition1 = rsi > 50 ? 1 : 0 condition2 = wave > 0 ? 1 : 0 condition3 = fastTrend > slowTrend ? 1 : 0 condition4 = close > fastTrend ? 1 : 0 condition5 = rising ? 1 : 0 condition6 = flowAvailable and flow > 0 ? 1 : 0 condition7 = flowAvailable and matrix > 0 ? 1 : 0 rankAvailable = flowAvailable ? 7 : 5 bullVotes = condition1 + condition2 + condition3 + condition4 + condition5 + condition6 + condition7 bearVotes = rankAvailable - bullVotes rankScore = rankReady ? bullVotes - bearVotes : na bullPowerShade = rankReady ? math.colorGradient(bullVotes / rankAvailable, 0, 1, "#24332C", bullColor) : na bearPowerShade = rankReady ? math.colorGradient(bearVotes / rankAvailable, 0, 1, "#332724", bearColor) : na powerTop = showPowerBars and rankReady ? 118 : na powerTopBase = 112 powerBottom = -112 powerBottomBase = showPowerBars and rankReady ? -118 : na matrixTop = showVolumeMatrix and flowAvailable ? -100 : na matrixBottom = -106 tracker = showMoneyFlow and flowAvailable ? flow * 0.6 : na zero = 0 zoneUpper = upper zoneLower = lower outerUpper = 100 outerLower = -100 pane(title="Prime / MVP Suite ยท independent", height=panelHeight, min=-125, max=125, note="Volume components inactive; price oscillator active", noteWhen=volumeUnavailable) fill(outerUpper, zoneUpper, color=bearColor, opacity=0.06) fill(zoneLower, outerLower, color=bullColor, opacity=0.06) fill(tracker, zero, colorSeries=flowShade, opacity=0.2) fill(main, signal, colorSeries=mainShade, opacity=ribbonOpacity) fill(powerTop, powerTopBase, colorSeries=bullPowerShade, style="cells", opacity=0.95) fill(powerBottom, powerBottomBase, colorSeries=bearPowerShade, style="cells", opacity=0.95) fill(matrixTop, matrixBottom, colorSeries=matrixShade, style="cells", opacity=0.95) plot(tracker, title="Money Flow Tracker", colorSeries=flowShade, width=1, opacity=0.6) plot(signal, title="Signal ribbon", colorSeries=mainShade, width=1, opacity=0.6) plot(main, title="Prime / MVP oscillator", colorSeries=mainShade, width=3) hline(0, color="#999999", style="dotted", opacity=0.4) rankLabelBar = barIndex - math.floor(barIndex / rankStride) * rankStride == 0 plotText(zero, when=showRank and rankReady and rankLabelBar, text="" + bullVotes + "/" + rankAvailable, color=rankScore >= 0 ? bullColor : bearColor, position="center", fontSize=8) upperLevel = upper lowerLevel = lower fairnessReverseUp = ta.crossover(fairness, lowerLevel) fairnessReverseDown = ta.crossunder(fairness, upperLevel) plotShape(main, when=showMoneyFlow and flowAvailable and fairnessReverseUp, shape="square", color=bullColor, position="below", size=4) plotShape(main, when=showMoneyFlow and flowAvailable and fairnessReverseDown, shape="square", color=bearColor, position="above", size=4) alertcondition(flowAvailable and fairnessReverseUp, title="Volume-weighted discount recovered") alertcondition(flowAvailable and fairnessReverseDown, title="Volume-weighted premium reversed") reverseUp = ta.crossover(main, lowerLevel) reverseDown = ta.crossunder(main, upperLevel) plotShape(main, when=showReversals and reverseUp, shape="triangleUp", color=bullColor, position="below", size=6) plotShape(main, when=showReversals and reverseDown, shape="triangleDown", color=bearColor, position="above", size=6) overextension = mode == 1 and flowAvailable and math.abs(main) > 75 and math.abs(fairness) > 60 ? (main > 0 ? 100 : -100) : na plot(overextension, title="MVP extension warnings", style="histogram", color=bullColor, opacity=0.45) shiftUp = isClosed and rankReady and rankScore > 0 and nz(rankScore[1]) <= 0 and main > signal shiftDown = isClosed and rankReady and rankScore < 0 and nz(rankScore[1]) >= 0 and main < signal plotShape(main, when=showShifts and shiftUp, shape="diamond", color=mvpBullColor, position="center", size=6) plotShape(main, when=showShifts and shiftDown, shape="diamond", color=mvpBearColor, position="center", size=6) oscLowPivot = ta.pivotlow(main, strength, strength) oscHighPivot = ta.pivothigh(main, strength, strength) oscLastLow = barIndex > 0 ? oscLastLow[1] : na oscLastLowPrice = barIndex > 0 ? oscLastLowPrice[1] : na oscLastLowBar = barIndex > 0 ? oscLastLowBar[1] : 0 oscLastHigh = barIndex > 0 ? oscLastHigh[1] : na oscLastHighPrice = barIndex > 0 ? oscLastHighPrice[1] : na oscLastHighBar = barIndex > 0 ? oscLastHighBar[1] : 0 oscBullDivergence = 0 oscBearDivergence = 0 if isClosed and not na(oscLowPivot) { oscLowBar = barIndex - strength oscLowGap = oscLowBar - oscLastLowBar oscBullDivergence = not na(oscLastLow) and oscLowGap >= math.max(1, divergenceMinBars) and oscLowGap <= math.max(divergenceMinBars, divergenceMaxBars) and low[strength] < oscLastLowPrice and oscLowPivot > oscLastLow if showDivergences and oscBullDivergence { draw.label("oscBull" + barIndex, oscLowBar, main[strength], "D", color=mvpBullColor, fontSize=9, position="below") } oscLastLow = oscLowPivot oscLastLowPrice = low[strength] oscLastLowBar = oscLowBar } if isClosed and not na(oscHighPivot) { oscHighBar = barIndex - strength oscHighGap = oscHighBar - oscLastHighBar oscBearDivergence = not na(oscLastHigh) and oscHighGap >= math.max(1, divergenceMinBars) and oscHighGap <= math.max(divergenceMinBars, divergenceMaxBars) and high[strength] > oscLastHighPrice and oscHighPivot < oscLastHigh if showDivergences and oscBearDivergence { draw.label("oscBear" + barIndex, oscHighBar, main[strength], "D", color=mvpBullColor, fontSize=9, position="above") } oscLastHigh = oscHighPivot oscLastHighPrice = high[strength] oscLastHighBar = oscHighBar } alertcondition(oscBullDivergence, title="Oscillator bullish divergence") alertcondition(oscBearDivergence, title="Oscillator bearish divergence") moneyLowPivot = ta.pivotlow(flow, strength, strength) moneyHighPivot = ta.pivothigh(flow, strength, strength) moneyLastLow = barIndex > 0 ? moneyLastLow[1] : na moneyLastLowPrice = barIndex > 0 ? moneyLastLowPrice[1] : na moneyLastLowBar = barIndex > 0 ? moneyLastLowBar[1] : 0 moneyLastHigh = barIndex > 0 ? moneyLastHigh[1] : na moneyLastHighPrice = barIndex > 0 ? moneyLastHighPrice[1] : na moneyLastHighBar = barIndex > 0 ? moneyLastHighBar[1] : 0 moneyBullDivergence = 0 moneyBearDivergence = 0 if isClosed and not na(moneyLowPivot) { moneyLowBar = barIndex - strength moneyLowGap = moneyLowBar - moneyLastLowBar moneyBullDivergence = not na(moneyLastLow) and moneyLowGap >= math.max(1, divergenceMinBars) and moneyLowGap <= math.max(divergenceMinBars, divergenceMaxBars) and low[strength] < moneyLastLowPrice and moneyLowPivot > moneyLastLow if showDivergences and moneyBullDivergence { draw.label("moneyBull" + barIndex, moneyLowBar, main[strength], "MF", color=mvpBullColor, fontSize=9, position="below") } moneyLastLow = moneyLowPivot moneyLastLowPrice = low[strength] moneyLastLowBar = moneyLowBar } if isClosed and not na(moneyHighPivot) { moneyHighBar = barIndex - strength moneyHighGap = moneyHighBar - moneyLastHighBar moneyBearDivergence = not na(moneyLastHigh) and moneyHighGap >= math.max(1, divergenceMinBars) and moneyHighGap <= math.max(divergenceMinBars, divergenceMaxBars) and high[strength] > moneyLastHighPrice and moneyHighPivot < moneyLastHigh if showDivergences and moneyBearDivergence { draw.label("moneyBear" + barIndex, moneyHighBar, main[strength], "MF", color=mvpBullColor, fontSize=9, position="above") } moneyLastHigh = moneyHighPivot moneyLastHighPrice = high[strength] moneyLastHighBar = moneyHighBar } alertcondition(moneyBullDivergence, title="Money flow bullish divergence") alertcondition(moneyBearDivergence, title="Money flow bearish divergence") plotShape(main, when=showDivergences and (oscBullDivergence or oscBearDivergence), shape="circle", color=mvpBullColor, size=4, position="center") alertcondition(reverseUp, title="Oscillator left lower zone") alertcondition(reverseDown, title="Oscillator left upper zone") alertcondition(shiftUp, title="Bullish confluence shift") alertcondition(shiftDown, title="Bearish confluence shift")