
Chiến lược giao dịch tự điều chỉnh giá chéo đường trung bình là một phương pháp giao dịch định lượng dựa trên đường trung bình di chuyển Hull ((HMA)). Chiến lược này sử dụng giá và chéo của HMA để tạo ra tín hiệu mua và bán, đồng thời đặt mức dừng và dừng cố định để quản lý rủi ro và lợi nhuận. Chiến lược sử dụng HMA 104 chu kỳ làm chỉ số chính, kết hợp với giá chéo để kích hoạt giao dịch.
Cốt lõi của chiến lược này là sử dụng trung bình di chuyển Hull ((HMA) làm chỉ số chính. HMA là một trung bình di chuyển tiên tiến, nó có thể phản ứng nhanh chóng với sự thay đổi giá trong khi giảm sự trì trệ.
Chiến lược này đảm bảo không mở lại các vị trí mở bằng cách theo dõi các vị trí đã có. Khi một giao dịch bị xóa, hệ thống đặt lại dấu hiệu để cho phép tín hiệu giao dịch mới có hiệu lực.
Chiến lược tự điều chỉnh giá giao dịch chéo là một phương pháp giao dịch đơn giản và hiệu quả. Bằng cách tận dụng lợi thế của đường trung bình di chuyển Hull, chiến lược này có thể nắm bắt xu hướng thị trường, đồng thời bảo vệ vốn bằng các biện pháp quản lý rủi ro cố định. Mặc dù có một số rủi ro tiềm ẩn đối với chiến lược, nhưng có thể nâng cao hơn nữa hiệu suất và khả năng thích ứng của nó bằng cách tối ưu hóa và cải tiến liên tục.
/*backtest
start: 2024-01-01 00:00:00
end: 2024-03-23 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("SHIESTD", overlay=true)
// Function to calculate Hull Moving Average (HMA)
hma(src, length) =>
wma1 = ta.wma(src, length)
wma2 = ta.wma(src, length / 2)
hma = ta.wma(2 * wma2 - wma1, math.round(math.sqrt(length)))
hma
// Parameters
hma_length = 104
// Calculate Hull Moving Average
hma_value = hma(close, hma_length)
// Plot HMA
plot(hma_value, title="104-period Hull Moving Average", color=color.blue, linewidth=2)
// Define SL and TP values in dollars
long_sl_amount = 1.25
long_tp_amount = 37.5
short_sl_amount = 1.25
short_tp_amount = 37.5
// Number of contracts
contracts = 2
// Function to calculate SL and TP prices based on entry price and dollar amounts
long_sl_price(entry_price) =>
entry_price - long_sl_amount
long_tp_price(entry_price) =>
entry_price + long_tp_amount
short_sl_price(entry_price) =>
entry_price + short_sl_amount
short_tp_price(entry_price) =>
entry_price - short_tp_amount
// Trading conditions
price_intersects_hma = ta.crossover(close, hma_value) or ta.crossunder(close, hma_value)
// Long and Short Conditions based on price intersecting HMA
long_condition = ta.crossover(close, hma_value)
short_condition = ta.crossunder(close, hma_value)
// Track open positions
var bool long_open = false
var bool short_open = false
// Handle Long Positions
if (long_condition and not long_open)
entry_price = close
strategy.entry("Long", strategy.long, qty=contracts)
strategy.exit("Exit Long", from_entry="Long", stop=long_sl_price(entry_price), limit=long_tp_price(entry_price))
long_open := true
// Handle Short Positions
if (short_condition and not short_open)
entry_price = close
strategy.entry("Short", strategy.short, qty=contracts)
strategy.exit("Exit Short", from_entry="Short", stop=short_sl_price(entry_price), limit=short_tp_price(entry_price))
short_open := true
// Reset flags when the position is closed
if (strategy.opentrades == 0)
long_open := false
short_open := false