Hệ thống giao dịch định lượng tích hợp đa chiến lược


Ngày tạo: 2023-09-15 12:29:33 sửa đổi lần cuối: 2023-09-15 12:29:33
sao chép: 0 Số nhấp chuột: 818
1
tập trung vào
1617
Người theo dõi

Bài viết này sẽ giới thiệu cho bạn về một chiến lược giao dịch thuật toán tiền tệ kỹ thuật số có tên là Quantified Trading System (QTS) được tích hợp nhiều chiến lược. Chiến lược này tích hợp các lợi thế của nhiều chiến lược đơn lẻ để xây dựng một danh mục nhiều chiến lược với mục đích đạt được sự ổn định và đa dạng cao hơn.

Chiến lược này kết hợp bốn chiến lược giao dịch định lượng phổ biến, bao gồm:

  1. Chiến lược phá vỡ kênh: Xây dựng các kênh lên xuống dựa trên giá cao nhất và giá thấp nhất trong một chu kỳ nhất định và tạo thêm khoảng trống khi giá phá vỡ kênh.

  2. Chiến lược động lực: Xác định động lực dựa trên hướng thay đổi giá trong một chu kỳ nhất định, làm nhiều khi giá tăng lên và giảm khi giảm.

  3. Chiến lược MACD: Xây dựng nhiều vị trí giảm giá dựa trên đường trung bình nhanh và chậm.

  4. Chiến lược hình thành Harami: Xác định sự đảo ngược giá trong tương lai bằng cách nhận ra các hình dạng cụ thể, giao dịch gần điểm biến.

Các chiến lược này có những lợi thế riêng biệt, và khi kết hợp với nhau, chúng có thể mang lại lợi nhuận ổn định hơn.

Chiến lược phá vỡ kênh có thể nắm bắt xu hướng của thị trường; Chiến lược động lực có thể theo dõi xu hướng ngắn hạn kịp thời; Chiến lược MACD có thể phát hiện điểm biến đổi xu hướng trung bình; Chiến lược Harami có thể đánh giá điểm đảo ngược quan trọng.

Kết hợp chúng trong một chiến lược, bạn có thể thực hiện theo đuổi giảm trong xu hướng và mở vị trí phản đối gần điểm biến đổi. Ngoài ra, bạn cũng có thể phân tán rủi ro giữa các chiến lược khác nhau.

Tất nhiên, sự kết hợp nhiều chiến lược này cũng có một số nhược điểm:

  1. Chiến lược quá phức tạp, điều chỉnh tham số khó khăn

  2. Một số chiến lược có thể mâu thuẫn

  3. Tăng tần suất và chi phí giao dịch

  4. Phản hồi có thể kém hơn một chiến lược đơn lẻ

Do đó, người dùng khi sử dụng kết hợp đa chiến lược này cần chú ý đến sự khó khăn của điều chỉnh tham số, kiểm tra tác động lẫn nhau giữa các xung đột, kiểm soát tần suất giao dịch và kiểm tra lại đầy đủ để đảm bảo tính ổn định lâu dài.

Nhìn chung, hệ thống giao dịch định lượng đa chiến lược này có thể có được một danh mục giao dịch rất phong phú và hoạt động rất tốt trong xu hướng lớn. Nó kết hợp các lợi thế của các chiến lược khác nhau để có được lợi nhuận tích cực lâu dài ổn định hơn.

