
Chiến lược này là một hệ thống theo dõi xu hướng dựa trên nhiều đường trung bình di chuyển. Nó sử dụng các đường trung bình di chuyển đơn giản với ba chu kỳ khác nhau (50, 100, 200) để nắm bắt cơ hội xu hướng của thị trường thông qua tín hiệu chéo của đường trung bình nhanh và đường trung bình trung bình, kết hợp với xác nhận xu hướng của đường trung bình chậm.
Logic cốt lõi của chiến lược này dựa trên các yếu tố chính sau:
Chiến lược này là một hệ thống theo dõi xu hướng cổ điển, thông qua việc sử dụng nhiều đường trung bình, nó đảm bảo độ tin cậy của tín hiệu và có thể nắm bắt được xu hướng chính một cách hiệu quả. Mặc dù có một số sự chậm trễ, nhưng thông qua tối ưu hóa và quản lý rủi ro hợp lý, nó có thể trở thành một hệ thống giao dịch ổn định.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("MA Cross Strategy", overlay=true)
// Input untuk periode Moving Average dan warna label
fastLength = input.int(50, minval=1, title="Fast MA Length")
mediumLength = input.int(100, minval=1, title="Medium MA Length")
slowLength = input.int(200, minval=1, title="Slow MA Length")
longLabelColor = input.color(color.green, "Long Label Color")
shortLabelColor = input.color(color.red, "Short Label Color")
// Hitung Moving Average
fastMA = ta.sma(close, fastLength)
mediumMA = ta.sma(close, mediumLength)
slowMA = ta.sma(close, slowLength)
// Kondisi untuk buy dan sell
longCondition = ta.crossover(fastMA, mediumMA) and close >= slowMA
shortCondition = ta.crossunder(fastMA, mediumMA) and close <= slowMA
// Plot Moving Average
plot(fastMA, color=color.green, linewidth=1, title="Fast MA")
plot(mediumMA, color=color.orange, linewidth=1, title="Medium MA")
plot(slowMA, color=color.red, linewidth=2, title="Slow MA")
// Plot penanda crossover dengan warna dinamis
plot(ta.cross(fastMA, mediumMA) and (longCondition or shortCondition) ? mediumMA : na,
color=longCondition ? color.green : color.red,
style=plot.style_circles, linewidth=4, title="Crossover")
// Plot label saat kondisi entry terpenuhi
plotshape(longCondition, title="Long", location=location.belowbar, style=shape.labelup, size=size.normal, color=color.green, textcolor=color.white, text="Long")
plotshape(shortCondition, title="Short", location=location.abovebar, style=shape.labeldown, size=size.normal, color=color.red, textcolor=color.white, text="Short")
// Strategi
if longCondition
strategy.entry("Long", strategy.long)
if shortCondition
strategy.entry("Short", strategy.short)
// Exit strategy (berdasarkan crossover MA)
if ta.crossunder(fastMA, mediumMA) and strategy.position_size > 0
strategy.close("Long")
if ta.crossover(fastMA, mediumMA) and strategy.position_size < 0
strategy.close("Short")