Chuyển chiến lược chuyển tiếp kênh Vegas

Tác giả:ChaoZhang, Ngày: 2024-01-02 10:53:06
Tags:

img

Ý tưởng cốt lõi của chiến lược này là xác định hướng xu hướng ngắn hạn, trung hạn và dài hạn của cổ phiếu dựa trên EMA với các chu kỳ khác nhau như 36, 143, 169, kết hợp với chỉ số MACD để phát hành tín hiệu mua và bán. Cụ thể, trong ngắn hạn, EMA 5 và 10 ngày được sử dụng để đánh giá, trong trung hạn, EMA 20 và 60 ngày được sử dụng để đánh giá, trong dài hạn, EMA 120 và 250 ngày được sử dụng để đánh giá, khi EMA ngắn hạn vượt qua EMA trung hạn lên, nó tăng, nếu không nó giảm; Chỉ số MACD của tín hiệu tăng và giảm được sử dụng để xác định thời gian mua và bán.

Cơ chế cụ thể của chiến lược đường hầm Vegas:

  1. Sử dụng EMA 36 và EMA 43 để hình thành đánh giá xu hướng ngắn hạn, chúng tạo thành kênh đỏ;
  2. Sử dụng EMA 144 và EMA 169 để hình thành đánh giá xu hướng trung hạn, chúng tạo thành kênh xanh;
  3. Sử dụng EMA576 và EMA676 để hình thành đánh giá xu hướng dài hạn, chúng tạo thành kênh màu xám;
  4. Khi giá đứng trên đường EMA trên, đi dài, kết hợp với chỉ số MACD phá vỡ qua trục 0 lên như tín hiệu mua;
  5. Khi giá phá vỡ dưới đường EMA trên, đi ngắn, kết hợp với chỉ số MACD phá vỡ qua trục 0 xuống như tín hiệu bán;
  6. Theo sự đột phá của dòng EMA, ba chiến lược được xác định, tương ứng ngắn hạn, trung bình và dài hạn, tương ứng với thời gian nắm giữ khác nhau.

Ưu điểm của chiến lược này:

  1. Kết hợp ba kênh ngắn, trung bình và dài để đánh giá hướng xu hướng, tương đối ổn định;
  2. Đường hầm Vegas rất trực quan để xác định xu hướng;
  3. MACD giúp nắm bắt thời gian mua và bán tốt hơn;
  4. Được chia thành ba chiến lược ngắn hạn, trung bình và dài hạn để hoạt động linh hoạt hơn.

Rủi ro lớn:

  1. Khi giá dao động mạnh, đường EMA chậm, có khả năng đưa ra những phán đoán sai lầm;
  2. Khi ba kênh hiển thị tín hiệu không nhất quán, có nguy cơ hoạt động sai;
  3. Hoạt động biểu đồ phút cần sức chịu đựng tâm lý mạnh mẽ hơn.

Phương pháp đối phó:

  1. Điều chỉnh chu kỳ EMA để phù hợp hơn với các đặc điểm thị trường hiện tại;
  2. Điều chỉnh kích thước vị trí trước để hạn chế lỗ đơn.

Không gian tối ưu hóa:

  1. Các đường hầm Vegas khả năng đánh giá xu hướng cần được cải thiện, các dải Bollinger có thể được thêm vào;
  2. MACD hoạt động kém cho các thị trường bên, các chỉ số như KD và RSI có thể là lựa chọn tốt hơn;
  3. Thêm các chính sách dừng lỗ, chẳng hạn như dừng lỗ khi giá đóng phá vỡ các đường EMA chính;
  4. ETF ngắn để phòng ngừa rủi ro với giới hạn và giảm cổ phiếu có tác động lớn hơn.

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

//@version=4

strategy("Vegas Tunnel strategy", overlay=true)
//-------------------------------------------
//-------------------------------------------
// Inputs
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=input.resolution, defval="D")
//tfSet = input(title = "Time Frame", options=["Current","120", "240", "D", "W"], defval="D")
tfSet = useCurrentRes ? timeframe.period : resCustom
maPeriods2 = input(12, "12 EMA")
maPeriods6 = input(240, "240 SMA")
BBlength = input(20, title="BB Length", minval=1)
BBsrc = input(close, title="BB Source")
mult = input(2.0, minval=0.001, maxval=50, title="BB StdDev")
sm2 = security(syminfo.tickerid, tfSet, ema(close, maPeriods2))
sm6 = security(syminfo.tickerid, tfSet, sma(close, maPeriods6))
p2 = plot(sm2, color=color.green, transp=30,  linewidth=2, title="SMA2")
p6 = plot(sm6, color=color.white, transp=30,  linewidth=2, title="SMA6")
//BB
basis = sma(BBsrc, BBlength)
dev = mult * stdev(BBsrc, BBlength)
upper = basis + dev
lower = basis - dev
offset = input(0, "BB Offset", type = input.integer, minval = -500, maxval = 500)
//plot(basis, "Basis", color=color.blue,linewidth, offset = offset)
pBB1 = plot(upper, "Upper", color=color.blue, offset = offset)
pBB2= plot(lower, "Lower", color=color.blue, offset = offset)

