
Không còn mê tín chỉ số duy nhất nữa. Chiến lược này kết hợp hoàn hảo ba chiều của quét lưu lượng, giao thông bất thường, xu hướng EMA, 11 chu kỳ dao động để xác định kháng cự hỗ trợ quan trọng, 31 chu kỳ EMA lọc xu hướng.
Vấn đề lớn nhất của chiến lược quét lưu lượng thông thường là có quá nhiều tiếng ồn. Ở đây, sử dụng 1 lần đường trung bình khối lượng giao dịch 11 chu kỳ làm bộ lọc, chỉ có đột phá trọng lượng để kích hoạt tín hiệu.
Thiết kế mạnh mẽ nhất ở đây là: ngay lập tức thanh toán ngay khi có tín hiệu quét thanh khoản ngược. Lập luận “chống lại tôi” này nhạy cảm hơn so với lệnh dừng truyền thống và có thể rút lui ngay khi xu hướng đảo ngược.
31 chu kỳ EMA không chỉ được sử dụng để lọc vào, mà còn là hàng rào cuối cùng để buộc ra. Thiết kế này thể hiện tâm lý cốt lõi của “xu hướng là vua” khi giá giảm xuống EMA.
Các thiết kế buy_lock và sell_lock trong mã rất khéo léo. Một khi kích hoạt tín hiệu quét, sẽ khóa tín hiệu theo cùng hướng cho đến khi giá quay trở lại vị trí quan trọng. Điều này tránh mở vị trí lặp lại trong cùng một làn sóng, giảm chi phí giao dịch và tiếp xúc với rủi ro.
Chiến lược này phù hợp nhất với môi trường thị trường có xu hướng rõ ràng nhưng có nhiều biến động. Nó hoạt động tốt khi tăng hoặc giảm một bên, nhưng thường xuyên bị dừng khi dao động ngang.
Chiến lược có nguy cơ mất mát liên tục, đặc biệt là khi cấu trúc thị trường thay đổi. Xác định dao động của chu kỳ 11 có thể không hiệu quả trong một số tình huống cực đoan, EMA chu kỳ 31 có sự chậm trễ trong sự đảo ngược nhanh.
/*backtest
start: 2024-12-17 00:00:00
end: 2025-12-15 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT","balance":500000}]
*/
//@version=5
strategy(
"Liquidity Sweep + Volume + OB + EMA Cross Exit (Fixed)",
overlay=true,
max_boxes_count=500,
max_lines_count=500,
initial_capital=100000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=10,
pyramiding=1)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// INPUTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
len = input.int(11, "Swing Length", minval=1)
volLen = input.int(11, "Volume MA Length", group="Volume Filter")
volMult = input.float(1, "Volume Multiplier", step=0.1, group="Volume Filter")
emaLength = input.int(31, "EMA Length", minval=1, group="EMA Filter")
extendBoxes = input.bool(true, "Extend Boxes")
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// EMA
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
emaVal = ta.ema(close, emaLength)
plot(emaVal, title="EMA", color=color.orange)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// COLORS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
buyCol = color.lime
sellCol = color.red
liqBuyCol = color.new(color.lime, 85)
liqSellCol = color.new(color.red, 85)
obBuyCol = color.new(color.green, 75)
obSellCol = color.new(color.maroon, 75)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// VOLUME FILTER
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
volMA = ta.sma(volume, volLen)
highVol = volume > volMA * volMult
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// PIVOTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ph = ta.pivothigh(len, len)
pl = ta.pivotlow(len, len)
var float lastPH = na
var float lastPL = na
if not na(ph)
lastPH := ph
if not na(pl)
lastPL := pl
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LIQUIDITY SWEEPS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
sellSweep = not na(lastPH) and high > lastPH and close < lastPH and highVol
buySweep = not na(lastPL) and low < lastPL and close > lastPL and highVol
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ANTI-SPAM LOCK
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var bool buyLock = false
var bool sellLock = false
if buySweep
buyLock := true
else if not na(lastPL) and close < lastPL
buyLock := false
if sellSweep
sellLock := true
else if not na(lastPH) and close > lastPH
sellLock := false
buySignal = buySweep and not buyLock[1]
sellSignal = sellSweep and not sellLock[1]
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// TRADE STATE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var float entryPrice = na
var int entryBar = na
var int entryDir = 0 // 1 = BUY, -1 = SELL
var bool tradeAlive = false
//━━━━━━━━ ENTRY ━━━━━━━━━━━━━━━━━━━
if buySignal and not tradeAlive
strategy.entry("BUY", strategy.long)
entryPrice := close
entryBar := bar_index
entryDir := 1
tradeAlive := true
if sellSignal and not tradeAlive
strategy.entry("SELL", strategy.short)
entryPrice := close
entryBar := bar_index
entryDir := -1
tradeAlive := true
barsFromEntry = tradeAlive ? bar_index - entryBar : na
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// EXIT LOGIC
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
exitBuyAfter3 = tradeAlive and entryDir == 1 and barsFromEntry >= 3 and close < entryPrice
exitSellAfter3 = tradeAlive and entryDir == -1 and barsFromEntry >= 3 and close > entryPrice
exitOppBuy = tradeAlive and entryDir == 1 and sellSignal
exitOppSell = tradeAlive and entryDir == -1 and buySignal
// EMA downside cross exit
emaCrossDown = tradeAlive and ta.crossunder(close, emaVal)
exitEMA = emaCrossDown
exitSignal = exitBuyAfter3 or exitSellAfter3 or exitOppBuy or exitOppSell or exitEMA
if exitSignal
if entryDir == 1
strategy.close("BUY")
if entryDir == -1
strategy.close("SELL")
tradeAlive := false
entryPrice := na
entryBar := na
entryDir := 0
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// PLOTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plotshape(buySignal, "BUY", shape.labelup, location.belowbar, color=buyCol, text="BUY", textcolor=color.black)
plotshape(sellSignal, "SELL", shape.labeldown, location.abovebar, color=sellCol, text="SELL", textcolor=color.white)
plotshape(exitBuyAfter3, "EXIT BUY 3+", shape.xcross, location.abovebar, color=color.orange)
plotshape(exitSellAfter3, "EXIT SELL 3+", shape.xcross, location.belowbar, color=color.orange)
plotshape(exitOppBuy, "EXIT BUY OPP", shape.flag, location.abovebar, color=color.yellow)
plotshape(exitOppSell, "EXIT SELL OPP", shape.flag, location.belowbar, color=color.yellow)
plotshape(exitEMA and entryDir == 1, "EXIT EMA BUY", shape.triangledown, location.abovebar, color=color.blue)
plotshape(exitEMA and entryDir == -1, "EXIT EMA SELL", shape.triangleup, location.belowbar, color=color.blue)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(buySignal, "BUY Alert", "Liquidity Sweep BUY")
alertcondition(sellSignal, "SELL Alert", "Liquidity Sweep SELL")
alertcondition(exitEMA,title="EXIT EMA CROSS",message="Price crossed below EMA")