
Đây là hệ thống giao dịch theo xu hướng dựa trên tín hiệu giao nhau của Đường trung bình động hàm mũ ba (EMA). Hệ thống kết hợp ba đường trung bình động EMA8, EMA21 và EMA89, tạo ra các tín hiệu giao dịch thông qua điểm giao nhau của đường trung bình động và tích hợp chức năng dừng lỗ thông minh dựa trên tỷ lệ rủi ro-lợi nhuận để đạt được mục tiêu quản lý rủi ro tự động.
Hệ thống chủ yếu bao gồm các mô-đun chức năng cốt lõi sau:
Chiến lược này hiện thực hóa một hệ thống giao dịch theo xu hướng hoàn chỉnh bằng cách kết hợp hệ thống giao cắt trung bình động cổ điển với các phương pháp quản lý rủi ro hiện đại. Ưu điểm của hệ thống nằm ở cơ chế tạo tín hiệu đáng tin cậy và phương pháp kiểm soát rủi ro thông minh, nhưng trong các ứng dụng thực tế, vẫn cần tối ưu hóa tham số và mở rộng chức năng theo đặc điểm cụ thể của thị trường. Thông qua cải tiến và tối ưu hóa liên tục, chiến lược này dự kiến sẽ duy trì hiệu suất ổn định trong nhiều môi trường thị trường khác nhau.
/*backtest
start: 2024-12-06 00:00:00
end: 2025-01-04 08:00:00
period: 4h
basePeriod: 4h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Crossover with SL to BE", shorttitle="OmegaGalsky", overlay=true)
// Входни параметри
ema8_period = input.int(8, title="EMA 8 Period")
ema21_period = input.int(21, title="EMA 21 Period")
ema89_period = input.int(89, title="EMA 89 Period")
fixed_risk_reward = input.float(1.0, title="Risk/Reward Ratio (R2R)")
sl_percentage = input.float(0.001, title="Stop Loss Percentage", step=0.0001)
tp_percentage = input.float(0.0025, title="Take Profit Percentage", step=0.0001)
// Изчисляване на EMA
ema8 = ta.ema(close, ema8_period)
ema21 = ta.ema(close, ema21_period)
ema89 = ta.ema(close, ema89_period)
// Условия за BUY
buy_condition = ta.crossover(ema8, ema21) and close > ema89 and close > open
// Условия за SELL
sell_condition = ta.crossunder(ema8, ema21) and close < ema89 and close < open
// Вход в BUY позиция
if (buy_condition)
stop_loss = close * (1 - sl_percentage)
take_profit = close * (1 + tp_percentage)
strategy.entry("BUY", strategy.long)
strategy.exit("TP/SL", from_entry="BUY", stop=stop_loss, limit=take_profit)
// Вход в SELL позиция
if (sell_condition)
stop_loss = close * (1 + sl_percentage)
take_profit = close * (1 - tp_percentage)
strategy.entry("SELL", strategy.short)
strategy.exit("TP/SL", from_entry="SELL", stop=stop_loss, limit=take_profit)
// Логика за преместване на стоп към BE
if (strategy.position_size > 0)
entry_price = strategy.position_avg_price
// За LONG позиция
if (strategy.position_size > 0 and high >= entry_price + (entry_price * sl_percentage * fixed_risk_reward))
strategy.exit("SL to BE", from_entry="BUY", stop=entry_price)
label.new(bar_index, high, "SL moved to BE", color=color.green)
// За SHORT позиция
if (strategy.position_size < 0 and low <= entry_price - (entry_price * sl_percentage * fixed_risk_reward))
strategy.exit("SL to BE", from_entry="SELL", stop=entry_price)
label.new(bar_index, low, "SL moved to BE", color=color.red)
// Чертеж на EMA
plot(ema8, color=color.orange, title="EMA 8")
plot(ema21, color=color.blue, title="EMA 21")
plot(ema89, color=color.purple, title="EMA 89")