script("Market Oracle Suite - independent", kind="indicator") input signalMode = 0 input manualLength = 21 input autoTune = 1 input tuningMin = 8 input tuningMax = 32 input tuningStep = 4 input tuningWindow = 120 input tuningFeeBps = 5 input atrLength = 14 input trendThreshold = 18 input bandMultiplier = 1.8 input useVolume = 1 input sessionSeconds = 86400 input sessionOffset = 0 input useMTF = 0 input higherFrame = 3600 input higherLength = 3 input showSignals = 1 input showBands = 1 input showRanges = 1 input showCloud = 1 input showTargets = 1 input showPatterns = 1 input showDashboard = 1 input candleHighlight = 1 atr = ta.atr(atrLength) adx = ta.adx(14) manualReactor = ta.ema(close, manualLength) tunedReactor = ta.tunedEma(close, tuningMin, tuningMax, tuningStep, tuningWindow, tuningFeeBps) chosenLength = ta.tuneLength(close, tuningMin, tuningMax, tuningStep, tuningWindow, tuningFeeBps) reactor = autoTune == 1 ? tunedReactor : manualReactor optimalLength = autoTune == 1 ? chosenLength : manualLength kernel = ta.kernelRQ(close, 12, 8, 32) residual = close - kernel noise = ta.stdev(residual, 32) width = math.max(atr * bandMultiplier, nz(noise, 0) * 2) upperBand = kernel + width lowerBand = kernel - width consolidation = math.clamp(10 - adx / 4, 0, 10) ready = not na(atr) and not na(adx) and atr > 0 trend = not ready or adx < trendThreshold ? 0 : close > reactor and reactor > reactor[1] ? 1 : close < reactor and reactor < reactor[1] ? -1 : 0 shade = trend == 1 ? "#62E8A4" : trend == -1 ? "#F35A64" : "#87909F" cloudUpper = showCloud == 1 ? reactor + atr * 0.15 : na cloudLower = showCloud == 1 ? reactor - atr * 0.15 : na bandTop = showBands == 1 ? upperBand : na bandBottom = showBands == 1 ? lowerBand : na priceSource = (high + low + close) / 3 sessionBasis = ta.sessionVwap(priceSource, sessionSeconds, sessionOffset) sessionDeviation = ta.sessionVwapDev(priceSource, sessionSeconds, sessionOffset) volumeReady = useVolume == 1 and not na(volume) and volume > 0 and not na(sessionBasis) rangeBasis = showRanges == 1 and volumeReady ? sessionBasis : na rangeTop = showRanges == 1 and volumeReady ? sessionBasis + sessionDeviation * 2 : na rangeBottom = showRanges == 1 and volumeReady ? sessionBasis - sessionDeviation * 2 : na htfBasis = na htfWidth = na if useMTF == 1 { htfBasis = ta.htfEma(close, higherFrame, higherLength) htfWidth = ta.htfAtr(higherFrame, higherLength) } htfTop = showBands == 1 and useMTF == 1 ? htfBasis + htfWidth * bandMultiplier : na htfBottom = showBands == 1 and useMTF == 1 ? htfBasis - htfWidth * bandMultiplier : na rsi = ta.rsi(close, 14) priceScore = ready ? math.clamp((close - reactor) / atr, -2, 2) : 0 kernelScore = kernel > kernel[1] ? 1 : kernel < kernel[1] ? -1 : 0 momentumScore = not na(rsi) ? math.clamp((rsi - 50) / 25, -1, 1) : 0 volumeScore = volumeReady ? (close > sessionBasis ? 1 : close < sessionBasis ? -1 : 0) : 0 scoreWeight = volumeReady ? 5 : 4 primeScore = math.clamp(5 + (priceScore + kernelScore + momentumScore + volumeScore) * 5 / scoreWeight, 0, 10) forecast = not ready ? "Warming up" : consolidation >= 6 ? "Ranging" : primeScore >= 6 ? "Bullish bias" : primeScore <= 4 ? "Bearish bias" : "Neutral" bullTrend = ready and trend == 1 and nz(trend[1], 0) != 1 bearTrend = ready and trend == -1 and nz(trend[1], 0) != -1 bullReversal = ready and low < lowerBand and close > lowerBand and close > open bearReversal = ready and high > upperBand and close < upperBand and close < open bullEngulf = close > open and close[1] < open[1] and close >= open[1] and open <= close[1] bearEngulf = close < open and close[1] > open[1] and close <= open[1] and open >= close[1] htfBull = useMTF == 0 or (not na(htfBasis) and close > htfBasis) htfBear = useMTF == 0 or (not na(htfBasis) and close < htfBasis) longCandidate = signalMode == 0 ? trend == 1 : signalMode == 1 ? bullReversal : bullTrend and bullEngulf shortCandidate = signalMode == 0 ? trend == -1 : signalMode == 1 ? bearReversal : bearTrend and bearEngulf longQualified = longCandidate and htfBull shortQualified = shortCandidate and htfBear buy = isClosed and longQualified and not nz(longQualified[1], 0) sell = isClosed and shortQualified and not nz(shortQualified[1], 0) and not buy entry = buy or sell ? close : entry[1] entryRisk = buy or sell ? atr * 1.5 : entryRisk[1] entryDirection = buy ? 1 : sell ? -1 : nz(entryDirection[1], 0) entryBar = buy or sell ? barIndex : nz(entryBar[1], -1) stopPrice = entry - entryDirection * entryRisk targetOne = entry + entryDirection * entryRisk targetTwo = entry + entryDirection * entryRisk * 2 targetThree = entry + entryDirection * entryRisk * 3 plot(reactor, title="Adaptive Reactor", colorSeries=shade, width=3) plot(kernel, title="Kernel Assistant", color="#8D91FF", width=1) plot(bandTop, title="Reversal band high", color="#E67791", width=1) plot(bandBottom, title="Reversal band low", color="#62DCC7", width=1) fill(bandTop, kernel, color="#C65C7C", opacity=0.035) fill(kernel, bandBottom, color="#43BDA7", opacity=0.035) fill(cloudUpper, cloudLower, colorSeries=shade, opacity=0.22) plot(rangeBasis, title="Session VWAP", color="#ECC06B", width=1) plot(rangeTop, title="Session range high", color="#ECC06B", width=1) plot(rangeBottom, title="Session range low", color="#ECC06B", width=1) plot(htfTop, title="Closed HTF high", color="#B09AE6", style="step", width=1) plot(htfBottom, title="Closed HTF low", color="#B09AE6", style="step", width=1) plotText(low, when=buy and showSignals == 1, text="BUY", color="#11281D", background="#62E8A4", style="label", position="below", fontSize=10) plotText(high, when=sell and showSignals == 1, text="SELL", color="#FFFFFF", background="#E34F63", style="label", position="above", fontSize=10) plotShape(low, when=bullEngulf and showPatterns == 1, shape="diamond", color="#62E8A4", position="below", size=4) plotShape(high, when=bearEngulf and showPatterns == 1, shape="diamond", color="#E34F63", position="above", size=4) barcolor(candleHighlight == 1, color=shade) alertcondition(buy, title="Oracle BUY", message="Independent Oracle: closed-bar BUY") alertcondition(sell, title="Oracle SELL", message="Independent Oracle: closed-bar SELL") if showTargets == 1 and entryBar >= 0 and not na(entryRisk) { draw.line("entry", entryBar, entry, barIndex + 8, entry, color="#A3ADBF", style="dotted", text="Entry {price}") draw.line("stop", entryBar, stopPrice, barIndex + 8, stopPrice, color="#E34F63", style="dashed", text="SL {price}") draw.line("tp1", entryBar, targetOne, barIndex + 8, targetOne, color="#62E8A4", style="dashed", text="TP1 {price}") draw.line("tp2", entryBar, targetTwo, barIndex + 8, targetTwo, color="#62E8A4", style="dashed", text="TP2 {price}") draw.line("tp3", entryBar, targetThree, barIndex + 8, targetThree, color="#62E8A4", style="dashed", text="TP3 {price}") } if showDashboard == 1 { table.cell("oracle", 0, 0, "ORACLE SUITE", color="#FFFFFF", background="#29334A") table.cell("oracle", 1, 0, "Independent", color="#AEBBDA", background="#29334A") table.cell("oracle", 0, 1, "Tuning") table.cell("oracle", 1, 1, "" + optimalLength, color="#ECC06B") table.cell("oracle", 0, 2, "Prime score") table.cell("oracle", 1, 2, "" + math.round(primeScore) + "/10", color=shade, progress=primeScore / 10) table.cell("oracle", 0, 3, "Consolidation") table.cell("oracle", 1, 3, ready ? "" + math.round(consolidation) + "/10" : "Warming", color="#B09AE6", progress=ready ? consolidation / 10 : 0) table.cell("oracle", 0, 4, "Outlook") table.cell("oracle", 1, 4, forecast, color=shade) table.cell("oracle", 0, 5, "Volume / VWAP") table.cell("oracle", 1, 5, volumeReady ? "Active" : "Inactive", color=volumeReady ? "#62E8A4" : "#87909F") table.cell("oracle", 0, 6, "HTF filter") table.cell("oracle", 1, 6, useMTF == 0 ? "Off" : na(htfBasis) ? "Warming" : "Closed only", color="#AEBBDA") }