Quantum Market Intelligence Pro

CEO_OF_GOLD · study · 248 行 · 点赞 137 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("Quantum Market Intelligence Pro", shorttitle="QM Intelligence", overlay=true, max_labels_count=300)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 1. INPUT SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
string G_TREND = "01. Trend Intelligence"
string G_VOL   = "02. Volatility Intelligence"
string G_SIGNAL = "03. Signal Engine"
string G_RISK = "04. Risk Management"
string G_VISUAL = "05. Visual Settings"
 
fastLen = input.int(21, "Fast EMA", minval=2, group=G_TREND)
slowLen = input.int(55, "Slow EMA", minval=5, group=G_TREND)
diLen = input.int(14, "DI Length", minval=2, group=G_TREND)
adxSmooth = input.int(14, "ADX Smoothing", minval=2, group=G_TREND)
adxThreshold = input.float(20, "Trend ADX Threshold", minval=5, group=G_TREND)
 
atrLen = input.int(14, "ATR Length", minval=2, group=G_VOL)
bbLen = input.int(20, "Compression Length", minval=5, group=G_VOL)
bbMult = input.float(2.0, "Band Multiplier", minval=0.5, group=G_VOL)
compressionFactor = input.float(0.75, "Compression Sensitivity", minval=0.1, step=0.05, group=G_VOL)
 
rsiLen = input.int(14, "RSI Length", minval=2, group=G_SIGNAL)
rsiBull = input.int(55, "Bullish RSI Level", minval=50, maxval=90, group=G_SIGNAL)
rsiBear = input.int(45, "Bearish RSI Level", minval=10, maxval=50, group=G_SIGNAL)
useVolume = input.bool(true, "Use Volume Confirmation", group=G_SIGNAL)
volLen = input.int(20, "Volume Average Length", minval=2, group=G_SIGNAL)
minScore = input.int(3, "Minimum Signal Score (1-5)", minval=1, maxval=5, group=G_SIGNAL)
 
slATR = input.float(1.5, "Stop Loss ATR Multiplier", minval=0.2, step=0.1, group=G_RISK)
tp1ATR = input.float(1.0, "Target 1 ATR", minval=0.2, step=0.1, group=G_RISK)
tp2ATR = input.float(2.0, "Target 2 ATR", minval=0.2, step=0.1, group=G_RISK)
tp3ATR = input.float(3.0, "Target 3 ATR", minval=0.2, step=0.1, group=G_RISK)
 
showEMAs = input.bool(true, "Show EMA Ribbon", group=G_VISUAL)
showSignals = input.bool(true, "Show BUY/SELL Signals", group=G_VISUAL)
showBackground = input.bool(true, "Show Market Regime Background", group=G_VISUAL)
showRisk = input.bool(true, "Show Active Trade Levels", group=G_VISUAL)
showDashboard = input.bool(true, "Show Intelligence Dashboard", group=G_VISUAL)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 2. CORE CALCULATIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
emaFast = ta.ema(close, fastLen)
emaSlow = ta.ema(close, slowLen)
 
[plusDI, minusDI, adx] = ta.dmi(diLen, adxSmooth)
 
rsi = ta.rsi(close, rsiLen)
atr = ta.atr(atrLen)
 
atrPercent = close != 0 ? atr / close * 100 : 0
atrAverage = ta.sma(atrPercent, 50)
 
basis = ta.sma(close, bbLen)
dev = ta.stdev(close, bbLen) * bbMult
upperBand = basis + dev
lowerBand = basis - dev
 
bbWidth = basis != 0 ? (upperBand - lowerBand) / basis * 100 : 0
bbWidthAverage = ta.sma(bbWidth, 50)
 
volAverage = ta.sma(volume, volLen)
volumeRatio = not na(volAverage) and volAverage > 0 ? volume / volAverage : 1.0
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 3. MARKET REGIME ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
compression = not na(bbWidthAverage) and bbWidth < bbWidthAverage * compressionFactor
highVolatility = not na(atrAverage) and atrPercent > atrAverage * 1.5
 
bullTrend = emaFast > emaSlow and adx >= adxThreshold and plusDI > minusDI
bearTrend = emaFast < emaSlow and adx >= adxThreshold and minusDI > plusDI
 
