در اینجا کد نهایی برای ترکیب اندیکاتورهای MACD، RSI، میانگین متحرک، حجم و ADX در تریدینگ ویو ارائه شده است. این کد سیگنالهای خرید و فروش را بر اساس ترکیب این اندیکاتورها تولید میکند و شامل فیلترهای حجم و ADX برای تأیید سیگنالها است.
//@version=5
indicator("MACD + RSI + MA with Filters", overlay=true, description="Combines MACD, RSI, Moving Average, Volume, and ADX for buy/sell signals.")
// Inputs for MACD
fastLength = input(12, title="MACD Fast Length", tooltip="Length of the fast moving average for MACD.")
slowLength = input(26, title="MACD Slow Length", tooltip="Length of the slow moving average for MACD.")
signalLength = input(9, title="MACD Signal Length", tooltip="Length of the signal line for MACD.")
// Inputs for RSI
rsiLength = input(14, title="RSI Length", tooltip="Length of the RSI.")
overbought = input(70, title="Overbought Level", tooltip="RSI level considered overbought.")
oversold = input(30, title="Oversold Level", tooltip="RSI level considered oversold.")
// Inputs for Moving Average
maLength = input(20, title="MA Length", tooltip="Length of the moving average.")
// Inputs for Volume Filter
volumeThreshold = input(1.5, title="Volume Multiplier", step=0.1, tooltip="Multiplier for average volume to filter signals.")
// Inputs for ADX
adxLength = input(14, title="ADX Length", tooltip="Length of the ADX.")
adxThreshold = input(25, title="ADX Threshold", tooltip="Minimum ADX value to consider a strong trend.")
// Calculate MACD
[macdLine, signalLine, histLine] = ta.macd(close, fastLength, slowLength, signalLength)
// Calculate RSI
rsiValue = ta.rsi(close, rsiLength)
// Calculate Moving Average
maValue = ta.sma(close, maLength)
// Calculate Volume Average
volumeAvg = ta.sma(volume, 20)
// Calculate ADX
adxValue = ta.adx(high, low, close, adxLength)
// Enhanced Conditions for Buy Signal with Volume and ADX Filters
buySignal = ta.crossover(macdLine, signalLine) and (rsiValue < oversold) and (close > maValue) and (histLine > 0) and (volume > volumeAvg * volumeThreshold) and (adxValue > adxThreshold)
// Enhanced Conditions for Sell Signal with Volume and ADX Filters
sellSignal = ta.crossunder(macdLine, signalLine) and (rsiValue > overbought) and (close < maValue) and (histLine < 0) and (volume > volumeAvg * volumeThreshold) and (adxValue > adxThreshold)
// Plotting MACD
plot(macdLine, title="MACD Line", color=color.blue)
plot(signalLine, title="Signal Line", color=color.red)
plot(histLine, title="Histogram", style=plot.style_columns, color=(histLine >= 0 ? color.green : color.red))
// Plotting RSI
plot(rsiValue, title="RSI", color=color.purple)
hline(overbought, title="Overbought", color=color.red, linestyle=hline.style_dashed)
hline(oversold, title="Oversold", color=color.green, linestyle=hline.style_dashed)
// Plotting Moving Average
plot(maValue, title="SMA", color=color.orange)
// Plotting ADX
plot(adxValue, title="ADX", color=color.purple)
// Plotting Buy and Sell Signals
plotshape(buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(sellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
// Alerts
alertcondition(buySignal, title="Buy Alert", message="Buy Signal")
alertcondition(sellSignal, title="Sell Alert", message="Sell Signal")
این کد شامل ترکیب اندیکاتورهای MACD، RSI، میانگین متحرک، حجم و ADX است و سیگنالهای خرید و فروش را بر اساس این ترکیب تولید میکند. همچنین، شامل فیلترهای حجم و ADX برای تأیید سیگنالها است.