Chiến lược giao dịch dựa trên các vùng cung và cầu với EMA và Trailing Stop

Tác giả:ChaoZhang, Ngày: 2024-01-18 16:41:16
Tags:

img

Tổng quan

Chiến lược sử dụng các vùng cung và cầu, Trung bình Di chuyển Triệt để (EMA) và Trung bình True Range (ATR) để dừng lại cho các tín hiệu giao dịch. Người dùng có thể điều chỉnh cài đặt EMA và khả năng hiển thị tín hiệu. Chiến lược đánh dấu các vùng cao hơn (HH), thấp hơn (LL), thấp hơn (LH) và thấp hơn (HL).

Chiến lược logic

Tính toán chỉ số

Đường trung bình chuyển động theo cấp số (EMA):

  • EMA được tính từ giá đóng trong một khoảng thời gian (bên mặc định: 200).
  • Công thức: EMA = (Price_t x α) + (EMA_t-1 x (1 - α)), trong đó α = 2/(dài + 1)

Phạm vi thực trung bình (ATR):

  • ATR đo biến động thị trường từ phạm vi giá thực sự.
  • Phạm vi thực sự là lớn nhất trong số:
    • Điện cao trừ điện thấp
    • Giá trị tuyệt đối của mức cao hiện tại trừ giá đóng trước
    • Giá trị tuyệt đối của mức thấp hiện tại trừ đi mức đóng trước đó
  • ATR thường sử dụng 14 giai đoạn.

Được sử dụng để xác định EMA cho xu hướng và ATR cho dừng theo sau dựa trên biến động.

Xác định vùng cung và cầu

Nó xác định các mô hình HH (Tăng cao hơn), LL (Dưới thấp hơn), HL (Tăng thấp hơn) và LH (Dưới cao hơn):

  1. cao hơn cao hơn (HH): đỉnh hiện tại > đỉnh trước, động lực tăng lên.

  2. Hạ Hạ (LL): Đường đáy hiện tại < đường đáy trước, động lực giảm.

  3. Cao thấp (HL): Đường đáy hiện tại > Đường đáy trước, tiếp tục tăng lên.

  4. Tăng thấp hơn (LH): đỉnh hiện tại < đỉnh trước, tiếp tục giảm.

Được sử dụng với xu hướng để xác định sự đảo ngược hoặc tiếp tục.

Nhập và ra

Tín hiệu nhập cảnh: Mua/bán trên nến thứ ba đóng cửa trên/dưới mức cao/ thấp trước đó.

Đi ra: Stop loss theo dõi dựa trên ATR.

Ưu điểm

  1. Kết hợp xu hướng, đảo ngược, biến động cho tín hiệu mạnh mẽ.
  2. Các vùng cung/nhu cầu xác định các S/R chính.
  3. Dinamic ATR dừng điều chỉnh để biến động.
  4. Các thông số có thể tùy chỉnh.
  5. Quy tắc đơn giản.

Rủi ro và cải tiến

  1. tín hiệu sai: tối ưu hóa chiều dài EMA.
  2. Tỷ lệ ATR tăng cao có nguy cơ theo đuổi xu hướng.
  3. Hãy xem xét các bộ lọc bổ sung trên các mục.
  4. Kiểm tra cách tiếp cận tập trung vào xu hướng.

Kết luận

Kết hợp nhiều kỹ thuật để backtests tốt. thế giới thực là phức tạp, tối ưu hóa là chìa khóa. chiến lược cơ bản cho phép mở rộng và kết hợp.


/*backtest
start: 2023-12-18 00:00:00
end: 2024-01-17 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Supply and Demand Zones with EMA and Trailing Stop", shorttitle="SD Zones", overlay=true)

showBuySignals = input(true, title="Show Buy Signals", group="Signals")
showSellSignals = input(true, title="Show Sell Signals", group="Signals")
showHLZone = input(true, title="Show HL Zone", group="Zones")
showLHZone = input(true, title="Show LH Zone", group="Zones")
showHHZone = input(true, title="Show HH Zone", group="Zones")
showLLZone = input(true, title="Show LL Zone", group="Zones")

emaLength = input(200, title="EMA Length", group="EMA Settings")
atrLength = input(14, title="ATR Length", group="Trailing Stop")
atrMultiplier = input(2, title="ATR Multiplier", group="Trailing Stop")

// Function to identify supply and demand zones
getZones(src, len, mult) =>
    base = request.security(syminfo.tickerid, "D", close)
    upper = request.security(syminfo.tickerid, "D", high)
    lower = request.security(syminfo.tickerid, "D", low)
    multiplier = request.security(syminfo.tickerid, "D", mult)
    zonetype = base + multiplier * len
    zone = src >= zonetype
    [zone, upper, lower]

// Identify supply and demand zones
[supplyZone, _, _] = getZones(close, high[1] - low[1], 1)
[demandZone, _, _] = getZones(close, high[1] - low[1], -1)

// Plot supply and demand zones
bgcolor(supplyZone ? color.new(color.red, 80) : na)
bgcolor(demandZone ? color.new(color.green, 80) : na)

// EMA with Linear Weighted method
ema = ta.ema(close, emaLength)

// Color code EMA based on its relation to candles
emaColor = close > ema ? color.new(color.green, 0) : close < ema ? color.new(color.red, 0) : color.new(color.yellow, 0)

// Plot EMA
plot(ema, color=emaColor, title="EMA")

// Entry Signal Conditions after the third candle
longCondition = ta.crossover(close, high[1]) and bar_index >= 2
shortCondition = ta.crossunder(close, low[1]) and bar_index >= 2

// Trailing Stop using ATR
atrValue = ta.atr(atrLength)
trailStop = close - atrMultiplier * atrValue

// Strategy Entry and Exit
if (longCondition)
    strategy.entry("Buy", strategy.long)
    strategy.exit("TrailStop", from_entry="Buy", loss=trailStop)

if (shortCondition)
    strategy.entry("Sell", strategy.short)
    strategy.exit("TrailStop", from_entry="Sell", loss=trailStop)

// Plot Entry Signals
plotshape(series=showBuySignals ? longCondition : na, title="Buy Signal", color=color.new(color.green, 0), style=shape.triangleup, location=location.belowbar)
plotshape(series=showSellSignals ? shortCondition : na, title="Sell Signal", color=color.new(color.red, 0), style=shape.triangledown, location=location.abovebar)

// Plot Trailing Stop
plot(trailStop, color=color.new(color.red, 0), title="Trailing Stop")

// Plot HH, LL, LH, and HL zones
plotshape(series=showHHZone and ta.highest(high, 2)[1] and ta.highest(high, 2)[2] ? 1 : na, title="HH Zone", color=color.new(color.blue, 80), style=shape.triangleup, location=location.abovebar)
plotshape(series=showLLZone and ta.lowest(low, 2)[1] and ta.lowest(low, 2)[2] ? 1 : na, title="LL Zone", color=color.new(color.blue, 80), style=shape.triangledown, location=location.belowbar)
plotshape(series=showLHZone and ta.highest(high, 2)[1] and ta.lowest(low, 2)[2] ? 1 : na, title="LH Zone", color=color.new(color.orange, 80), style=shape.triangleup, location=location.abovebar)
plotshape(series=showHLZone and ta.lowest(low, 2)[1] and ta.highest(high, 2)[2] ? 1 : na, title="HL Zone", color=color.new(color.orange, 80), style=shape.triangledown, location=location.belowbar)


Thêm nữa