Chiến lược động lực dựa trên DEMA và EMA Crossover với bộ lọc biến động ATR

Tác giả:ChaoZhang, Ngày: 2024-01-08 14:14:57
Tags:

img

I. Tổng quan chiến lược

Chiến lược này được đặt tên là Momentum Strategy Based on DEMA and EMA Crossover with ATR Volatility Filter. Nó tạo ra các tín hiệu giao dịch ngắn hạn bằng cách phát hiện DEMA và EMA crossover kết hợp với chỉ số biến động ATR. Khi DEMA vượt dưới EMA trong khi ATR tăng, nó rút ngắn chứng khoán. Khi DEMA vượt qua lại EMA, nó đóng vị trí.

II. Chiến lược logic

  1. Tính toán chỉ số DEMA. DEMA là Đường trung bình di chuyển nhân tố kép sử dụng EMA kép, có thể lọc tiếng ồn thị trường ngắn hạn và cải thiện độ chính xác tín hiệu.

  2. Tính toán chỉ số EMA. EMA là Mức trung bình chuyển động nhân tố phản ứng nhanh hơn với sự thay đổi giá.

  3. Tính toán chỉ số biến động ATR. ATR đo biến động thị trường và mức độ rủi ro. ATR tăng đại diện cho sự biến động tăng và khả năng giảm giá ngắn hạn.

  4. Khi DEMA vượt dưới EMA và ATR tăng trên ngưỡng, nó báo hiệu sự khởi đầu của một xu hướng giảm ngắn hạn và tăng rủi ro thị trường.

  5. Khi DEMA vượt qua EMA, nó báo hiệu hỗ trợ giá và tăng giá.

III. Ưu điểm

  1. Sự kết hợp của EMA và EMA kép có thể cải thiện hiệu quả độ chính xác tín hiệu.

  2. Bộ lọc biến động ATR loại bỏ các giao dịch whipsaw có rủi ro thấp.

  3. Thời gian nắm giữ ngắn phù hợp với việc theo dõi đà phát triển ngắn hạn và tránh bảo hiểm kéo dài.

  4. Logic đơn giản và rõ ràng, dễ hiểu và thực hiện.

IV. Rủi ro

  1. Các thông số ATR không phù hợp có thể làm mất cơ hội giao dịch.

  2. Cần phải theo dõi cả tín hiệu dài và ngắn cùng một lúc, làm tăng khó khăn hoạt động.

  3. Được ảnh hưởng bởi biến động thị trường ngắn hạn.

Giải pháp: Tối ưu hóa tham số thông qua backtesting; đơn giản hóa logic để tập trung vào một bên; thư giãn mức dừng lỗ phù hợp.

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

  1. Tối ưu hóa các thông số cho DEMA và EMA để tìm kết hợp tốt nhất.

  2. Tối ưu hóa thời gian xem lại ATR để xác định điểm chuẩn biến động tối ưu.

  3. Thêm các chỉ số khác như BOLL Bands để cải thiện độ chính xác tín hiệu.

  4. Đưa ra các quy tắc dừng lỗ và lấy lợi nhuận để khóa trong lợi nhuận nhất quán hơn.

VI. Kết luận

Chiến lược này xây dựng một hệ thống giao dịch ngắn hạn đơn giản nhưng hiệu quả bằng cách sử dụng DEMA, EMA crossover và chỉ số biến động ATR. Logic sạch và dễ vận hành làm cho nó phù hợp với giao dịch động lượng tần số cao.


