Chiến lược kết hợp các chỉ số theo dõi xu hướng đột phá

Tác giả:ChaoZhang, Ngày: 2024-02-20 11:38:22
Tags:

img

Tổng quan

Chiến lược này được đặt tên là Strategy of Indicators Combination Breakthrough Trend Tracking. Nó kết hợp các chỉ số khác nhau để xác định hướng xu hướng thị trường và thực hiện các hoạt động theo dõi xu hướng. Các thành phần chính bao gồm:

  1. Sử dụng chỉ số xu hướng sóng để đánh giá xu hướng chính của thị trường
  2. Xử lý một số tín hiệu sai bằng các chỉ số RSI và MFI
  3. Định hướng hoạt động cụ thể với chỉ số EMA
  4. Tham gia thị trường với phương pháp theo dõi đột phá để đảm bảo theo xu hướng

Nguyên tắc chiến lược

Chiến lược chủ yếu đánh giá hướng và sức mạnh của xu hướng chính, và đặt giao dịch hai chiều dài và ngắn.

Tín hiệu dài:

  1. Giá trên đường EMA 200 ngày, cho thấy thị trường tăng
  2. Giá rút lại khoảng đường EMA 50 ngày tạo thành hỗ trợ
  3. Xu hướng sóng đảo ngược sang xu hướng tăng và tín hiệu mua xuất hiện
  4. Cả RSI và MFI đều cho thấy mua quá mức
  5. 3 đường K liên tiếp vượt qua đường EMA 50 ngày liên tiếp, cho thấy sự đột phá lên

Tín hiệu ngắn: Ngược lại với tín hiệu dài

Lợi nhuận và dừng lỗ: Hai tùy chọn được cung cấp: giá thấp nhất/giá cao nhất dừng lỗ, ATR dừng lỗ

Phân tích lợi thế

Chiến lược có những lợi thế sau:

  1. Tích hợp nhiều chỉ số để xác định xu hướng chính và tránh sự đột phá sai
  2. Ước dụng EMA để xác định hướng hoạt động, dễ dàng theo dõi xu hướng
  3. Phương pháp dừng lỗ kéo dài đạt được lợi nhuận bền vững
  4. Có khả năng đi cả dài và ngắn, theo thị trường theo bất kỳ hướng nào

Phân tích rủi ro

Chiến lược này cũng có một số rủi ro:

  1. Khả năng tín hiệu sai từ các chỉ số
  2. Đặt điểm dừng lỗ quá nhỏ, làm tăng rủi ro dừng lỗ
  3. Tần suất giao dịch cao dẫn đến tổn thất ẩn từ phí giao dịch

Để giảm các rủi ro trên, tối ưu hóa có thể được thực hiện trong các khía cạnh sau:

  1. Điều chỉnh các thông số chỉ báo để lọc tín hiệu sai
  2. Nới lỏng đúng điểm dừng mất mát
  3. Tối ưu hóa các thông số chỉ số để giảm tần suất giao dịch

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

Từ cấp mã, các hướng tối ưu hóa chính của chiến lược này bao gồm:

  1. Điều chỉnh các tham số của xu hướng sóng, RSI và MFI để tìm ra sự kết hợp tốt nhất của các tham số
  2. Kiểm tra hiệu suất của các thông số chu kỳ EMA khác nhau
  3. Điều chỉnh các yếu tố tỷ lệ rủi ro-lợi nhuận của việc lấy lợi nhuận và dừng lỗ để có được cấu hình tối ưu

Thông qua điều chỉnh tham số và thử nghiệm, chiến lược có thể tối đa hóa lợi nhuận trong khi giảm giảm và rủi ro.

Kết luận

Chiến lược này tích hợp nhiều chỉ số để xác định hướng xu hướng chính, sử dụng chỉ số EMA như một tín hiệu hoạt động cụ thể và sử dụng stop loss để khóa lợi nhuận. Thông qua tối ưu hóa tham số, có thể đạt được lợi nhuận tương đối tốt ổn định. Nhưng cũng cần lưu ý các rủi ro hệ thống nhất định, hiệu quả của các chỉ số và những thay đổi trong môi trường thị trường cần phải được theo dõi liên tục.


