
Chiến lược này là một hệ thống giao dịch dựa trên đường chéo trung bình di chuyển chỉ số dài hạn (EMA) kết hợp với cơ chế quản lý vị trí động và kiểm soát rủi ro. Chiến lược này nhận diện xu hướng thị trường thông qua đường chéo EMA 21 chu kỳ và 55 chu kỳ, đồng thời điều chỉnh kích thước vị trí giao dịch theo tỷ lệ lợi nhuận rủi ro và tỷ lệ rủi ro tùy chỉnh của người dùng, kiểm soát chính xác rủi ro.
Lịch lý cốt lõi của chiến lược được xây dựng dựa trên tín hiệu giao chéo EMA của hai chu kỳ thời gian. Khi EMA chu kỳ 21 đi lên vượt qua EMA chu kỳ 55, hệ thống nhận ra là xu hướng tăng và kích hoạt nhiều tín hiệu; Khi EMA chu kỳ 21 đi xuống vượt qua EMA chu kỳ 55, hệ thống nhận ra là xu hướng giảm và kích hoạt tín hiệu phá vỡ.
Chiến lược này xây dựng một hệ thống giao dịch hoàn chỉnh bằng cách kết hợp tín hiệu xu hướng EMA và quản lý rủi ro động. Điểm mạnh cốt lõi của chiến lược là cơ chế quản lý vị trí và kiểm soát rủi ro khoa học của nó, nhưng vẫn cần tối ưu hóa các tham số thích hợp theo môi trường thị trường và sở thích rủi ro cá nhân.
/*backtest
start: 2024-02-21 00:00:00
end: 2024-07-11 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Carlos Humberto Rodríguez Arias
//@version=5
strategy("EMA Crossover Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// EMA periods
MT_EMA = input.int(21, title="Medium Term EMA")
LT_EMA = input.int(55, title="Long Term EMA")
RR = input.float(2.0, title="Risk-Reward Ratio") // User-defined RR
RiskPercent = input.float(1.0, title="Risk Percentage") // User-defined risk percentage
// Calculate EMAs
Signal_MT_EMA = ta.ema(close, MT_EMA)
Signal_LT_EMA = ta.ema(close, LT_EMA)
// Plot EMAs
plot(Signal_MT_EMA, title="Medium Term EMA", color=color.orange, linewidth=2)
plot(Signal_LT_EMA, title="Long Term EMA", color=color.blue, linewidth=2)
// Determine trend conditions
uptrend = ta.crossover(Signal_MT_EMA, Signal_LT_EMA)
downtrend = ta.crossunder(Signal_MT_EMA, Signal_LT_EMA)
// Stop-Loss Calculations
longStopLoss = ta.lowest(low, 2) // SL for buy = lowest low of last 2 candles
shortStopLoss = ta.highest(high, 2) // SL for sell = highest high of last 2 candles
// Take-Profit Calculations
longTakeProfit = close + (close - longStopLoss) * RR
shortTakeProfit = close - (shortStopLoss - close) * RR
// Calculate Position Size based on Risk Percentage
capital = strategy.equity * (RiskPercent / 100)
longPositionSize = capital / (close - longStopLoss)
shortPositionSize = capital / (shortStopLoss - close)
// Execute Buy Order
if uptrend
strategy.entry("Long", strategy.long, qty=longPositionSize)
strategy.exit("Long Exit", from_entry="Long", stop=longStopLoss, limit=longTakeProfit)
// Execute Sell Order
if downtrend
strategy.entry("Short", strategy.short, qty=shortPositionSize)
strategy.exit("Short Exit", from_entry="Short", stop=shortStopLoss, limit=shortTakeProfit)