
Chiến lược này là một chiến lược chéo trung bình di chuyển đơn giản. Nó làm nhiều khi đi qua EMA chậm trên EMA nhanh và làm trống khi đi qua EMA chậm dưới EMA nhanh. Chiến lược này kết hợp dừng, dừng và dừng di chuyển để kiểm soát rủi ro hiệu quả.
Chiến lược này dựa trên đường trung bình di chuyển nhanh chậm. Đường nhanh là EMA 9 ngày, đường chậm là EMA 21 ngày. Khi đường nhanh đi qua đường chậm từ phía dưới, làm nhiều.
Đặt dừng dựa trên một phần trăm nhất định của gần, dừng dựa trên một phần trăm nhất định của gần. Đặt dừng di chuyển dựa trên một phần trăm nhất định của gần, khi giá đạt đến mức đó, dừng di chuyển đến giá mở cửa.
Chiến lược này có những ưu điểm sau:
Chiến lược này cũng có một số rủi ro:
Giải pháp:
Chiến lược này có thể được tối ưu hóa bằng cách:
Chiến lược này có thể đạt được hiệu quả tốt hơn bằng cách đặt các tham số hợp lý và điều chỉnh tối ưu hóa cho các thị trường khác nhau. Tuy nhiên, cần lưu ý đến nguy cơ báo cáo sai và khó tối ưu hóa tham số.
/*backtest
start: 2022-12-20 00:00:00
end: 2023-12-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("XAUUSD Strategy with SL, TP, and BE", shorttitle="EA", overlay=true)
// Define strategy parameters
fastLength = input(9, title="Fast EMA Length")
slowLength = input(21, title="Slow EMA Length")
stopLossPercent = input(1, title="Stop Loss (%)", minval=0, maxval=5) / 100
takeProfitPercent = input(2, title="Take Profit (%)", minval=0, maxval=5) / 100
breakEvenPercent = input(1, title="Break Even (%)", minval=0, maxval=5) / 100
// Calculate EMAs
fastEMA = ema(close, fastLength)
slowEMA = ema(close, slowLength)
// Plot EMAs on the chart
plot(fastEMA, color=color.blue, title="Fast EMA")
plot(slowEMA, color=color.red, title="Slow EMA")
// Strategy logic
enterLong = crossover(fastEMA, slowEMA)
exitLong = crossunder(fastEMA, slowEMA)
enterShort = crossunder(fastEMA, slowEMA)
exitShort = crossover(fastEMA, slowEMA)
// Calculate stop loss, take profit, and break-even levels
longStopLoss = close * (1 - stopLossPercent)
longTakeProfit = close * (1 + takeProfitPercent)
shortStopLoss = close * (1 + stopLossPercent)
shortTakeProfit = close * (1 - takeProfitPercent)
longBreakEven = close * (1 + breakEvenPercent)
shortBreakEven = close * (1 - breakEvenPercent)
// Execute strategy with stop loss, take profit, and break-even
strategy.entry("Long", strategy.long, when = enterLong)
strategy.exit("Take Profit/Stop Loss Long", from_entry="Long", profit = longTakeProfit, loss = longStopLoss)
strategy.entry("Short", strategy.short, when = enterShort)
strategy.exit("Take Profit/Stop Loss Short", from_entry="Short", profit = shortTakeProfit, loss = shortStopLoss)
// Move stop loss to break even when price reaches break-even level
strategy.exit("Break Even Long", from_entry="Long", loss = longBreakEven)
strategy.exit("Break Even Short", from_entry="Short", loss = shortBreakEven)