
Chiến lược này là một hệ thống giao dịch định lượng kết hợp nhiều chỉ số kỹ thuật, kết hợp hợp tác với ba chỉ số kỹ thuật cổ điển thông qua moving average (MA), chỉ số tương đối mạnh (RSI) và moving average convergence divergence (MACD) để xây dựng một hệ thống tín hiệu giao dịch hoàn chỉnh. Chiến lược này sử dụng theo dõi xu hướng kết hợp với nhận dạng động lượng, đồng thời đảm bảo hướng giao dịch đúng, đồng thời tập trung vào nắm bắt cơ hội. Đồng thời tích hợp các cơ chế kiểm soát rủi ro như dừng lỗ, dừng và theo dõi lỗ, tạo thành một chiến lược giao dịch có hệ thống.
Chiến lược này xây dựng tín hiệu giao dịch dựa trên ba cấp độ:
Cụ thể, khi đường trung bình nhanh (trên 50 ngày) xuyên qua đường trung bình chậm (trên 200 ngày) hình thành nếp nhăn vàng, đồng thời RSI không đạt đến mức mua quá mức và MACD hình thành nếp nhăn vàng, hệ thống tạo ra tín hiệu làm nhiều. Ngược lại, khi nếp nhăn chết xuất hiện và RSI không đạt đến mức bán quá mức, MACD hình thành nếp nhăn chết, hệ thống tạo ra tín hiệu làm trống.
Chiến lược này xây dựng một hệ thống giao dịch tương đối hoàn chỉnh thông qua sự phối hợp hợp của nhiều chỉ số kỹ thuật. Chiến lược này hoạt động tốt trong thị trường có xu hướng rõ ràng, nhưng vẫn cần điều chỉnh tối ưu hóa theo tình hình thị trường thực tế.
/*backtest
start: 2024-06-01 00:00:00
end: 2025-02-18 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EthioTrader
//@version=5
strategy("Optimal Multi-Indicator Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1)
// ===== Input Parameters =====
// Moving Averages
fastMA = ta.sma(close, 50)
slowMA = ta.sma(close, 200)
plot(fastMA, "Fast MA", color=color.green)
plot(slowMA, "Slow MA", color=color.red)
// RSI
rsiLength = input(14, "RSI Length")
rsiOverbought = input(70, "RSI Overbought")
rsiOversold = input(30, "RSI Oversold")
rsi = ta.rsi(close, rsiLength)
// MACD
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
// Risk Management
stopLossPerc = input(2.0, "Stop Loss (%)") / 100
takeProfitPerc = input(4.0, "Take Profit (%)") / 100
trailingStopPerc = input(1.0, "Trailing Stop (%)") / 100
// ===== Strategy Logic =====
// Trend Condition: Golden Cross (Fast MA > Slow MA)
bullishTrend = ta.crossover(fastMA, slowMA)
bearishTrend = ta.crossunder(fastMA, slowMA)
// Momentum Condition: RSI and MACD
bullishMomentum = rsi < rsiOverbought and ta.crossover(macdLine, signalLine)
bearishMomentum = rsi > rsiOversold and ta.crossunder(macdLine, signalLine)
// Entry Signals
longCondition = bullishTrend and bullishMomentum
shortCondition = bearishTrend and bearishMomentum
// Exit Signals
trailingStop = strategy.position_avg_price * (1 - trailingStopPerc)
exitLong = ta.crossunder(close, trailingStop) or (close >= strategy.position_avg_price * (1 + takeProfitPerc))
exitShort = ta.crossover(close, trailingStop) or (close <= strategy.position_avg_price * (1 - takeProfitPerc))
// ===== Execute Orders =====
if (longCondition)
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", "Long", stop=strategy.position_avg_price * (1 - stopLossPerc), limit=strategy.position_avg_price * (1 + takeProfitPerc), trail_price=trailingStop, trail_offset=trailingStopPerc * close)
if (shortCondition)
strategy.entry("Short", strategy.short)
strategy.exit("Exit Short", "Short", stop=strategy.position_avg_price * (1 + stopLossPerc), limit=strategy.position_avg_price * (1 - takeProfitPerc), trail_price=trailingStop, trail_offset=trailingStopPerc * close)
// ===== Plotting =====
plotshape(series=longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")