Untitled
//@version=6 indicator('Kaan with Advanced Features - Optimized', overlay = true) // Function: Modular Moving Average (MA) Calculation f_mat(source, length, type) => switch type 'SMA' => ta.sma(source, length) 'EMA' => ta.ema(source, length) 'RMA' => ta.rma(source, length) 'WMA' => ta.wma(source, length) 'VWMA' => ta.vwma(source, length) 'HMA' => ta.hma(source, length) 'TMA' => ta.sma(ta.sma(source, length), length) => na // Default fallback value // Function: Gradient Coloring f_c_gradientAdvDecPro(_source, _center, _steps, _c_bearWeak, _c_bearStrong, _c_bullWeak, _c_bullStrong) => var float _qtyAdvDec = 0. var float _maxSteps = math.max(1, _steps) bool _xUp = ta.crossover(_source, _center) bool _xDn = ta.crossunder(_source, _center) float _chg = ta.change(_source) bool _up = _chg > 0 bool _dn = _chg < 0 bool _srcBull = _source > _center bool _srcBear = _source < _center _qtyAdvDec := _srcBull ? (_xUp ? 1 : (_up ? math.min(_maxSteps, _qtyAdvDec + 1) : (_dn ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec))) : _srcBear ? (_xDn ? 1 : (_dn ? math.min(_maxSteps, _qtyAdvDec + 1) : (_up ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec))) : _qtyAdvDec color _return = na if _srcBull _return := color.from_gradient(_qtyAdvDec, 1, _maxSteps, _c_bullWeak, _c_bullStrong) else if _srcBear _return := color.from_gradient(_qtyAdvDec, 1, _maxSteps, _c_bearWeak, _c_bearStrong) _return // Inputs: Colors bull = input.color(color.rgb(0, 255, 0), title = 'Bull Color') bear = input.color(color.rgb(255, 0, 0), title = 'Bear Color') neutral = input.color(color.rgb(255, 255, 0, 0), title = 'Neutral Color') UseGradient = input(true, title = 'Use Gradient Colors') stepn = input(5, title = 'Max Gradient Steps') // Inputs: Moving Averages LengthMA = input.int(55, minval = 1, title = 'MA Line Length', inline = 'MA Info') MAType = input.string(defval = 'EMA', title = 'MA Line Type', options = ['EMA', 'SMA', 'RMA', 'WMA', 'VWMA', 'HMA', 'TMA'], inline = 'MA Info') MASource = input(hl2, title = 'MA Source') useMAFilter = input(true, title = 'Use MA Filter') // MA filtreleme kontrolü MATypeFilter = input.string(defval = 'EMA', title = 'MA Filter Type', options = ['EMA', 'SMA', 'RMA', 'WMA', 'VWMA', 'HMA', 'TMA'], inline = 'MA Filter') LengthMAFilter = input.int(50, title = 'MA Filter Length') // MA filtre uzunluğu // Pre-computed Metrics ma = f_mat(close, LengthMA, MAType) maFilter = f_mat(close, LengthMAFilter, MATypeFilter) // MA filtreleme için hesaplama col = f_c_gradientAdvDecPro(ma, ta.ema(ma, 3), stepn, neutral, bear, neutral, bull) // Visuals: Plotting BodyColor = col WickColor = color.rgb(80, 80, 80, 100) // Light gray with transparency barcolor(UseGradient ? col : na) // Barların rengini sadece iç gövdeye uygula plotcandle(open, close, high, low, color = na, wickcolor = WickColor, bordercolor = na) // Gövdeye renk vermiyoruz, sadece fitil rengi koyuyoruz // Inputs: MACD Filter useMACD = input(true, title = 'Use MACD Filter') MACDLong = input.int(12, title = 'MACD Fast Length') MACDShort = input.int(26, title = 'MACD Slow Length') MACDSignal = input.int(9, title = 'MACD Signal Length') // Inputs: ADX and Filters useADX = input(true, title = "Use ADX Filtering") ADXLength = input.int(14, title = "ADX Length", inline = "ADX") ADXThreshold = input.int(25, title = "ADX Threshold", inline = "ADX") DIplusMin = input.float(20, title = "DI+ Minimum", inline = "ADX") DIminusMax = input.float(20, title = "DI- Maximum", inline = "ADX") // Inputs: Other Indicators useATR = input(true, title = "Use ATR Filtering") ATRLength = input.int(14, title = "ATR Length") ATRMultiplier = input.float(1.5, title = "ATR Multiplier") useRSI = input(true, title = "Use RSI Confirmation") RSILength = input.int(14, title = "RSI Length") RSIOverbought = input.int(70, title = "RSI Overbought Level") RSIOversold = input.int(30, title = "RSI Oversold Level") useBB = input(true, title = "Use Bollinger Bands Confirmation") BBLength = input.int(20, title = "Bollinger Band Length") BBMultiplier = input.float(2.0, title = "Bollinger Band Multiplier") // Pre-computed Metrics ATRValue = ta.atr(ATRLength) RSI = ta.rsi(close, RSILength) basis = ta.sma(close, BBLength) dev = BBMultiplier * ta.stdev(close, BBLength) upperBand = basis + dev lowerBand = basis - dev // Correct usage of ta.dmi with two arguments (length, adxSmoothing) [plusDI, minusDI, ADXValue] = ta.dmi(ADXLength, 14) // MACD Calculation [macdLine, signalLine, _] = ta.macd(close, MACDLong, MACDShort, MACDSignal) // Filters smaATR = ta.sma(ATRValue, ATRLength) volatilityFilter = not useATR or (ATRValue < ATRMultiplier * smaATR) RSIConfirmBuy = not useRSI or RSI < RSIOversold RSIConfirmSell = not useRSI or RSI > RSIOverbought BBBuy = not useBB or close < lowerBand BBSell = not useBB or close > upperBand ADXFilterBuy = not useADX or (ADXValue > ADXThreshold and plusDI > DIplusMin and minusDI < DIminusMax) ADXFilterSell = not useADX or (ADXValue > ADXThreshold and plusDI < DIplusMin and minusDI > DIminusMax) MACDFilterBuy = not useMACD or macdLine > signalLine MACDFilterSell = not useMACD or macdLine < signalLine // MA Filter Logic MAFilterBuy = not useMAFilter or close > maFilter MAFilterSell = not useMAFilter or close < maFilter // Buy/Sell Conditions var bool buySignal = false var bool sellSignal = false var bool buyTriggered = false var bool sellTriggered = false // Buy/Sell Logic with Preventing Repeating Signals if (col == bull and volatilityFilter and RSIConfirmBuy and BBBuy and ADXFilterBuy and MACDFilterBuy and MAFilterBuy and not buyTriggered) buySignal := true buyTriggered := true // Mark buy as triggered sellTriggered := false // Reset sellTriggered else if (col == bear and volatilityFilter and RSIConfirmSell and BBSell and ADXFilterSell and MACDFilterSell and MAFilterSell and not sellTriggered) sellSignal := true sellTriggered := true // Mark sell as triggered buyTriggered := false // Reset buyTriggered // Neutral Check: If neutral, keep current signal active (do not reset) if (col == neutral) // Neutral condition does not affect ongoing signals buySignal := buySignal sellSignal := sellSignal // Preventing repeat signals if (buySignal and col != bull) buySignal := false // Reset buy signal if condition no longer holds if (sellSignal and col != bear) sellSignal := false // Reset sell signal if condition no longer holds // Visuals: Plotting Buy/Sell Signals (Only plot the signal once, until opposite signal is triggered) plotshape(buySignal, title = "Buy Signal", location = location.belowbar, color = bull, style = shape.labelup, text = "BUY", textcolor = color.white, size = size.normal) plotshape(sellSignal, title = "Sell Signal", location = location.abovebar, color = bear, style = shape.labeldown, text = "SELL", textcolor = color.white, size = size.normal) // Alerts alertcondition(buySignal, title = 'Buy Signal', message = 'Buy Signal: HAMA is Bullish and Confirmed by Indicators') alertcondition(sellSignal, title = 'Sell Signal', message = 'Sell Signal: HAMA is Bearish and Confirmed by Indicators')
Leave a Comment