//MACD
fast_ma = ema(close, 48)
slow_ma = ema(close, 56)
macd = fast_ma - slow_ma

//vagas隧道
f1=ema(close, 36)
f2=ema(close, 43)
f3=ema(close, 144)
f4=ema(close, 169)
f5=ema(close, 576)
f6=ema(close, 676)
f7=ema(close,2304)
z1=plot(f1,color=color.red, title="ema36",transp=100)
z2=plot(f2,color=color.red, title="ema43",transp=100)
z3=plot(f3,color=color.green, title="ema144",transp=100)
z4=plot(f4,color=color.green, title="ema169",transp=100)
z5=plot(f5,color=color.white, title="ema576",transp=100)
z6=plot(f6,color=color.white, title="ema676",transp=100)
fill(z1, z2, color=color.red,transp=60)
fill(z3, z4, color=color.green,transp=60)
fill(z5, z6, color=color.gray,transp=60)

// Make input options that configure backtest date range
startDate = input(title="Start Date", type=input.integer,
     defval=1, minval=1, maxval=31)
startMonth = input(title="Start Month", type=input.integer,
     defval=1, minval=1, maxval=12)
startYear = input(title="Start Year", type=input.integer,
     defval=2018, minval=1800, maxval=2100)
endDate = input(title="End Date", type=input.integer,
     defval=1, minval=1, maxval=31)
endMonth = input(title="End Month", type=input.integer,
     defval=11, minval=1, maxval=12)
endYear = input(title="End Year", type=input.integer,
     defval=2030, minval=1800, maxval=2100)
// Look if the close time of the current bar
// falls inside the date range
inDateRange =  true

//波段多
if (inDateRange and crossunder(f3,f1))// 
    strategy.entry("buy", strategy.long,1, when=macd>0, comment = "買Long-term")
buyclose=crossunder(f3,f5) 
strategy.close("buy", when = buyclose, comment = "關Long-term")
//多策略1
if (inDateRange and crossover(low , f3) and macd>0 and f3>f6)
    strategy.entry("buy1", strategy.long,100, comment = "買Mid-term")
buyclose1=crossunder(close,upper*0.999) 
if (macd<0 or f3<f6)
    strategy.close("buy1", comment = "關Mid-term")
//strategy.close("buy1",when=cross(basis,close), comment = "關M",qty_percent=50)
strategy.close("buy1", when = buyclose1, comment = "關Mid-term",qty_percent=100)
//多策略3
if (inDateRange and  (macd>0) and crossunder(low,f1) and f1>f4) // 
    strategy.entry("buy3", strategy.long,1, comment = "買Short-term")
buyclose3=crossunder(close,upper*0.999)
if (macd<0 or f1<f4)
    strategy.close("buy3", comment = "關Short-term")
strategy.close("buy3", when = buyclose3, comment = "關Short-term")
//多策略4
if (inDateRange and  (macd>0) and crossunder(low,f5) and f4>f5) // 
    strategy.entry("buy4", strategy.long,1, comment = "買Long-term")
buyclose4=crossunder(close,upper*0.999)
if (macd<0 or f4<f6)
    strategy.close("buy4", comment = "關Long-term")
strategy.close("buy4", when = buyclose4, comment = "關Long-term")
    
//空策略1
if (inDateRange and  (macd<0) and crossunder(high,f1) and f1<f3 and f3<f6) // 
    strategy.entry("sell1", strategy.short,1, comment = "空Short-term")
sellclose1=crossunder(lower*0.999,close)
if (macd>0 or f1>f4)
    strategy.close("sell1", comment = "關空Short-term")
strategy.close("sell1", when = sellclose1, comment = "關空Short-term")
//空策略2
if (inDateRange and  (macd<0) and crossunder(high,f4) and f4<f6) // 
    strategy.entry("sell2", strategy.short,1, comment = "空Mid-term")
sellclose2=crossunder(lower,close)
if (macd>0 or f4>f6)
    strategy.close("sell2", comment = "關空Mid-term")
strategy.close("sell2", when = sellclose2, comment = "關Mid-term")
//空策略3
if (inDateRange and (macd<0) and crossunder(high,f6)) // 
    strategy.entry("sell3", strategy.short,1, comment = "空Long-term")
sellclose3=crossunder(lower,close)
if (macd>0 or f6>f7)
    strategy.close("sell3", comment = "關空Long-term")
strategy.close("sell3", when = sellclose3, comment = "關空Long-term")

Thêm nữa