ranging = adx < adxThreshold and not compression
transition = not bullTrend and not bearTrend and not ranging and not compression
 
string regime = "TRANSITION"
color regimeColor = color.orange
 
if compression
    regime := "COMPRESSION"
    regimeColor := color.yellow
else if highVolatility
    regime := "HIGH VOLATILITY"
    regimeColor := color.fuchsia
else if bullTrend
    regime := "BULLISH TREND"
    regimeColor := color.lime
else if bearTrend
    regime := "BEARISH TREND"
    regimeColor := color.red
else if ranging
    regime := "RANGING"
    regimeColor := color.gray
 
bgColor = showBackground ? color.new(regimeColor, 92) : na
bgcolor(bgColor, title="Market Regime Background")
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 4. TREND STRENGTH & BREAKOUT SCORE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
trendStrength = math.min(100.0, math.max(0.0, adx * 2.0))
 
int breakoutScore = 0
breakoutScore += compression ? 2 : 0
breakoutScore += volumeRatio > 1.2 ? 1 : 0
breakoutScore += adx > adxThreshold ? 1 : 0
breakoutScore += (close > upperBand or close < lowerBand) ? 1 : 0
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 5. SIGNAL ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
bullMomentum = rsi > rsiBull and plusDI > minusDI
bearMomentum = rsi < rsiBear and minusDI > plusDI
 
volumeBull = not useVolume or volumeRatio > 1
volumeBear = not useVolume or volumeRatio > 1
 
int bullScore = 0
bullScore += emaFast > emaSlow ? 1 : 0
bullScore += bullMomentum ? 1 : 0
bullScore += adx > adxThreshold ? 1 : 0
bullScore += volumeBull ? 1 : 0
bullScore += close > emaFast ? 1 : 0
 
int bearScore = 0
bearScore += emaFast < emaSlow ? 1 : 0
bearScore += bearMomentum ? 1 : 0
bearScore += adx > adxThreshold ? 1 : 0
bearScore += volumeBear ? 1 : 0
bearScore += close < emaFast ? 1 : 0
 
bullTrigger = ta.crossover(emaFast, emaSlow)
bearTrigger = ta.crossunder(emaFast, emaSlow)
 
buySignal = barstate.isconfirmed and bullTrigger and bullScore >= minScore
sellSignal = barstate.isconfirmed and bearTrigger and bearScore >= minScore
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 6. TRADE MANAGEMENT
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
var int tradeSide = 0
var float entryPrice = na
var float stopPrice = na
var float target1 = na
var float target2 = na
var float target3 = na
 
if buySignal
    tradeSide := 1
    entryPrice := close
    stopPrice := close - atr * slATR
    target1 := close + atr * tp1ATR
    target2 := close + atr * tp2ATR
    target3 := close + atr * tp3ATR
 
if sellSignal
    tradeSide := -1
    entryPrice := close
    stopPrice := close + atr * slATR
    target1 := close - atr * tp1ATR
    target2 := close - atr * tp2ATR
    target3 := close - atr * tp3ATR
 
if tradeSide == 1 and not na(stopPrice)
    if low <= stopPrice or high >= target3
        tradeSide := 0
 
if tradeSide == -1 and not na(stopPrice)
    if high >= stopPrice or low <= target3
        tradeSide := 0
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 7. CHART VISUALS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
plot(showEMAs ? emaFast : na, "Fast EMA", color=color.aqua, linewidth=2)
plot(showEMAs ? emaSlow : na, "Slow EMA", color=color.orange, linewidth=2)
 
plotshape(showSignals and buySignal, title="BUY", style=shape.labelup, location=location.belowbar, color=color.lime, text="BUY", textcolor=color.black, size=size.small)
plotshape(showSignals and sellSignal, title="SELL", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.small)
 
activeTrade = showRisk and tradeSide != 0
 
