
Chiến lược chéo đường trung bình di chuyển là một chiến lược giao dịch định lượng đơn giản và hiệu quả dựa trên đường trung bình di chuyển. Chiến lược này sử dụng chéo đường trung bình di chuyển nhanh và đường trung bình di chuyển chậm làm tín hiệu mua và bán.
Logic cốt lõi của chiến lược này là sử dụng moving average để đánh giá xu hướng thị trường. Moving average tự nó có chức năng làm rung động tiếng ồn thị trường ngẫu nhiên. Rapid moving average phản ứng nhanh hơn với sự thay đổi giá, phản ánh xu hướng mới nhất; và slow moving average phản ứng chậm hơn với sự thay đổi giá mới nhất, đại diện cho xu hướng trung hạn dài.
Cụ thể, chiến lược này đầu tiên xác định đường trung bình di chuyển nhanh sig1 và đường trung bình di chuyển chậm sig2 . Sau đó, dựa trên mối quan hệ chéo giữa sig1 và sig2 để đánh giá điểm mua và bán . Khi sig1 phá vỡ sig2 từ dưới tạo ra tín hiệu mua longCondition; khi sig1 phá vỡ sig2 từ trên tạo ra tín hiệu bán shortCondition .
Những lợi thế của chiến lược này rất rõ rệt:
Chiến lược này cũng có những rủi ro:
Các biện pháp tối ưu:
Chiến lược chéo trung bình di chuyển nói chung là một chiến lược định lượng đơn giản và thực tế. Bằng cách điều chỉnh tham số và tối ưu hóa thích hợp, nó có thể mang lại lợi nhuận ổn định trong nhiều môi trường thị trường.
/*backtest
start: 2023-11-14 00:00:00
end: 2023-11-16 04:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
// Simple yet effective MA cross strategy.
// You'll have to tune the parameters to get an optimal win ratio.
// If JPY or XAU or any other currency with pips defined as the
// second decimal digit are involved, do not forget to set the respective flag on.
//
// Created by vitelot/yanez/Vts, who's the same fellow with different user names
// December 2018 -- Merry Xmas
//
strategy("MA cross strategy Vts", overlay=true, initial_capital=1000, currency="EUR", pyramiding=0)
yr = input(2016, title="Starting year to analyse")
src = input(close, title="Source")
maType = input( defval="EMA", title="MA Type", options=["SMA","EMA","HMA","McG","WMA"])
//
isJPY = input(false, title="Is JPY or XAU involved?") // JPY and Gold have the pips defined as the 2 decimal digit
maPar1 = input(26, minval=1, title="MA fast period")
maPar2 = input(51, minval=2, title="MA slow period")
atrPar = input(14,minval=1, title="ATR period")
atrMulSL = input(1.5, title="SL ATR multiplicator")
atrMulTP = input(1.0, title="TP ATR multiplicator")
hma(sig, n) => // Hull moving average definition
wma( 2*wma(sig,round(n/2))-wma(sig,n), round(sqrt(n)))
mcg(sig,length) => // Mc Ginley MA definition
mg = 0.0
mg := na(mg[1]) ? ema(sig, length) : mg[1] + (sig - mg[1]) / (length * pow(sig/mg[1], 4))
ma(t,sig,len) =>
if t =="SMA"
sma(sig,len)
else
if t == "EMA"
ema(sig,len)
else
if t == "HMA"
hma(sig,len)
else
if t == "McG" // Mc Ginley
mcg(sig,len)
else
wma(sig,len)
sig1 = ma(maType, src, maPar1)
sig2 = ma(maType, src, maPar2)
tickFactor = isJPY? 1e3: 1e5
sl = atrMulSL*atr(atrPar)*tickFactor
tp = atrMulTP*atr(atrPar)*tickFactor
plot(sig1, color=aqua, title="MA1", linewidth=2)
plot(sig2, color=orange, title="MA2", linewidth=2)
longCondition = crossunder(sig2, sig1) and year>=yr // change the >= to == if you like exact years not a range
if (longCondition)
strategy.entry("Long", strategy.long, qty=1) // exit trade when SL and TP are hit
strategy.exit("Exit Long", "Long", loss=sl, profit=tp)
if (crossunder(sig1, sig2)) // or when the short condition is met
strategy.close("Long")
shortCondition = crossover(sig2,sig1) and year>=yr // change the >= to == if you like exact years not a range
if (shortCondition)
strategy.entry("Short", strategy.short, qty=1)
strategy.exit("Exit Short", "Short", loss=sl, profit=tp)
if (crossover(sig1,sig2))
strategy.close("Short")