Mã nguồn chiến lược
/*backtest
start: 2023-09-07 00:00:00
end: 2023-09-14 00:00:00
period: 45m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3

//Channel breakout
strategy("all_strategy", overlay=true)

length = input(title="Length", minval=1, maxval=1000, defval=5)

upBound = highest(high, length)
downBound = lowest(low, length)

if (not na(close[length]))
    strategy.entry("ChBrkLE", strategy.long, stop=upBound + syminfo.mintick, comment="ChBrkLE")
    strategy.entry("ChBrkSE", strategy.short, stop=downBound - syminfo.mintick, comment="ChBrkSE")

//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)


//Momentum
length1 = input(12)
price = close

momentum(seria, length) =>
    mom = seria - seria[length1]
    mom

mom0 = momentum(price, length1)
mom1 = momentum( mom0, 1)

if (mom0 > 0 and mom1 > 0)
    strategy.entry("MomLE", strategy.long, stop=high+syminfo.mintick, comment="MomLE")
else
    strategy.cancel("MomLE")

if (mom0 < 0 and mom1 < 0)
    strategy.entry("MomSE", strategy.short, stop=low-syminfo.mintick, comment="MomSE")
else
    strategy.cancel("MomSE")

//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)


//MACD Strategy
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)

MACD = ema(close, fastLength) - ema(close, slowlength)
aMACD = ema(MACD, MACDLength)
delta = MACD - aMACD

if (crossover(delta, 0))
    strategy.entry("MacdLE", strategy.long, comment="MacdLE")

if (crossunder(delta, 0))
    strategy.entry("MacdSE", strategy.short, comment="MacdSE")

//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)


//Harami

pctDw = input(60,minval=0,maxval=90,title="Doji, Min % of Range of Candle for Wicks")
pipMin= input(0,minval=0,title="Doji, Previous Candle Min Pip Body Size")
sname=input(true,title="Show Price Action Bar Names")
cbar = input(false,title="Highlight Harami & Doji Bars")
sHm    = input(false,title="Show Only Harami Style Doji's")
setalm = input(true, title="Generate Alert for Harami & Doji Bars")
uha   =input(true, title="Use Heikin Ashi Candles for Calculations")
bars = input(3,minval=1,maxval=3,step=1, title="Doji, Number of Lookback Bars")
//
// Use only Heikinashi Candles for all calculations
srcclose = uha ? security(heikinashi(syminfo.tickerid), timeframe.period, close) : close
srcopen = uha ? security(heikinashi(syminfo.tickerid), timeframe.period, open) : open
srchigh = uha ? security(heikinashi(syminfo.tickerid), timeframe.period, high) : high
srclow = uha ?security(heikinashi(syminfo.tickerid), timeframe.period, low) : low

//
pip = syminfo.mintick
range = srchigh - srclow


// Calculate Doji/Harami Candles
pctCDw = (pctDw/2) * 0.01
pctCDb = (100-pctDw) * 0.01

//Lookback Candles for bulls or bears
lbBull = bars==1? srcopen[1]>srcclose[1]: bars==2? (srcopen[1]>srcclose[1] and srcopen[2]>srcclose[2]): bars==3?(srcopen[1]>srcclose[1] and srcopen[2]>srcclose[2] and srcopen[3]>srcclose[3]):false
lbBear = bars==1? srcopen[1]<srcclose[1]: bars==2? (srcopen[1]<srcclose[1] and srcopen[2]<srcclose[2]): bars==3?(srcopen[1]<srcclose[1] and srcopen[2]<srcclose[2] and srcopen[3]<srcclose[3]):false

//Lookback Candle Size only if mininum size is > 0
lbSize = pipMin==0? true : bars==1 ? (abs(srcopen[1]-srcclose[1])>pipMin*pip) :
  bars==2 ? (abs(srcopen[1]-srcclose[1])>pipMin*pip and abs(srcopen[2]-srcclose[2])>pipMin*pip) :
  bars==3 ? (abs(srcopen[1]-srcclose[1])>pipMin*pip and abs(srcopen[2]-srcclose[2])>pipMin*pip and abs(srcopen[3]-srcclose[3])>pipMin*pip) :
  false

dojiBu = (srcopen[1] >= max(srcclose,srcopen) and srcclose[1]<=min(srcclose,srcopen)) and lbSize and
  (abs(srcclose-srcopen)<range*pctCDb and (srchigh-max(srcclose,srcopen))>(pctCDw*range) and (min(srcclose,srcopen)-srclow)>(pctCDw*range))? 1 : 0

dojiBe = (srcclose[1] >= max(srcclose,srcopen) and srcopen[1]<=min(srcclose,srcopen)) and lbSize and
  (abs(srcclose-srcopen)<range*pctCDb and (srchigh-max(srcclose,srcopen))>(pctCDw*range) and (min(srcclose,srcopen)-srclow)>(pctCDw*range))? 1 : 0
  
haramiBull = (srcopen<=srcclose or (max(srcclose,srcopen)-min(srcclose,srcopen))<pip*0.5) and lbBull and dojiBu
haramiBear = (srcopen>=srcclose or (max(srcclose,srcopen)-min(srcclose,srcopen))<pip*0.5) and lbBear and dojiBe

dojiBull = not sHm and not haramiBull and not haramiBear and lbBull and dojiBu
dojiBear = not sHm and not haramiBull and not haramiBear and lbBear and dojiBe

//
plotshape(haramiBear and sname?srchigh:na,title="Bearish Harami",text='Bearish\nHarami',color=red, style=shape.arrowdown,location=location.abovebar)
plotshape(haramiBear and cbar?max(srcopen,srcclose):na,title="Bear Colour Harami",color=red, style=shape.circle,location=location.absolute,size=size.normal)
//
plotshape(haramiBull and sname?srclow:na,title="Bullish Harami",text='Bullish\nHarami',color=green, style=shape.arrowup,location=location.belowbar)
plotshape(haramiBull and cbar?max(srcopen,srcclose):na,title="Bull Colour Harami",color=green, style=shape.circle,location=location.absolute,size=size.normal)
//
plotshape(dojiBear and sname?srchigh:na,title="Bearish Doji",text='Bearish\nDoji',color=fuchsia, style=shape.arrowdown,location=location.abovebar)
plotshape(dojiBear and cbar?max(srcopen,srcclose):na,title="Bear Colour Doji",color=fuchsia, style=shape.circle,location=location.absolute,size=size.normal)
//
plotshape(dojiBull and sname?srclow:na,title="Bullish Doji",text='Bullish\nDoji',color=aqua, style=shape.arrowup,location=location.belowbar)
plotshape(dojiBull and cbar?max(srcopen,srcclose):na,title="Bull Colour Doji",color=aqua, style=shape.circle,location=location.absolute,size=size.normal)

// Only Alert harami Doji's
bcolor = haramiBull ? 1 : haramiBear ? 2 : dojiBull ? 3 : dojiBear ? 4 : 0
baralert = setalm and bcolor>0
alertcondition(baralert,title="PACDOJI Alert",message="PACDOJI Alert")

//
plotshape(na(baralert[1])?na:baralert[1], transp=0,style=shape.circle,location=location.bottom, offset=-1,title="Bar Alert Confirmed", 
  color=bcolor[1]==1 ? green : bcolor[1]==2? red : bcolor[1]==3? aqua : bcolor[1]==4? fuchsia : na)

//EOF