OPEN-SOURCE SCRIPT
Pro Trend Buy/Sell/Exit [Copilot]

//version=5
indicator("Pro Trend Buy/Sell/Exit [Copilot]", overlay=true, max_labels_count=500)
// إعدادات قابلة للتخصيص
emaLength = input.int(55, "EMA Length")
rsiLength = input.int(14, "RSI Length")
rsiOverbought = input.float(70, "RSI Overbought")
rsiOversold = input.float(30, "RSI Oversold")
macdFastLen = input.int(12, "MACD Fast Length")
macdSlowLen = input.int(26, "MACD Slow Length")
macdSignalLen = input.int(9, "MACD Signal Length")
supertrendFactor = input.float(3, "Supertrend Factor")
supertrendATRlen = input.int(10, "Supertrend ATR Length")
showBuySellLabels = input.bool(true, "Show Buy/Sell Labels")
showExitLabels = input.bool(true, "Show Exit Labels")
// المؤشرات
ema = ta.ema(close, emaLength)
rsi = ta.rsi(close, rsiLength)
macdLine = ta.ema(close, macdFastLen) - ta.ema(close, macdSlowLen)
macdSignal = ta.ema(macdLine, macdSignalLen)
[supertrend, direction] = ta.supertrend(supertrendFactor, supertrendATRlen)
// حساب DMI (بديل ADX)
len = input.int(14, "DMI Length")
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
trur = ta.rma(ta.tr, len)
plusDI = 100 * ta.rma(plusDM, len) / trur
minusDI = 100 * ta.rma(minusDM, len) / trur
adx = ta.rma(math.abs(plusDI - minusDI) / (plusDI + minusDI) * 100, len)
// شروط الترند
trendUp = close > ema and adx > 25 and macdLine > macdSignal and direction == 1
trendDown = close < ema and adx > 25 and macdLine < macdSignal and direction == -1
// إشارات الدخول
buySignal = trendUp and ta.crossover(macdLine, macdSignal) and rsi > rsiOversold
sellSignal = trendDown and ta.crossunder(macdLine, macdSignal) and rsi < rsiOverbought
// إشارات الخروج
exitLong = buySignal[1] and (ta.crossunder(close, ema) or adx < 20 or ta.crossunder(rsi, 50) or direction == -1)
exitShort = sellSignal[1] and (ta.crossover(close, ema) or adx < 20 or ta.crossover(rsi, 50) or direction == 1)
// رسم الإشارات على الرسم البياني
plotshape(buySignal and showBuySellLabels, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", size=size.large)
plotshape(sellSignal and showBuySellLabels, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", size=size.large)
plotshape(exitLong and showExitLabels, style=shape.xcross, location=location.abovebar, color=color.orange, text="Exit Long", size=size.large)
plotshape(exitShort and showExitLabels, style=shape.xcross, location=location.belowbar, color=color.purple, text="Exit Short", size=size.large)
// إشعارات للبوت
alertcondition(buySignal, title="Buy Signal", message="BUY Signal on {{ticker}} at {{close}}")
alertcondition(sellSignal, title="Sell Signal", message="SELL Signal on {{ticker}} at {{close}}")
alertcondition(exitLong, title="Exit Long", message="EXIT LONG on {{ticker}} at {{close}}")
alertcondition(exitShort, title="Exit Short", message="EXIT SHORT on {{ticker}} at {{close}}")
indicator("Pro Trend Buy/Sell/Exit [Copilot]", overlay=true, max_labels_count=500)
// إعدادات قابلة للتخصيص
emaLength = input.int(55, "EMA Length")
rsiLength = input.int(14, "RSI Length")
rsiOverbought = input.float(70, "RSI Overbought")
rsiOversold = input.float(30, "RSI Oversold")
macdFastLen = input.int(12, "MACD Fast Length")
macdSlowLen = input.int(26, "MACD Slow Length")
macdSignalLen = input.int(9, "MACD Signal Length")
supertrendFactor = input.float(3, "Supertrend Factor")
supertrendATRlen = input.int(10, "Supertrend ATR Length")
showBuySellLabels = input.bool(true, "Show Buy/Sell Labels")
showExitLabels = input.bool(true, "Show Exit Labels")
// المؤشرات
ema = ta.ema(close, emaLength)
rsi = ta.rsi(close, rsiLength)
macdLine = ta.ema(close, macdFastLen) - ta.ema(close, macdSlowLen)
macdSignal = ta.ema(macdLine, macdSignalLen)
[supertrend, direction] = ta.supertrend(supertrendFactor, supertrendATRlen)
// حساب DMI (بديل ADX)
len = input.int(14, "DMI Length")
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
trur = ta.rma(ta.tr, len)
plusDI = 100 * ta.rma(plusDM, len) / trur
minusDI = 100 * ta.rma(minusDM, len) / trur
adx = ta.rma(math.abs(plusDI - minusDI) / (plusDI + minusDI) * 100, len)
// شروط الترند
trendUp = close > ema and adx > 25 and macdLine > macdSignal and direction == 1
trendDown = close < ema and adx > 25 and macdLine < macdSignal and direction == -1
// إشارات الدخول
buySignal = trendUp and ta.crossover(macdLine, macdSignal) and rsi > rsiOversold
sellSignal = trendDown and ta.crossunder(macdLine, macdSignal) and rsi < rsiOverbought
// إشارات الخروج
exitLong = buySignal[1] and (ta.crossunder(close, ema) or adx < 20 or ta.crossunder(rsi, 50) or direction == -1)
exitShort = sellSignal[1] and (ta.crossover(close, ema) or adx < 20 or ta.crossover(rsi, 50) or direction == 1)
// رسم الإشارات على الرسم البياني
plotshape(buySignal and showBuySellLabels, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", size=size.large)
plotshape(sellSignal and showBuySellLabels, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", size=size.large)
plotshape(exitLong and showExitLabels, style=shape.xcross, location=location.abovebar, color=color.orange, text="Exit Long", size=size.large)
plotshape(exitShort and showExitLabels, style=shape.xcross, location=location.belowbar, color=color.purple, text="Exit Short", size=size.large)
// إشعارات للبوت
alertcondition(buySignal, title="Buy Signal", message="BUY Signal on {{ticker}} at {{close}}")
alertcondition(sellSignal, title="Sell Signal", message="SELL Signal on {{ticker}} at {{close}}")
alertcondition(exitLong, title="Exit Long", message="EXIT LONG on {{ticker}} at {{close}}")
alertcondition(exitShort, title="Exit Short", message="EXIT SHORT on {{ticker}} at {{close}}")
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.