plot(activeTrade ? entryPrice : na, "Entry", color=color.blue, linewidth=2, style=plot.style_linebr)
plot(activeTrade ? stopPrice : na, "Stop Loss", color=color.red, linewidth=2, style=plot.style_linebr)
plot(activeTrade ? target1 : na, "Target 1", color=color.lime, linewidth=1, style=plot.style_linebr)
plot(activeTrade ? target2 : na, "Target 2", color=color.green, linewidth=1, style=plot.style_linebr)
plot(activeTrade ? target3 : na, "Target 3", color=color.teal, linewidth=2, style=plot.style_linebr)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 8. PROFESSIONAL DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
var table dashboard = table.new(position.top_right, 2, 9, border_width=1)
 
if barstate.islast and showDashboard
    table.cell(dashboard, 0, 0, "QUANTUM INTELLIGENCE", bgcolor=color.rgb(20, 30, 48), text_color=color.white)
    table.cell(dashboard, 1, 0, "PRO", bgcolor=color.rgb(20, 30, 48), text_color=color.aqua)
 
    table.cell(dashboard, 0, 1, "Market Regime", text_color=color.white, bgcolor=color.rgb(35, 40, 50))
    table.cell(dashboard, 1, 1, regime, text_color=regimeColor, bgcolor=color.rgb(35, 40, 50))
 
    table.cell(dashboard, 0, 2, "Trend Strength", text_color=color.white, bgcolor=color.rgb(35, 40, 50))
    table.cell(dashboard, 1, 2, str.tostring(trendStrength, "#") + "/100", text_color=color.aqua, bgcolor=color.rgb(35, 40, 50))
 
    table.cell(dashboard, 0, 3, "ADX", text_color=color.white, bgcolor=color.rgb(35, 40, 50))
    table.cell(dashboard, 1, 3, str.tostring(adx, "#.0"), text_color=color.white, bgcolor=color.rgb(35, 40, 50))
 
    table.cell(dashboard, 0, 4, "RSI", text_color=color.white, bgcolor=color.rgb(35, 40, 50))
    table.cell(dashboard, 1, 4, str.tostring(rsi, "#.0"), text_color=color.white, bgcolor=color.rgb(35, 40, 50))
 
    table.cell(dashboard, 0, 5, "Volatility", text_color=color.white, bgcolor=color.rgb(35, 40, 50))
    table.cell(dashboard, 1, 5, highVolatility ? "HIGH" : "NORMAL", text_color=highVolatility ? color.fuchsia : color.lime, bgcolor=color.rgb(35, 40, 50))
 
    table.cell(dashboard, 0, 6, "Breakout Score", text_color=color.white, bgcolor=color.rgb(35, 40, 50))
    table.cell(dashboard, 1, 6, str.tostring(breakoutScore) + "/5", text_color=color.yellow, bgcolor=color.rgb(35, 40, 50))
 
    table.cell(dashboard, 0, 7, "BUY / SELL Score", text_color=color.white, bgcolor=color.rgb(35, 40, 50))
    table.cell(dashboard, 1, 7, str.tostring(bullScore) + " / " + str.tostring(bearScore), text_color=color.aqua, bgcolor=color.rgb(35, 40, 50))
 
    string tradeStatus = tradeSide == 1 ? "LONG ACTIVE" : tradeSide == -1 ? "SHORT ACTIVE" : "NO ACTIVE TRADE"
    color tradeColor = tradeSide == 1 ? color.lime : tradeSide == -1 ? color.red : color.gray
 
    table.cell(dashboard, 0, 8, "Trade Status", text_color=color.white, bgcolor=color.rgb(35, 40, 50))
    table.cell(dashboard, 1, 8, tradeStatus, text_color=tradeColor, bgcolor=color.rgb(35, 40, 50))
 
if barstate.islast and not showDashboard
    table.clear(dashboard, 0, 0, 1, 8)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 9. ALERT CONDITIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
alertcondition(buySignal, "Quantum BUY", "Quantum Market Intelligence: BUY signal")
alertcondition(sellSignal, "Quantum SELL", "Quantum Market Intelligence: SELL signal")
alertcondition(compression and not compression[1], "Compression Detected", "Market compression detected")
alertcondition(highVolatility and not highVolatility[1], "High Volatility", "High volatility detected")
alertcondition(bullTrend and not bullTrend[1], "Bullish Regime", "Bullish market regime detected")
alertcondition(bearTrend and not bearTrend[1], "Bearish Regime", "Bearish market regime detected")

← 返回列表