Chiến lược kết hợp DMI và HMA

Tác giả:ChaoZhang, Ngày: 2024-01-04 17:23:06
Tags:

img

Tổng quan

Chiến lược này kết hợp chỉ số chuyển động theo hướng (DMI) và trung bình chuyển động Hull (HMA) để xác định hướng thị trường với DMI và xác nhận sức mạnh xu hướng với HMA, mà không cần quản lý rủi ro.

Chiến lược logic

  1. Tính toán True Range, DIPlus, DIMinus và ADX.

  2. Tính toán trung bình di chuyển nhanh và chậm của thân tàu (HMA).

  3. Khởi động bước vào dài khi DIPlus vượt qua DIMinus và HMA nhanh vượt qua HMA chậm.

  4. Bắt đầu truy cập ngắn khi DIMinus vượt dưới DIPlus và HMA nhanh vượt dưới HMA chậm.

  5. Đặt lệnh dài/ ngắn trên tín hiệu nhập cảnh.

Phân tích lợi thế

Việc xác nhận hai lần từ chỉ số xu hướng DMI và Hull MA đảm bảo độ chính xác trong việc nắm bắt xu hướng thị trường và tránh các whipsaws.

Phân tích rủi ro

Rủi ro chính đến từ không dừng lỗ, không kiểm soát lỗ khi biến động thị trường lớn xảy ra.

Các giải pháp có thể bao gồm thêm stop loss di chuyển, tối ưu hóa hỗn hợp tham số vv

Hướng dẫn tối ưu hóa

  1. Thêm ATR stop loss dựa trên True Range.

  2. Tối ưu hóa thời gian Hull để tìm ra kết hợp tốt nhất.

  3. Mức giới hạn động cho tín hiệu dài / ngắn.

  4. Thêm bộ lọc động lực để đảm bảo tính liên tục của xu hướng.

Tóm lại

Kết hợp DMI và HMA hoạt động xuất sắc trong việc xác định xu hướng với sự đơn giản và hiệu quả.


/*backtest
start: 2022-12-28 00:00:00
end: 2024-01-03 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Tuned_Official
//@version=4
strategy(title="DMI + HMA - No Risk Management", overlay = false, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.025)

//Inputs
hullLen1 = input(title="Hull 1 length", type=input.integer, defval=29)
hullLen2 = input(title="Hull 2 length", type=input.integer, defval=2)
len = input(title="Length for DI", type=input.integer, defval=76)

//Calculations
TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0

SmoothedTrueRange = 0.0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = 0.0
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus

//Indicators
fasthull = hma(close, hullLen1)
slowhull = hma(close, hullLen2)
DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
ADX = sma(DX, len)

//Plots
plot(DIPlus, color=color.green, title="DI+")
plot(DIMinus, color=color.red, title="DI-")
plot(ADX, color=color.black, title="ADX")

//conditions
go_long = crossover(DIPlus, DIMinus) and fasthull > slowhull //crossover(fasthull, slowhull) and DIPlus > DIMinus
go_short = crossover(DIMinus, DIPlus) and fasthull < slowhull //crossunder(fasthull, slowhull) and DIMinus > DIPlus

//Entry
if strategy.position_size < 0 or strategy.position_size == 0
    strategy.order("long", strategy.long, when=go_long)

if strategy.position_size > 0 or strategy.position_size == 0
    strategy.order("Short", strategy.short, when=go_short)

Thêm nữa