
Strategi ini adalah sistem perdagangan kuantitatif berfrekuensi tinggi berdasarkan indikator EMA dan MACD, yang menggabungkan stop loss dan manajemen posisi cerdas ATR. Strategi ini menggunakan EMA crossover 9 dan 21 siklus sebagai sinyal masuk utama, bekerja sama dengan indikator MACD untuk konfirmasi sinyal, dan melalui stop loss dan profit target yang dihitung secara dinamis oleh ATR, untuk mencapai loop perdagangan yang lengkap dan sistem kontrol risiko.
Strategi ini menggunakan kombinasi indikator teknis berlapis untuk mengidentifikasi peluang perdagangan. Pertama, menggunakan persimpangan rata-rata EMA periode pendek ((9) dan periode panjang ((21)) sebagai sinyal awal, menghasilkan sinyal do lebih ketika rata-rata jangka pendek melintasi rata-rata jangka panjang ke atas, sebaliknya menghasilkan sinyal do minus. Kedua, menggunakan indikator MACD yang dioptimalkan ((6,13,4)) sebagai sinyal konfirmasi, yang mengharuskan hubungan posisi garis MACD dengan garis sinyal untuk konsisten dengan arah persimpangan EMA.
Strategi ini membangun sistem perdagangan frekuensi tinggi yang lengkap dengan menggabungkan indikator teknis klasik dan metode manajemen risiko modern. Keunggulan inti dari strategi ini adalah pengakuan sinyal ganda dan kontrol risiko yang ketat, tetapi masih perlu diuji dan dioptimalkan secara menyeluruh di lingkungan real-time.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-04 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("High-Frequency Trade Script with EMA, MACD, and ATR-based TP/SL", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=2, initial_capital=100000)
// إعداد المؤشرات
emaBuy = ta.ema(close, 9) // EMA بفترة قصيرة للشراء
emaSell = ta.ema(close, 21) // EMA بفترة أطول للبيع
[macdLine, signalLine, _] = ta.macd(close, 6, 13, 4) // MACD بفترات قصيرة
atr = ta.atr(14) // حساب مؤشر ATR
// إعداد نسبة وقف الخسارة وجني الأرباح
stopLossATRMultiplier = 1.5 // تقليل وقف الخسارة لـ 1.5 * ATR
riskToRewardRatio = 2.0 // نسبة العائد إلى المخاطرة 1:2
// إعداد إدارة المخاطر
riskPercentage = 1.0 // المخاطرة كـ 1% من رأس المال
capital = strategy.equity // إجمالي رأس المال
riskAmount = capital * (riskPercentage / 100) // مقدار المخاطرة
// شروط إشارات الشراء: تقاطع EMA القصير فوق الطويل و MACD أعلى من Signal
longCondition = ta.crossover(emaBuy, emaSell) and macdLine > signalLine
// شروط إشارات البيع: تقاطع EMA القصير تحت الطويل و MACD أسفل Signal
shortCondition = ta.crossunder(emaBuy, emaSell) and macdLine < signalLine
// --- تنفيذ أوامر الشراء والبيع تلقائيًا مع وقف الخسارة وجني الأرباح --- //
// تعريف خطوط وقف الخسارة وجني الأرباح
var line longStopLossLine = na
var line longTakeProfitLine = na
var line shortStopLossLine = na
var line shortTakeProfitLine = na
if (longCondition)
longEntryPrice = close // سعر الدخول للشراء
longStopLoss = longEntryPrice - (atr * stopLossATRMultiplier) // وقف الخسارة بناءً على ATR
longTakeProfit = longEntryPrice + ((longEntryPrice - longStopLoss) * riskToRewardRatio) // جني الأرباح بنسبة 1:2
// حساب حجم الصفقة بناءً على مقدار المخاطرة
positionSize = riskAmount / (longEntryPrice - longStopLoss) // حجم العقد
// إدخال أمر الشراء
strategy.entry("Buy", strategy.long, qty=positionSize)
// إعداد أوامر وقف الخسارة وجني الأرباح
strategy.exit("Take Profit/Stop Loss", "Buy", stop=longStopLoss, limit=longTakeProfit)
// رسم الخطوط لجني الأرباح ووقف الخسارة
// longStopLossLine := line.new(bar_index, longStopLoss, bar_index + 1, longStopLoss, color=color.red, width=1, style=line.style_dashed) // خط وقف الخسارة
// longTakeProfitLine := line.new(bar_index, longTakeProfit, bar_index + 1, longTakeProfit, color=color.green, width=1, style=line.style_dashed) // خط جني الأرباح
if (shortCondition)
shortEntryPrice = close // سعر الدخول للبيع
shortStopLoss = shortEntryPrice + (atr * stopLossATRMultiplier) // وقف الخسارة بناءً على ATR
shortTakeProfit = shortEntryPrice - ((shortStopLoss - shortEntryPrice) * riskToRewardRatio) // جني الأرباح بنسبة 1:2
// حساب حجم الصفقة بناءً على مقدار المخاطرة
positionSize = riskAmount / (shortStopLoss - shortEntryPrice) // حجم العقد
// إدخال أمر البيع
strategy.entry("Sell", strategy.short, qty=positionSize)
// إعداد أوامر وقف الخسارة وجني الأرباح
strategy.exit("Take Profit/Stop Loss", "Sell", stop=shortStopLoss, limit=shortTakeProfit)
// رسم الخطوط لجني الأرباح ووقف الخسارة
// shortStopLossLine := line.new(bar_index, shortStopLoss, bar_index + 1, shortStopLoss, color=color.red, width=1, style=line.style_dashed) // خط وقف الخسارة
// shortTakeProfitLine := line.new(bar_index, shortTakeProfit, bar_index + 1, shortTakeProfit, color=color.green, width=1, style=line.style_dashed) // خط جني الأرباح
// --- رسم مؤشرات منفصلة --- //
plot(emaBuy, title="EMA Buy (9)", color=color.green, linewidth=2) // EMA الشراء
plot(emaSell, title="EMA Sell (21)", color=color.red, linewidth=2) // EMA البيع
plot(macdLine, title="MACD Line", color=color.blue, linewidth=1) // MACD Line
plot(signalLine, title="Signal Line", color=color.orange, linewidth=1) // Signal Line