1Bitcoin / USDTMEXC:BTCUSDTalirezaneisi8// @version=6 indicator("Traffic Light AI v3.9 - DMI/ADX + RSI + MFI + ROC (MTF, Traffic UI)", overlay=true) //===== Inputs ===== srcTF = input.timeframe("", "Signal Timeframe (blank = current)") adxLen = input.int(14, "DMI Length", minval=2) adxSmooth = input.int(14, "ADX Smoothing", minval=1) rsiLen = input.int(14, "RSI Length", minval=2) mfiLen = input.int(14, "MFI Length", minval=2) // ✅ تعریف صحیح rocLen = input.int(9, "ROC Length", minval=1) adxStrong = input.float(25.0, "ADX Strong (Trending)", minval=5, step=0.5) adxWeak = input.float(20.0, "ADX Weak (Range Filter)", minval=5, step=0.5) rsiUpper = input.float(55.0, "RSI Upper (Bull)", minval=50, maxval=80, step=0.1) rsiLower = input.float(45.0, "RSI Lower (Bear)", minval=20, maxval=50, step=0.1) mfiUpper = input.float(55.0, "MFI Upper (Bull)", minval=50, maxval=80, step=0.1) mfiLower = input.float(45.0, "MFI Lower (Bear)", minval=20, maxval=50, step=0.1) tintBars = input.bool(true, "Light Tint Candles (soft)") tintAlpha = input.int(80, "Tint Transparency (0=solid, 90=light)", minval=0, maxval=90) //===== Timeframe Resolve ===== _tf = srcTF == "" ? timeframe.period : srcTF //===== MTF-Safe Data (no repaint) ===== // DMI/ADX → returns = request.security( syminfo.tickerid, _tf, ta.dmi(adxLen, adxSmooth), lookahead=barmerge.lookahead_off) // RSI (uses close) rsiTF = request.security(syminfo.tickerid, _tf, ta.rsi(close, rsiLen), lookahead=barmerge.lookahead_off) // MFI در نسخه 6 نیاز به (series, length) دارد mfiTF = request.security(syminfo.tickerid, _tf, ta.mfi(hlc3, mfiLen), lookahead=barmerge.lookahead_off) // ✅ صحیح // ROC (uses close) rocTF = request.security(syminfo.tickerid, _tf, ta.roc(close, rocLen), lookahead=barmerge.lookahead_off) //===== بقیه کد بدون تغییر ===== // Trend via DI & ADX trendBull = (diplusTF > diminusTF) and (adxTF >= adxStrong) trendBear = (diminusTF > diplusTF) and (adxTF >= adxStrong) trendRange = adxTF rsiUpper momentumBear = rsiTF < rsiLower // Money Flow (MFI) volumeBull = mfiTF > mfiUpper volumeBear = mfiTF < mfiLower // Acceleration (ROC) accelBull = rocTF > 0 accelBear = rocTF < 0 // 3-of-4 scoring bullCount = (trendBull ? 1 : 0) + (momentumBull ? 1 : 0) + (volumeBull ? 1 : 0) + (accelBull ? 1 : 0) bearCount = (trendBear ? 1 : 0) + (momentumBear ? 1 : 0) + (volumeBear ? 1 : 0) + (accelBear ? 1 : 0) bull = bullCount >= 3 bear = bearCount >= 3 neutral = (not bull and not bear) or trendRange //===== Candle Tint ===== var color candleColor = na candleColor := tintBars ? (bull ? color.new(color.lime, tintAlpha) : bear ? color.new(color.red, tintAlpha) : color.new(color.gray, math.min(90, tintAlpha + 5))) : na barcolor(candleColor) //===== Traffic Light UI (table, top-right) ===== var table tl = table.new(position.top_right, 1, 3, border_width=2, frame_color=color.black) if barstate.isfirst table.cell(tl, 0, 0, "🟥", text_size=size.huge, text_color=color.red, bgcolor=color.black) table.cell(tl, 0, 1, "⚪️", text_size=size.huge, text_color=color.gray, bgcolor=color.black) table.cell(tl, 0, 2, "🟩", text_size=size.huge, text_color=color.lime, bgcolor=color.black) if barstate.islast table.cell_set_bgcolor(tl, 0, 0, bear ? color.red : color.new(color.red, 85)) table.cell_set_bgcolor(tl, 0, 1, neutral ? color.gray : color.new(color.gray, 85)) table.cell_set_bgcolor(tl, 0, 2, bull ? color.lime : color.new(color.lime, 85)) //===== Alerts ===== state = bull ? 1 : bear ? -1 : 0 prevState = nz(state, 0) bullFlip = state == 1 and prevState != 1 bearFlip = state == -1 and prevState != -1 neutralFlip = state == 0 and prevState != 0 alertcondition(bullFlip, "Green Light", "Traffic Light: GREEN (Bull context)") alertcondition(bearFlip, "Red Light", "Traffic Light: RED (Bear context)") alertcondition(neutralFlip, "Neutral Light", "Traffic Light: NEUTRAL (Range/No-Trade)") //===== Markers ===== plotchar(bull, char="▲", title="Bullish Context", color=color.lime, location=location.bottom) plotchar(bear, char="▼", title="Bearish Context", color=color.red, location=location.top) plotchar(neutral, char="•", title="Neutral Context", color=color.gray, location=location.bottom)