Ultimate Sell Indicator
Built by Grok
Working?
//@version=6
indicator("Advanced ML Ultimate Sell Indicator", shorttitle="AMLUSI", overlay=false, precision=2)
// --- Advanced Inputs ---
rsiLength = input.int(14, "RSI Length", minval=1, group="RSI")
rsiOverbought = input.float(70, "RSI Overbought", minval=50, maxval=100, group="RSI")
macdFast = input.int(12, "MACD Fast", minval=1, group="MACD")
macdSlow = input.int(26, "MACD Slow", minval=1, group="MACD")
macdSignal = input.int(9, "MACD Signal", minval=1, group="MACD")
stochK = input.int(14, "Stoch K", minval=1, group="Stochastic")
stochD = input.int(3, "Stoch D", minval=1, group="Stochastic")
stochSmooth = input.int(3, "Stoch Smooth", minval=1, group="Stochastic")
stochOverbought = input.float(80, "Stoch Overbought", minval=50, maxval=100, group="Stochastic")
bbLength = input.int(20, "BB Length", minval=1, group="Bollinger Bands")
bbMult = input.float(2.0, "BB Multiplier", minval=0.1, step=0.1, group="Bollinger Bands")
momLength = input.int(10, "Momentum Length", minval=1, group="Momentum")
adxLength = input.int(14, "ADX Length", minval=1, group="ADX")
cciLength = input.int(20, "CCI Length", minval=1, group="CCI")
cciOverbought = input.float(100, "CCI Overbought", minval=50, group="CCI")
atrLength = input.int(14, "ATR Length", minval=1, group="ATR")
willrLength = input.int(14, "Williams %R Length", minval=1, group="Williams %R")
willrOverbought = input.float(-20, "Williams %R Overbought", minval=-50, maxval=0, group="Williams %R")
lookback = input.int(50, "Lookback for Weights & Stats", minval=10, group="ML Settings")
sellThreshold = input.float(75, "Sell Threshold", minval=0, maxval=100, group="ML Settings")
smoothLength = input.int(5, "Smoothing Length", minval=1, group="ML Settings")
volatilityAdjust = input.bool(true, "Volatility Adjustment", group="Advanced")
trendFilter = input.bool(true, "Trend Filter", group="Advanced")
// --- Indicator Calculations ---
// 1. RSI
rsi = ta.rsi(close, rsiLength)
rsiSell = rsi > rsiOverbought ? (rsi - rsiOverbought) / (100 - rsiOverbought) * 100 : 0
// 2. MACD
[macdLine, signalLine, hist] = ta.macd(close, macdFast, macdSlow, macdSignal)
macdSell = hist < 0 ? math.abs(hist) / math.max(ta.highest(math.abs(hist), lookback), 0.0001) * 100 : 0
// 3. Stochastic
[k, d] = ta.stoch(high, low, close, stochK, stochD, stochSmooth)
stochSell = k > stochOverbought ? (k - stochOverbought) / (100 - stochOverbought) * 100 : 0
// 4. Bollinger Bands
[bbUpper, bbMiddle, bbLower] = ta.bb(close, bbLength, bbMult)
bbSell = close > bbUpper ? (close - bbUpper) / (bbUpper - bbMiddle + 0.0001) * 100 : 0
bbSell := math.min(bbSell, 100)
// 5. Momentum
mom = ta.mom(close, momLength)
momNorm = 100 * (mom - ta.lowest(mom, lookback)) / math.max(ta.highest(mom, lookback) - ta.lowest(mom, lookback), 0.0001)
momSell = momNorm < ta.highest(momNorm, momLength) ? (ta.highest(momNorm, momLength) - momNorm) / ta.highest(momNorm, momLength) * 100 : 0
// 6. ADX
adxValue = ta.adx(high, low, close, adxLength)
adxSell = adxValue < ta.highest(adxValue, lookback) ? (ta.highest(adxValue, lookback) - adxValue) / ta.highest(adxValue, lookback) * 100 : 0
// 7. CCI
cci = ta.cci(high, low, close, cciLength)
cciSell = cci > cciOverbought ? (cci - cciOverbought) / (cciOverbought * 2) * 100 : 0
cciSell := math.min(cciSell, 100)
// 8. ATR (Volatility Spike as Sell Signal)
atr = ta.atr(atrLength)
atrNorm = atr / ta.sma(close, atrLength)
atrSell = atrNorm > ta.highest(atrNorm, lookback) ? (atrNorm - ta.highest(atrNorm, lookback)) / ta.highest(atrNorm, lookback) * 100 : 0
atrSell := math.max(atrSell, 0)
// 9. Williams %R
willr = ta.willr(high, low, close, willrLength)
willrSell = willr > willrOverbought ? (willr - willrOverbought) / (0 - willrOverbought) * 100 : 0
// --- Advanced Features ---
// Volatility Adjustment
volatilityFactor = volatilityAdjust ? ta.stdev(close, lookback) / ta.sma(close, lookback) : 1.0
volatilityFactor := math.max(volatilityFactor, 0.1) // Prevent extreme scaling
// Trend Filter (EMA-based)
trendEma = ta.ema(close, lookback)
trendDirection = close > trendEma ? 1 : -1
trendAdjustedSell = trendFilter ? (trendDirection < 0 ? 1.5 : 1.0) : 1.0
// --- ML Simulation: Dynamic Weights with Statistical Enhancement ---
weightPeriod = lookback
rsiWeight = ta.sma(rsiSell > sellThreshold ? 1 : 0, weightPeriod) * (1 + ta.correlation(rsi, close, lookback))
macdWeight = ta.sma(macdSell > sellThreshold ? 1 : 0, weightPeriod) * (1 + ta.correlation(hist, close, lookback))
stochWeight = ta.sma(stochSell > sellThreshold ? 1 : 0, weightPeriod) * (1 + ta.correlation(k, close, lookback))
bbWeight = ta.sma(bbSell > sellThreshold ? 1 : 0, weightPeriod) * (1 + ta.correlation(bbUpper, close, lookback))
momWeight = ta.sma(momSell > sellThreshold ? 1 : 0, weightPeriod) * (1 + ta.correlation(mom, close, lookback))
adxWeight = ta.sma(adxSell > sellThreshold ? 1 : 0, weightPeriod) * (1 + ta.correlation(adxValue, close, lookback))
cciWeight = ta.sma(cciSell > sellThreshold ? 1 : 0, weightPeriod) * (1 + ta.correlation(cci, close, lookback))
atrWeight = ta.sma(atrSell > sellThreshold ? 1 : 0, weightPeriod) * (1 + ta.correlation(atr, close, lookback))
willrWeight = ta.sma(willrSell > sellThreshold ? 1 : 0, weightPeriod) * (1 + ta.correlation(willr, close, lookback))
// Normalize weights
totalWeight = rsiWeight + macdWeight + stochWeight + bbWeight + momWeight + adxWeight + cciWeight + atrWeight + willrWeight
totalWeight := totalWeight == 0 ? 1 : totalWeight
rsiWeight := rsiWeight / totalWeight
macdWeight := macdWeight / totalWeight
stochWeight := stochWeight / totalWeight
bbWeight := bbWeight / totalWeight
momWeight := momWeight / totalWeight
adxWeight := adxWeight / totalWeight
cciWeight := cciWeight / totalWeight
atrWeight := atrWeight / totalWeight
willrWeight := willrWeight / totalWeight
// --- Combined Sell Score with Adjustments ---
sellScoreRaw = (rsiSell * rsiWeight) + (macdSell * macdWeight) + (stochSell * stochWeight) +
(bbSell * bbWeight) + (momSell * momWeight) + (adxSell * adxWeight) +
(cciSell * cciWeight) + (atrSell * atrWeight) + (willrSell * willrWeight)
sellScoreAdjusted = sellScoreRaw * volatilityFactor * trendAdjustedSell
sellScore = ta.sma(sellScoreAdjusted, smoothLength)
// --- Dynamic Threshold ---
dynamicThreshold = ta.highest(sellScore, lookback) * 0.85
finalThreshold = math.max(sellThreshold, dynamicThreshold)
// --- Sell Signal ---
sellSignal = sellScore > finalThreshold
// --- Advanced Statistical Metrics ---
sharpeRatio = ta.sma(sellScore - ta.sma(sellScore, lookback), lookback) / ta.stdev(sellScore, lookback)
signalConfidence = ta.sma(sellSignal ? 1 : 0, lookback) * 100
// --- Plotting ---
plot(sellScore, "Sell Score", color=color.red, linewidth=2, style=plot.style_area)
plot(finalThreshold, "Dynamic Sell Threshold", color=color.orange, style=plot.style_dashed)
plot(sellThreshold, "Static Sell Threshold", color=color.yellow, style=plot.style_dashed)
hline(50, "Midline", color=color.gray, linestyle=hline.style_dotted)
plotshape(sellSignal, "Sell Signal", style=shape.triangledown, color=color.red, size=size.tiny)
plot(signalConfidence, "Signal Confidence (%)", color=color.blue, linewidth=1, display=display.bottom_right)
// --- Alerts ---
alertcondition(sellSignal, "Advanced Sell Signal", "Strong Selling Opportunity Detected (Confidence: " + str.tostring(signalConfidence, "#.##") + "%)")
alertcondition(sellScore > 90, "Extreme Sell Signal", "Extreme Selling Opportunity Detected!")
// --- Debugging Outputs (Optional) ---
if barstate.islast
label.new(bar_index, sellScore, "Score: " + str.tostring(sellScore, "#.##") + "\nConf: " + str.tostring(signalConfidence, "#.##") + "%", color=color.black, textcolor=color.white, style=label.style_label_down)
No comments: