
Chiến lược này là một hệ thống giao dịch theo dõi xu hướng dựa trên các đường trung bình di chuyển đa chỉ số ((EMA)). Nó sử dụng hình thức giao dịch vàng hình thành từ ba đường trung bình EMA25, EMA50 và EMA100 để xác nhận xu hướng tăng mạnh và tham gia vào một đợt khi giá vượt qua EMA25. Chiến lược này sử dụng phương pháp dừng lỗ động và dừng đợt để quản lý rủi ro và lợi nhuận.
Logic cốt lõi của chiến lược bao gồm những phần chính sau:
Chiến lược này xây dựng một hệ thống giao dịch theo dõi xu hướng hoàn chỉnh hơn bằng cách kết hợp nhiều đường trung bình và cách hoạt động theo đợt. Ưu điểm của chiến lược là kết hợp nhiều yếu tố quan trọng của theo dõi xu hướng và quản lý rủi ro, nhưng vẫn cần tối ưu hóa tham số và cải tiến quy tắc theo tình hình thị trường thực tế.
/*backtest
start: 2024-11-19 00:00:00
end: 2024-12-18 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("Golden Cross with Customizable TP/SL", overlay=true)
// Parameters for EMA
ema_short_length = 25
ema_mid_length = 50
ema_long_length = 100
// Parameters for stop-loss and take-profit
lookback_bars = input.int(20, title="Lookback bars for lowest low")
pip_buffer = input.float(0.0003, title="Stop-loss buffer (pips)") // Fixed default pip value (e.g., 3 pips for 5-digit pairs)
tp_multiplier1 = input.float(1.0, title="Take-profit multiplier 1")
tp_multiplier2 = input.float(1.5, title="Take-profit multiplier 2")
// Calculate EMAs
ema25 = ta.ema(close, ema_short_length)
ema50 = ta.ema(close, ema_mid_length)
ema100 = ta.ema(close, ema_long_length)
// Golden Cross condition (EMA25 > EMA50 > EMA100)
golden_cross = ema25 > ema50 and ema50 > ema100
// Entry condition: Candle crosses above EMA25 after a golden cross
cross_above_ema25 = ta.crossover(close, ema25)
entry_condition = golden_cross and cross_above_ema25
// Stop-loss and take-profit calculation
lowest_low = ta.lowest(low, lookback_bars)
var float entry_price = na
var float stop_loss = na
var float take_profit1 = na
var float take_profit2 = na
if (entry_condition)
entry_price := close
stop_loss := lowest_low - pip_buffer
take_profit1 := entry_price + (entry_price - stop_loss) * tp_multiplier1
take_profit2 := entry_price + (entry_price - stop_loss) * tp_multiplier2
strategy.entry("Buy1", strategy.long, qty=0.5) // First 50%
strategy.entry("Buy2", strategy.long, qty=0.5) // Second 50%
// Separate exit conditions for each entry
cross_below_ema100 = ta.crossunder(close, ema100)
exit_condition1 = close >= take_profit1
exit_condition2 = close >= take_profit2
exit_condition_sl = close <= stop_loss
if (exit_condition1 or cross_below_ema100)
strategy.close("Buy1")
if (exit_condition2 or cross_below_ema100 or exit_condition_sl)
strategy.close("Buy2")
// Plot EMAs
plot(ema25, color=color.blue, title="EMA 25")
plot(ema50, color=color.orange, title="EMA 50")
plot(ema100, color=color.red, title="EMA 100")