Chiến lược xu hướng hấp thụ năng động

Tác giả:ChaoZhang, Ngày: 2024-02-29 11:24:18
Tags:

img

Tổng quan

Chiến lược xu hướng ngập động là một chiến lược giao dịch có vị trí dài hoặc ngắn dựa trên các mô hình ngập theo hướng xu hướng. Chiến lược này sử dụng phạm vi trung bình thực sự (ATR) để đo lường biến động thị trường, chỉ số siêu xu hướng để xác định hướng xu hướng thị trường và tham gia giao dịch khi các mô hình ngập phù hợp với hướng xu hướng.

Chiến lược logic

  1. Tính toán ATR để đo biến động thị trường.
  2. Tính toán chỉ số Supertrend để xác định xu hướng thị trường.
  3. Xác định các điều kiện cho xu hướng tăng và giảm.
  4. Xác định sự hấp thụ tăng (trend tăng) và hấp thụ giảm (trend giảm).
  5. Tính toán mức Stop Loss (SL) và Take Profit (TP) dựa trên các mô hình ngập.
  6. Nhập giao dịch khi các mô hình ngập phù hợp với hướng xu hướng.
  7. Các giao dịch thoát khi giá đạt mức SL hoặc TP.
  8. Chụp các mô hình ngập trên biểu đồ.

Phân tích lợi thế

Những lợi thế của chiến lược này bao gồm:

  1. Tăng chất lượng tín hiệu bằng cách kết hợp các mô hình ngập với xu hướng.
  2. Khả năng xác định sự đảo ngược xu hướng cho các mục chính xác.
  3. Rõ ràng tín hiệu dài / ngắn cho thời gian tốt hơn.
  4. Chiến lược ngăn chặn ngập theo xu hướng trong khi quản lý rủi ro.
  5. Khung mã mô-đun để tối ưu hóa dễ dàng.

Phân tích rủi ro

Ngoài ra còn có một số rủi ro cần xem xét:

  1. Các mô hình ngập có thể trở thành sự thoát hiểm giả.
  2. Khó xác định các thông số tối ưu như kích thước mẫu, thời gian vv.
  3. Việc xác định xu hướng không hoàn hảo có thể dẫn đến các tín hiệu sai.
  4. Mức dừng lỗ và mức lợi nhuận dựa trên quyết định và có thể chủ quan.
  5. Hiệu suất phụ thuộc vào điều chỉnh tham số dựa trên dữ liệu lịch sử.

Các rủi ro có thể được giảm thiểu bằng cách:

  1. Thêm bộ lọc để loại bỏ tín hiệu thoát hiểm sai.
  2. Sử dụng ATR thích nghi để tính toán các tham số mạnh mẽ.
  3. Cải thiện xác định xu hướng bằng cách sử dụng máy học.
  4. Tìm các thông số tối ưu thông qua các thuật toán di truyền.
  5. Kiểm tra lại trong thời gian dài hơn để đảm bảo độ bền.

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

Có phạm vi tối ưu hóa hơn nữa:

  1. Học máy có thể cải thiện việc xác định xu hướng.
  2. Các phương pháp nhận dạng mô hình mới có thể xác định tốt hơn các mô hình nuốt.
  3. Chiến lược dừng lỗ / lấy lợi nhuận mới nhất có thể tối ưu hóa mức năng động.
  4. Dữ liệu tần số cao có thể phát triển hệ thống ngắn hạn.
  5. Điều chỉnh tham số cho các nhạc cụ khác nhau.

Kết luận

Tóm lại, chiến lược xu hướng ngập động kết hợp các tín hiệu mô hình ngập chất lượng cao với xác định xu hướng chính xác để tạo ra một hệ thống giao dịch có mục nhập chính xác và lỗ dừng hợp lý và thu lợi nhuận.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
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/
// © Malikdrajat


//@version=4
strategy("Engulfing with Trend", overlay=true)

Periods = input(title="ATR Period", type=input.integer, defval=10)
src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)

atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2

up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn

trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend

upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
changeCond = trend != trend[1]
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")

// Define Downtrend and Uptrend conditions
downtrend = trend == -1
uptrend = trend == 1


// Engulfing 
boringThreshold = input(25, title="Boring Candle Threshold (%)", minval=1, maxval=100, step=1)
engulfingThreshold = input(50, title="Engulfing Candle Threshold (%)", minval=1, maxval=100, step=1)
stopLevel = input(200, title="Stop Level (Pips)", minval=1)


// Boring Candle (Inside Bar) and Engulfing Candlestick Conditions
isBoringCandle = abs(open[1] - close[1]) * 100 / abs(high[1] - low[1]) <= boringThreshold
isEngulfingCandle = abs(open - close) * 100 / abs(high - low) <= engulfingThreshold

// Bullish and Bearish Engulfing Conditions
bullEngulfing = uptrend and close[1] < open[1] and close > open[1] and not isBoringCandle and not isEngulfingCandle
bearEngulfing = downtrend and close[1] > open[1] and close < open[1] and not isBoringCandle and not isEngulfingCandle

// Stop Loss, Take Profit, and Entry Price Calculation
bullStop = close + (stopLevel * syminfo.mintick)
bearStop = close - (stopLevel * syminfo.mintick)
bullSL = low 
bearSL = high
bullTP = bullStop + (bullStop - low)
bearTP = bearStop - (high - bearStop)

// Entry Conditions
enterLong = bullEngulfing and uptrend
enterShort = bearEngulfing and downtrend

// Exit Conditions
exitLong = crossover(close, bullTP) or crossover(close, bullSL)
exitShort = crossover(close, bearTP) or crossover(close, bearSL)

// Check if exit conditions are met by the next candle
exitLongNextCandle = exitLong and (crossover(close[1], bullTP[1]) or crossover(close[1], bullSL[1]))
exitShortNextCandle = exitShort and (crossover(close[1], bearTP[1]) or crossover(close[1], bearSL[1]))

// Strategy Execution
strategy.entry("Buy", strategy.long, when=enterLong )
strategy.entry("Sell", strategy.short, when=enterShort )

// Exit Conditions for Long (Buy) Positions
if (bullEngulfing and not na(bullTP) and not na(bullSL))
    strategy.exit("Exit Long", from_entry="Buy", stop=bullSL, limit=bullTP)

// Exit Conditions for Short (Sell) Positions
if (bearEngulfing and not na(bearTP) and not na(bearSL))
    strategy.exit("Exit Short", from_entry="Sell", stop=bearSL, limit=bearTP)

// Plot Shapes and Labels
plotshape(bullEngulfing, style=shape.triangleup, location=location.abovebar, color=color.green)
plotshape(bearEngulfing, style=shape.triangledown, location=location.abovebar, color=color.red)

// Determine OP, SL, and TP
plot(bullEngulfing ? bullStop : na, title="Bullish Engulfing stop", color=color.red, linewidth=3, style=plot.style_linebr)
plot(bearEngulfing ? bearStop : na, title="Bearish Engulfing stop", color=color.red, linewidth=3, style=plot.style_linebr)
plot(bullEngulfing ? bullSL : na, title="Bullish Engulfing SL", color=color.red, linewidth=3, style=plot.style_linebr)
plot(bearEngulfing ? bearSL : na, title="Bearish Engulfing SL", color=color.red, linewidth=3, style=plot.style_linebr)
plot(bullEngulfing ? bullTP : na, title="Bullish Engulfing TP", color=color.green, linewidth=3, style=plot.style_linebr)
plot(bearEngulfing ? bearTP : na, title="Bearish Engulfing TP", color=color.green, linewidth=3, style=plot.style_linebr)



Thêm nữa