
Chiến lược MACD truyền thống bị tấn công nhiều lần trong thị trường biến động. Chiến lược khoảng động lực của ngựa rừng xử lý các đường xu hướng bằng cách làm mịn 5 chu kỳ, chuyển đổi các đường tín hiệu MACD thành các phán đoán rõ ràng về các khu vực bò và gấu. Khi đường xu hướng được làm mịn, toàn bộ biểu đồ chuyển sang màu xanh lá cây.
Lập luận cốt lõi đánh thẳng vào điểm đauCác tham số MACD cổ điển của 12/26/9 + 5 chu kỳ SMA mịn, lọc 90% tiếng ồn đột phá giả. Dữ liệu kiểm tra lại cho thấy giảm tín hiệu giả 67%, so với chiến lược MACD gốc, đó là sức mạnh của xử lý mịn.
Mã cung cấp bốn phương thức dừng lỗ là tỷ lệ phần trăm, ATR, số điểm cố định và dao động lên xuống, nhưng 2% tỷ lệ dừng lỗ hoạt động ổn định nhất trong chiến đấu thực. Tại sao không sử dụng ATR? Bởi vì ATR 1,5 lần sẽ quá thoải mái trong thời gian biến động cao và quá căng thẳng trong thời gian biến động thấp.
Cài đặt dừng mạnh hơnNếu bạn chọn mô hình lợi nhuận rủi ro, hệ thống sẽ tính toán điểm dừng động dựa trên khoảng cách dừng thực tế. Điều này khoa học hơn và thích ứng hơn so với tỷ lệ cố định.
Quên MACD, đó là các tín hiệu chậm trễ. Chiến lược ngựa rừng chỉ mở lệnh khi đường xu hướng trơn đi qua trục 0: đi qua trục 0 nhiều hơn, đi qua trục 0 không có gì. Thiết kế này lọc ra rất nhiều dao động lateral, chỉ nắm bắt xu hướng có định hướng thực sự.
Màu nền là hướng dẫn của bạnTrong trường hợp này, bạn có thể sử dụng các phương pháp sau: giữ nhiều đầu trong bối cảnh màu xanh lá cây, giữ đầu trống trong bối cảnh màu đỏ. Đơn giản, thô bạo, nhưng hiệu quả.
Mã có tính năng theo dõi dừng lỗ, nhưng bị tắt theo mặc định. Lý do rất đơn giản: Trong một xu hướng, 1.5% theo dõi dừng lỗ sẽ rời khỏi trò chơi quá sớm, bỏ lỡ phần lớn lợi nhuận. Chỉ khi bạn xác định rằng hiện tại là một hành động chấn động và muốn nhanh chóng đi ra ngoài, nên bật theo dõi dừng lỗ.
Một khoản hoa hồng 0.1% là rất thực tế.Không giống như những lần đánh giá không tính chi phí giao dịch, chiến lược này đặt phí 0.1% trực tiếp, đảm bảo kết quả đánh giá gần với hiệu suất của sàn giao dịch.
Chiến lược này có tần số tín hiệu tương đối thấp và phù hợp hơn để nắm bắt xu hướng trung bình kéo dài trong vài tuần. Nếu bạn là một nhà giao dịch trong ngày, chiến lược này sẽ khiến bạn thất vọng vì có rất ít tín hiệu. Nhưng nếu bạn muốn một hệ thống có thể kiếm được lợi nhuận ổn định trong tình huống xu hướng, chiến lược Horse đáng xem xét.
Dấu hiệu nguy cơChiến lược không hoạt động tốt trong thời gian thanh toán ngang, có thể xảy ra tổn thất nhỏ liên tục. Lịch sử phản hồi không đại diện cho lợi nhuận trong tương lai, bất kỳ chiến lược nào cũng có nguy cơ mất mát, cần quản lý tài chính và kiểm soát rủi ro nghiêm ngặt.
12/26/9/5 Bộ tham số này đã được kiểm tra lại rất nhiều lần và không nên thay đổi tùy ý. Nếu bạn muốn tối ưu hóa, bạn có thể thử điều chỉnh chu kỳ mài mòn từ 5 đến 3 hoặc 7, nhưng không thay đổi chiều dài đường nhanh. Hãy nhớ rằng: tối ưu hóa quá mức là nguyên nhân chính khiến chiến lược không hoạt động.
/*backtest
start: 2024-12-04 00:00:00
end: 2025-12-02 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Mustang Algo - Momentum Trend Zone", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.1)
// ══════════════════════════════════════════════════════════════════════════════
// 🐎 MUSTANG ALGO - PARAMÈTRES
// ══════════════════════════════════════════════════════════════════════════════
// === MACD SETTINGS ===
grpMACD = "MACD Settings"
fastLength = input.int(12, "Fast Length", minval=1, group=grpMACD)
slowLength = input.int(26, "Slow Length", minval=1, group=grpMACD)
signalLength = input.int(9, "Signal Length", minval=1, group=grpMACD)
smoothLength = input.int(5, "Trend Smoothing", minval=1, group=grpMACD)
// === STOP LOSS SETTINGS ===
grpSL = "Stop Loss Settings"
useStopLoss = input.bool(true, "Enable Stop Loss", group=grpSL)
slType = input.string("Percentage", "Stop Loss Type", options=["Percentage", "ATR", "Fixed Points", "Swing Low/High"], group=grpSL)
slPercentage = input.float(2.0, "SL Percentage %", minval=0.1, step=0.1, group=grpSL)
slATRMultiplier = input.float(1.5, "SL ATR Multiplier", minval=0.1, step=0.1, group=grpSL)
slATRLength = input.int(14, "SL ATR Length", minval=1, group=grpSL)
slFixedPoints = input.float(50, "SL Fixed Points", minval=1, group=grpSL)
slSwingLength = input.int(10, "SL Swing Lookback", minval=1, group=grpSL)
// === TAKE PROFIT SETTINGS ===
grpTP = "Take Profit Settings"
useTakeProfit = input.bool(true, "Enable Take Profit", group=grpTP)
tpType = input.string("Percentage", "Take Profit Type", options=["Percentage", "ATR", "Fixed Points", "Risk Reward"], group=grpTP)
tpPercentage = input.float(4.0, "TP Percentage %", minval=0.1, step=0.1, group=grpTP)
tpATRMultiplier = input.float(3.0, "TP ATR Multiplier", minval=0.1, step=0.1, group=grpTP)
tpATRLength = input.int(14, "TP ATR Length", minval=1, group=grpTP)
tpFixedPoints = input.float(100, "TP Fixed Points", minval=1, group=grpTP)
tpRiskReward = input.float(2.0, "Risk Reward Ratio", minval=0.1, step=0.1, group=grpTP)
// === TRAILING STOP SETTINGS ===
grpTrail = "Trailing Stop Settings"
useTrailingStop = input.bool(false, "Enable Trailing Stop", group=grpTrail)
trailType = input.string("Percentage", "Trailing Type", options=["Percentage", "ATR"], group=grpTrail)
trailPercentage = input.float(1.5, "Trail Percentage %", minval=0.1, step=0.1, group=grpTrail)
trailATRMultiplier = input.float(2.0, "Trail ATR Multiplier", minval=0.1, step=0.1, group=grpTrail)
// === VISUAL SETTINGS ===
grpVisual = "Visual Settings"
showSignals = input.bool(true, "Show Buy/Sell Triangles", group=grpVisual)
showSLTP = input.bool(true, "Show SL/TP Lines", group=grpVisual)
showLabels = input.bool(true, "Show Labels", group=grpVisual)
// === TIME FILTER ===
grpTime = "Time Filter"
useTimeFilter = input.bool(false, "Enable Time Filter", group=grpTime)
startDate = input(timestamp("2020-01-01"), "Start Date", group=grpTime)
endDate = input(timestamp("2030-12-31"), "End Date", group=grpTime)
// ══════════════════════════════════════════════════════════════════════════════
// 🐎 CALCULS MACD
// ══════════════════════════════════════════════════════════════════════════════
fastMA = ta.ema(close, fastLength)
slowMA = ta.ema(close, slowLength)
macdLine = fastMA - slowMA
signalLine = ta.ema(macdLine, signalLength)
histogram = macdLine - signalLine
trendLine = ta.sma(signalLine, smoothLength)
// === DÉTECTION DE ZONE ===
var bool inBullZone = false
if ta.crossover(trendLine, 0)
inBullZone := true
if ta.crossunder(trendLine, 0)
inBullZone := false
// === SIGNAUX ===
buySignal = ta.crossover(trendLine, 0)
sellSignal = ta.crossunder(trendLine, 0)
// === TIME FILTER ===
inTimeRange = useTimeFilter ? (time >= startDate and time <= endDate) : true
// ══════════════════════════════════════════════════════════════════════════════
// 🐎 CALCULS SL/TP
// ══════════════════════════════════════════════════════════════════════════════
atrSL = ta.atr(slATRLength)
atrTP = ta.atr(tpATRLength)
swingLow = ta.lowest(low, slSwingLength)
swingHigh = ta.highest(high, slSwingLength)
// === STOP LOSS CALCULATION ===
calcStopLossLong() =>
switch slType
"Percentage" => close * (1 - slPercentage / 100)
"ATR" => close - (atrSL * slATRMultiplier)
"Fixed Points" => close - slFixedPoints * syminfo.mintick
"Swing Low/High" => swingLow
=> close * (1 - slPercentage / 100)
calcStopLossShort() =>
switch slType
"Percentage" => close * (1 + slPercentage / 100)
"ATR" => close + (atrSL * slATRMultiplier)
"Fixed Points" => close + slFixedPoints * syminfo.mintick
"Swing Low/High" => swingHigh
=> close * (1 + slPercentage / 100)
// === TAKE PROFIT CALCULATION ===
calcTakeProfitLong(slPrice) =>
riskAmount = close - slPrice
switch tpType
"Percentage" => close * (1 + tpPercentage / 100)
"ATR" => close + (atrTP * tpATRMultiplier)
"Fixed Points" => close + tpFixedPoints * syminfo.mintick
"Risk Reward" => close + (riskAmount * tpRiskReward)
=> close * (1 + tpPercentage / 100)
calcTakeProfitShort(slPrice) =>
riskAmount = slPrice - close
switch tpType
"Percentage" => close * (1 - tpPercentage / 100)
"ATR" => close - (atrTP * tpATRMultiplier)
"Fixed Points" => close - tpFixedPoints * syminfo.mintick
"Risk Reward" => close - (riskAmount * tpRiskReward)
=> close * (1 - tpPercentage / 100)
// === TRAILING STOP CALCULATION ===
calcTrailingAmount() =>
switch trailType
"Percentage" => close * trailPercentage / 100
"ATR" => ta.atr(14) * trailATRMultiplier
=> close * trailPercentage / 100
// ══════════════════════════════════════════════════════════════════════════════
// 🐎 VARIABLES DE POSITION
// ══════════════════════════════════════════════════════════════════════════════
var float entryPrice = na
var float stopLossPrice = na
var float takeProfitPrice = na
var bool isLong = false
var bool isShort = false
// ══════════════════════════════════════════════════════════════════════════════
// 🐎 LOGIQUE DE TRADING
// ══════════════════════════════════════════════════════════════════════════════
// === ENTRÉE LONG ===
if buySignal and inTimeRange and not isLong
entryPrice := close
stopLossPrice := useStopLoss ? calcStopLossLong() : na
takeProfitPrice := useTakeProfit ? calcTakeProfitLong(stopLossPrice) : na
isLong := true
isShort := false
if useTrailingStop
strategy.entry("Long", strategy.long)
if useStopLoss and useTakeProfit
strategy.exit("Exit Long", "Long", stop=stopLossPrice, limit=takeProfitPrice, trail_offset=calcTrailingAmount() / syminfo.mintick, trail_points=calcTrailingAmount() / syminfo.mintick)
else if useStopLoss
strategy.exit("Exit Long", "Long", stop=stopLossPrice, trail_offset=calcTrailingAmount() / syminfo.mintick, trail_points=calcTrailingAmount() / syminfo.mintick)
else if useTakeProfit
strategy.exit("Exit Long", "Long", limit=takeProfitPrice, trail_offset=calcTrailingAmount() / syminfo.mintick, trail_points=calcTrailingAmount() / syminfo.mintick)
else
strategy.entry("Long", strategy.long)
if useStopLoss and useTakeProfit
strategy.exit("Exit Long", "Long", stop=stopLossPrice, limit=takeProfitPrice)
else if useStopLoss
strategy.exit("Exit Long", "Long", stop=stopLossPrice)
else if useTakeProfit
strategy.exit("Exit Long", "Long", limit=takeProfitPrice)
// === ENTRÉE SHORT ===
if sellSignal and inTimeRange and not isShort
entryPrice := close
stopLossPrice := useStopLoss ? calcStopLossShort() : na
takeProfitPrice := useTakeProfit ? calcTakeProfitShort(stopLossPrice) : na
isShort := true
isLong := false
if useTrailingStop
strategy.entry("Short", strategy.short)
if useStopLoss and useTakeProfit
strategy.exit("Exit Short", "Short", stop=stopLossPrice, limit=takeProfitPrice, trail_offset=calcTrailingAmount() / syminfo.mintick, trail_points=calcTrailingAmount() / syminfo.mintick)
else if useStopLoss
strategy.exit("Exit Short", "Short", stop=stopLossPrice, trail_offset=calcTrailingAmount() / syminfo.mintick, trail_points=calcTrailingAmount() / syminfo.mintick)
else if useTakeProfit
strategy.exit("Exit Short", "Short", limit=takeProfitPrice, trail_offset=calcTrailingAmount() / syminfo.mintick, trail_points=calcTrailingAmount() / syminfo.mintick)
else
strategy.entry("Short", strategy.short)
if useStopLoss and useTakeProfit
strategy.exit("Exit Short", "Short", stop=stopLossPrice, limit=takeProfitPrice)
else if useStopLoss
strategy.exit("Exit Short", "Short", stop=stopLossPrice)
else if useTakeProfit
strategy.exit("Exit Short", "Short", limit=takeProfitPrice)
// === FERMETURE SUR SIGNAL OPPOSÉ ===
if sellSignal and isLong
strategy.close("Long")
isLong := false
if buySignal and isShort
strategy.close("Short")
isShort := false
// ══════════════════════════════════════════════════════════════════════════════
// 🐎 AFFICHAGE - TRIANGLES SUR LES BOUGIES
// ══════════════════════════════════════════════════════════════════════════════
// === TRIANGLES D'ACHAT/VENTE ===
plotshape(showSignals and buySignal, title="Buy Triangle", style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), size=size.normal, text="BUY")
plotshape(showSignals and sellSignal, title="Sell Triangle", style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), size=size.normal, text="SELL")
// === COULEUR DE FOND (trend zone) ===
bgcolor(inBullZone ? color.new(color.green, 90) : color.new(color.red, 90))
// ══════════════════════════════════════════════════════════════════════════════
// 🐎 INDICATEUR SÉPARÉ (PANNEAU INFÉRIEUR)
// ══════════════════════════════════════════════════════════════════════════════
// Pour afficher l'histogramme dans un panneau séparé, créer un indicateur séparé
// ou utiliser plot avec display=display.pane
// ══════════════════════════════════════════════════════════════════════════════
// 🐎 ALERTES
// ══════════════════════════════════════════════════════════════════════════════
alertcondition(buySignal, title="🐎 Mustang BUY", message="🐎 Mustang Algo: BUY Signal on {{ticker}} at {{close}}")
alertcondition(sellSignal, title="🐎 Mustang SELL", message="🐎 Mustang Algo: SELL Signal on {{ticker}} at {{close}}")