
Chiến lược này là một hệ thống theo dõi xu hướng dựa trên các tín hiệu chéo đường trung bình (EMA). Nó sử dụng 34 chu kỳ EMA làm chỉ số xu hướng chính, kết hợp với cơ chế kiểm soát lợi nhuận và rủi ro, để thực hiện giao dịch hoàn toàn tự động.
Chiến lược này hoạt động dựa trên các nguyên tắc cốt lõi sau:
Đây là một chiến lược theo dõi xu hướng được thiết kế hợp lý, logic và rõ ràng. Bằng cách nắm bắt xu hướng, sử dụng mục tiêu lợi nhuận nhiều lần để quản lý rủi ro và giữ một số vị trí để nắm bắt xu hướng lớn. Chiến lược có khả năng điều chỉnh mạnh mẽ, phù hợp với các thương nhân có sở thích rủi ro khác nhau. Mặc dù có một số rủi ro vốn có, nhưng có thể đạt được lợi nhuận ổn định bằng cách đặt tham số và quản lý rủi ro hợp lý.
/*backtest
start: 2024-02-08 00:00:00
end: 2025-02-06 08:00:00
period: 2d
basePeriod: 2d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA25 Long Strategy", overlay=true)
// Inputs
initial_capital = input.float(50000, title="Initial Capital ($)")
leverage = input.int(1, title="Leverage")
mode = input.string("Fixed Volume", title="Position Sizing Mode", options=["Fixed Volume", "Current Balance"])
ema_length = input.int(34, title="EMA Length")
stop_loss_percent = input.float(7, title="Stop Loss (%)", step=0.1) / 100
take_profit_1_percent = input.float(5, title="Take Profit 1 (%)", step=0.1) / 100
take_profit_2_percent = input.float(10, title="Take Profit 2 (%)", step=0.1) / 100
take_profit_3_percent = input.float(15, title="Take Profit 3 (%)", step=0.1) / 100
position_size_percent = input.float(100, title="Position Size (%)", step=1) / 100
long_term_hold_percent = input.float(10, title="Long Term Hold (%)", step=1) / 100
trade_delay = input.int(8, title="Trade Delay (hours)", minval=1) * 60 // Convert hours to minutes
// Calculate EMA
ema = ta.ema(close, ema_length)
// Plot EMA
plot(ema, title="EMA25", color=color.blue)
// Determine if a new trade can be placed
var float last_trade_time = na
can_trade = na(last_trade_time) or (time - last_trade_time) > trade_delay * 60 * 1000
// Determine position size based on selected mode
var float position_size = na
if (mode == "Fixed Volume")
position_size := initial_capital * leverage * position_size_percent / close
else
position_size := strategy.equity * leverage * position_size_percent / close
// Entry Condition
var float entry_price = na
price_crossed_ema_up = ta.crossover(close, ema)
price_crossed_ema_down = ta.crossunder(close, ema)
if ((price_crossed_ema_up or price_crossed_ema_down) and can_trade)
entry_price := ema
strategy.entry("Long", strategy.long, qty=position_size, limit=entry_price)
last_trade_time := time
label.new(bar_index, entry_price, text="Entry", color=color.green, style=label.style_label_up, textcolor=color.white, size=size.small)
// Stop Loss
strategy.exit("Stop Loss", from_entry="Long", stop=entry_price * (1 - stop_loss_percent))
// Take Profits
take_profit_1_price = entry_price * (1 + take_profit_1_percent)
take_profit_2_price = entry_price * (1 + take_profit_2_percent)
take_profit_3_price = entry_price * (1 + take_profit_3_percent)
strategy.exit("Take Profit 1", from_entry="Long", limit=take_profit_1_price, qty=position_size / 3)
strategy.exit("Take Profit 2", from_entry="Long", limit=take_profit_2_price, qty=position_size / 3)
strategy.exit("Take Profit 3", from_entry="Long", limit=take_profit_3_price, qty=position_size / 3)
// Long Term Hold (10% of position)
hold_qty = position_size * long_term_hold_percent
if (strategy.position_size > hold_qty)
strategy.close("Long Term Hold")