/*backtest
start: 2023-12-08 00:00:00
end: 2024-01-07 00:00:00
period: 1h
basePeriod: 15m
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/
// © Qorbanjf

//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Qorbanjf

//@version=4
strategy("Qorban: DEMA/EMA & VOL Short ONLY", shorttitle="DEMA/EMA & VOL SHORT", overlay=true)

// DEMA
length = input(10, minval=1, title="DEMA LENGTH")
src = input(close, title="Source")
e1 = ema(src, length)
e2 = ema(e1, length)
dema1 = 2 * e1 - e2
plot(dema1, "DEMA", color=color.yellow)

//EMA
len = input(25, minval=1, title="EMA Length")
srb = input(close, title="Source")
offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)
ema1 = ema(srb, len)
plot(ema1, title="EMA", color=color.blue, offset=offset)

// get ATR VALUE
atr = atr(14)

//ATRP (Average True Price in precentage)

// Inputs
atrTimeFrame = input("D", title="ATR Timeframe", type=input.resolution)
atrLookback = input(defval=14,title="ATR Lookback Period",type=input.integer)
useMA = input(title = "Show Moving Average?", type = input.bool, defval = true)
maType = input(defval="EMA", options=["EMA", "SMA"], title = "Moving Average Type")
maLength = input(defval = 20, title = "Moving Average Period", minval = 1)
slType = input(title="Stop Loss ATR / %", type=input.float, defval=5.0, step=0.1)
slMulti = input(title="SL Multiplier", type=input.float, defval=1.0, step=0.1)
minimumProfitPercent = input(title="Minimum profit %", type=input.float, defval=20.00)

// ATR Logic
// atrValue = atr(atrLookback)
// atrp = (atrValue/close)*100
// plot(atrp, color=color.white, linewidth=2, transp = 30)

atrValue = security(syminfo.tickerid, atrTimeFrame, atr(atrLookback))
atrp = (atrValue/close)*100

// Moving Average Logic
ma(maType, src, length) =>
    maType == "EMA" ? ema(src, length) : sma(src, length) //Ternary Operator (if maType equals EMA, then do ema calc, else do sma calc)
maFilter = security(syminfo.tickerid, atrTimeFrame, ma(maType, atrp, maLength))


// Determine percentage of open profit
var entry = 0.0
distanceProfit = low - entry
distanceProfitPercent = distanceProfit / entry

//Determin if we have a long entry signal OR a sell position signal
profitSignal = minimumProfitPercent == 0.0 or distanceProfitPercent >= minimumProfitPercent
shortSignal = crossunder(dema1, ema1) and atrp > maFilter and strategy.position_size == 0 and not na(atr)
exitSignal = profitSignal and strategy.position_size !=0 and  crossover(dema1, ema1)


// === INPUT BACKTEST RANGE ===
//FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
//FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
//FromYear  = input(defval = 2017, title = "From Year", minval = 2000)
//ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
//ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
//ToYear    = input(defval = 9999, title = "To Year", minval = 2017)

//Invert trade direction & flipping 
//tradInvert = input(defval = false, title = "invert trade direction")
//MOM_MR = input(defval=1, title = "MOM = 1 / MR = -1", minval=-1, maxval=1)
//plots=input(false, title="Show plots?")

// Get stop loss (in pips AND percentage distance)
shortStop = highest(high, 4) - (atr * slMulti)
shortStopPercent = close - (close * slMulti)

// Save long stop & target prices (used for drawing data to the chart & deetermining profit)
var shortStopSaved = 0.0
var shortTargetSaved = 0.0
enterShort = false
if shortSignal
    shortStopSaved := slType ? shortStop : shortStopPercent
    enterShort:= true
    entry := close


// long conditions 
//enterLong = crossover(dema1, ema1) and atrp < maFilter
//exitSignal => crossunder(dema1, ema1)

//Enter trades when conditions are met
strategy.entry("short", strategy.short, when=enterShort, comment="SHORT")

//place exit orders (only executed after trades are active)
strategy.exit(id="Short exit",
 from_entry="short",
 limit=exitSignal ? close : na,
 stop=shortStopSaved,
 when=strategy.position_size > 0,
 comment="end short")
 

//short strategy
//goShort() => crossunder(dema1, ema1) and atrp > maFilter
//KillShort() => crossover(dema1, ema1) 
//strategy.entry("SHORT", strategy.short, when = goShort())
//strategy.close("COVER", when = KillShort())


Thêm nữa