PROTECTED SOURCE SCRIPT
استراتيجية محسنة: تقليل الخسائر، إدارة ذكية

//version=5
strategy("استراتيجية محسنة: تقليل الخسائر، إدارة ذكية", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// الإعدادات
emaFastLen = input.int(20, title="EMA سريع")
emaSlowLen = input.int(50, title="EMA بطيء")
atrLength = input.int(14, title="طول ATR")
riskMultiplier = input.float(1.0, title="نسبة المخاطرة من ATR", step=0.1)
takeProfitRatio = input.float(1.5, title="نسبة الهدف الربحي إلى وقف الخسارة", step=0.1)
maxConsecutiveLosses = input.int(2, title="عدد الخسائر المتتالية المسموح بها")
// حساب المتوسطات والاتجاه
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)
atr = ta.atr(atrLength)
longCondition = ta.crossover(emaFast, emaSlow)
shortCondition = ta.crossunder(emaFast, emaSlow)
// متابعة الخسائر المتتالية
var int lossCount = 0
if strategy.closedtrades > 0
lastTrade = strategy.closedtrades - 1
isLoss = strategy.closedtrades.profit(lastTrade) < 0
lossCount := isLoss ? lossCount + 1 : 0
canTrade = lossCount <= maxConsecutiveLosses
// الدخول في صفقات شراء فقط (بناء على طلب المستخدم)
if longCondition and canTrade
stopLoss = close - (atr * riskMultiplier)
takeProfit = close + ((close - stopLoss) * takeProfitRatio)
strategy.entry("Buy", strategy.long)
strategy.exit("TP/SL", from_entry="Buy", stop=stopLoss, limit=takeProfit)
// تفعيل trailing stop عند الربح
trailTrigger = input.float(0.5, title="نقطة تفعيل Trailing (%)", step=0.1) / 100
trailOffset = input.float(0.3, title="مسافة Trailing Stop (%)", step=0.1) / 100
if strategy.opentrades > 0
entryPrice = strategy.opentrades.entry_price(0)
if close > entryPrice * (1 + trailTrigger)
trailStop = close * (1 - trailOffset)
strategy.exit("Trail Exit", from_entry="Buy", stop=trailStop)
plot(emaFast, color=color.green, title="EMA سريع")
plot(emaSlow, color=color.red, title="EMA بطيء")
strategy("استراتيجية محسنة: تقليل الخسائر، إدارة ذكية", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// الإعدادات
emaFastLen = input.int(20, title="EMA سريع")
emaSlowLen = input.int(50, title="EMA بطيء")
atrLength = input.int(14, title="طول ATR")
riskMultiplier = input.float(1.0, title="نسبة المخاطرة من ATR", step=0.1)
takeProfitRatio = input.float(1.5, title="نسبة الهدف الربحي إلى وقف الخسارة", step=0.1)
maxConsecutiveLosses = input.int(2, title="عدد الخسائر المتتالية المسموح بها")
// حساب المتوسطات والاتجاه
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)
atr = ta.atr(atrLength)
longCondition = ta.crossover(emaFast, emaSlow)
shortCondition = ta.crossunder(emaFast, emaSlow)
// متابعة الخسائر المتتالية
var int lossCount = 0
if strategy.closedtrades > 0
lastTrade = strategy.closedtrades - 1
isLoss = strategy.closedtrades.profit(lastTrade) < 0
lossCount := isLoss ? lossCount + 1 : 0
canTrade = lossCount <= maxConsecutiveLosses
// الدخول في صفقات شراء فقط (بناء على طلب المستخدم)
if longCondition and canTrade
stopLoss = close - (atr * riskMultiplier)
takeProfit = close + ((close - stopLoss) * takeProfitRatio)
strategy.entry("Buy", strategy.long)
strategy.exit("TP/SL", from_entry="Buy", stop=stopLoss, limit=takeProfit)
// تفعيل trailing stop عند الربح
trailTrigger = input.float(0.5, title="نقطة تفعيل Trailing (%)", step=0.1) / 100
trailOffset = input.float(0.3, title="مسافة Trailing Stop (%)", step=0.1) / 100
if strategy.opentrades > 0
entryPrice = strategy.opentrades.entry_price(0)
if close > entryPrice * (1 + trailTrigger)
trailStop = close * (1 - trailOffset)
strategy.exit("Trail Exit", from_entry="Buy", stop=trailStop)
plot(emaFast, color=color.green, title="EMA سريع")
plot(emaSlow, color=color.red, title="EMA بطيء")
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya dengan percuma dan tanpa had – ketahui lebih lanjut di sini.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya dengan percuma dan tanpa had – ketahui lebih lanjut di sini.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.