/*backtest
start: 2023-02-13 00:00:00
end: 2024-02-19 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
//Lowest Low/ Highest High & ATR Stop Loss/ Take Profit
//Optimized for the 30 minutes chart

strategy(title="TradePro's Trading Idea Cipher B+ Divergence EMA Pullback Strategy", shorttitle="WT MFI RSI EMA PB STRAT", overlay = true, pyramiding = 0, max_bars_back=5000, calc_on_order_fills = false, commission_type =  strategy.commission.percent, commission_value = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital=5000, currency=currency.USD)

// { Time Range
FromMonth=input(defval=1,title="FromMonth",minval=1,maxval=12)
FromDay=input(defval=1,title="FromDay",minval=1,maxval=31)
FromYear=input(defval=2020,title="FromYear",minval=2016)
ToMonth=input(defval=1,title="ToMonth",minval=1,maxval=12)
ToDay=input(defval=1,title="ToDay",minval=1,maxval=31)
ToYear=input(defval=9999,title="ToYear",minval=2017)
start=timestamp(FromYear,FromMonth,FromDay,00,00)
finish=timestamp(ToYear,ToMonth,ToDay,23,59)
window()=>true

// See if this bar's time happened on/after start date
afterStartDate = time >= start and time<=finish?true:false

zeroline = 0

// } Time Range

// { Wavetrend, RSI, MFI

// WaveTrend
cl = input(12, "Channel Length")
al = input(12, "Average Length")
overbought = input(53, title = 'WT Overbought Level 1', type = input.integer)
oversold = input(-53, title = 'WT Oversold Level 1', type = input.integer)
ap = hlc3 
esa = ema(ap, cl)
d = ema(abs(ap - esa), cl)
ci = (ap - esa) / (0.015 * d)
tci = ema(ci, al)
 
wt1 = tci
wt2 = sma(wt1,4)

wtOs = wt2 <= oversold
wtOb = wt2 >= overbought
wtX = cross(wt1, wt2)
wtUp = wt2 - wt1 <= 0
wtDown = wt2 - wt1 >= 0
buySignal = wtX and wtOs and wtUp
sellSignal = wtX and wtOb and wtDown

// RSI & MFI

rsiMFIPosY = input(2, title = 'MFI Area Y Pos', type = input.float)
rsiMFIperiod = input(80,title = 'MFI Period', type = input.integer)
rsiMFIMultiplier = input(200, title = 'MFI Area multiplier', type = input.float)
f_rsimfi(_period, _multiplier, _tf) => security(syminfo.tickerid, _tf, sma(((close - open) / (high - low)) * _multiplier, _period) - rsiMFIPosY)
rsiMFI = f_rsimfi(rsiMFIperiod, rsiMFIMultiplier, timeframe.period)

// } Wavetrend, RSI, MFI

// { EMA
emasrc = close
res = input(title="EMA Timeframe", type=input.resolution, defval="30")
len1 = input(title="EMA1 Length", type=input.integer, defval=200)
col1 = color.yellow

len2 = input(title="EMA2 Length", type=input.integer, defval=50)
col2 = color.blue

// Calculate EMA
ema1 = ema(emasrc, len1)
emaSmooth1 = security(syminfo.tickerid, res, ema1, barmerge.gaps_off, barmerge.lookahead_off)

ema2 = ema(emasrc, len2)
emaSmooth2 = security(syminfo.tickerid, res, ema2, barmerge.gaps_off, barmerge.lookahead_off)

// Draw EMA
plot(emaSmooth1, title="EMA1", linewidth=1, color=col1)
plot(emaSmooth2, title="EMA2", linewidth=1, color=col2)

// } EMA

// { Long Entry

enablelong = input(true, title="Enable long?")

//Long Signal
upcondition = close > emaSmooth1
wavetrendlong = wt1 and wt2 < zeroline
mfilong = rsiMFI > 0
emapblong1 = (close > emaSmooth2) and (close[1] < emaSmooth2[1])
emapblong2 = ((close[2] > emaSmooth2[2]) and (close[3] > emaSmooth2[3]) and (close[4] > emaSmooth2[4])) or ((close[5] > emaSmooth2[5]) and (close[6] > emaSmooth2[6]) and (close[7] > emaSmooth2[7])) or ((close[8] > emaSmooth2[8]) and (close[9] > emaSmooth2[9]) and (close[10] > emaSmooth2[10]))

longcondition = upcondition and wavetrendlong and buySignal and mfilong and emapblong1 and emapblong2

//strategy buy long
if (longcondition) and (afterStartDate) and strategy.opentrades < 1 and (enablelong == true)
    strategy.entry("long", strategy.long)

plotshape(longcondition, style=shape.arrowup,
                 location=location.abovebar, color=color.green)

// } Long Entry

// { Short Entry

enableshort = input(true, title="Enable short?")

//Short Signal
downcondition = close < emaSmooth1
wavetrendshort = wt1 and wt2 > zeroline
mfishort = rsiMFI < 0
emapbshort1 = (close < emaSmooth2) and (close[1] > emaSmooth2[1])
emapbshort2 = ((close[2] < emaSmooth2[2]) and (close[3] < emaSmooth2[3]) and (close[4] < emaSmooth2[4])) or ((close[5] < emaSmooth2[5]) and (close[6] < emaSmooth2[6]) and (close[7] < emaSmooth2[7])) or ((close[8] < emaSmooth2[8]) and (close[9] < emaSmooth2[9]) and (close[10] < emaSmooth2[10]))

shortcondition = downcondition and wavetrendshort and sellSignal and mfishort and emapbshort1 and emapbshort2

//strategy buy short
if (shortcondition) and (afterStartDate) and strategy.opentrades < 1 and (enableshort == true)
    strategy.entry("short", strategy.short)

plotshape(shortcondition, style=shape.arrowdown,
                 location=location.belowbar, color=color.red)

// } Short Entry

// { Exit Conditions
bought = strategy.position_size[1] < strategy.position_size
sold = strategy.position_size[1] > strategy.position_size
barsbought = barssince(bought)
barssold = barssince(sold)
slbuffer = input(title="SL Buffer", type=input.float, step=0.1, defval=0)

// } Exit Conditions

// { Lowest Low/ Highes High Exit Condition
enablelowhigh = input(false, title="Enable lowest low/ highest high exit?")

//Lowest Low LONG
profitfactorlong = input(title="ProfitfactorLong", type=input.float, step=0.1, defval=2)
loLen = input(title="Lowest Low Lookback", type=input.integer,
  defval=50, minval=2)
stop_level_long = lowest(low, loLen)[1]

if enablelowhigh == true and strategy.position_size>0
    profit_level_long = strategy.position_avg_price + ((strategy.position_avg_price - stop_level_long[barsbought])*profitfactorlong) + slbuffer
    strategy.exit(id="TP/ SL", stop=stop_level_long[barsbought] - slbuffer, limit=profit_level_long)

//Lowest Low SHORT
profitfactorshort = input(title="ProfitfactorShort", type=input.float, step=0.1, defval=2)
highLen = input(title="highest high lookback", type=input.integer,
  defval=50, minval=2)
stop_level_short = highest(high, highLen)[1]

if enablelowhigh == true and strategy.position_size<0
    profit_level_short = strategy.position_avg_price - ((stop_level_short[barssold] - strategy.position_avg_price)*profitfactorshort) - slbuffer
    strategy.exit(id="TP/ SL", stop=stop_level_short[barssold] + slbuffer, limit=profit_level_short)

// } Lowest Low/ Highes High Exit Condition

// { ATR Take Profit/ Stop Loss
enableatr = input(true, title="Enable ATR exit?")
atrprofitfactorlong = input(title="ATR Profitfactor Long", type=input.float, step=0.1, defval=6)
atrstopfactorlong = input(title="ATR Stopfactor Long", type=input.float, step=0.1, defval=5)
atrprofitfactorshort = input(title="ATR Profitfactor Short", type=input.float, step=0.1, defval=3)
atrstopfactorshort = input(title="ATR Stopfactor Short", type=input.float, step=0.1, defval=5)

//ATR
lengthATR = input(title="ATR Length", defval=11, minval=1)
atr = atr(lengthATR)

//LONG EXIT
if (afterStartDate) and ((enableatr == true) and (strategy.opentrades > 0))
    barsbought1 = barssince(bought)
    profit_level = strategy.position_avg_price + (atr*atrprofitfactorlong)
    stop_level = strategy.position_avg_price - (atr*atrstopfactorlong)
    strategy.exit("Take Profit/ Stop Loss", "long", stop=stop_level[barsbought1], limit=profit_level[barsbought1])

//SHORT EXIT
if (afterStartDate) and ((enableatr == true) and (strategy.opentrades > 0))
    barssold1 = barssince(sold)
    profit_level = strategy.position_avg_price - (atr*atrprofitfactorshort)
    stop_level = strategy.position_avg_price + (atr*atrstopfactorshort)
    strategy.exit("Take Profit/ Stop Loss", "short", stop=stop_level[barssold1], limit=profit_level[barssold1])

// } ATR Take Profit/ Stop Loss

Thêm nữa