
Chiến lược này sử dụng ba chỉ số kỹ thuật là hỗ trợ, kháng cự và đường xu hướng để tự động vào và dừng. Chiến lược này trước tiên xác định các vị trí hỗ trợ và kháng cự quan trọng, sau đó kết hợp với hướng xu hướng để đánh giá thời gian vào.
Phản ứng:
Chiến lược này tích hợp các lợi thế của nhiều chỉ số kỹ thuật, có thể đạt được tỷ lệ rủi ro lợi nhuận tốt hơn với điều kiện đặt tham số hợp lý. Điều quan trọng là tối ưu hóa các tham số và thứ tự nhập cảnh. Nhìn chung, khung chiến lược là hợp lý và có rất nhiều chỗ để cải thiện.
/*backtest
start: 2024-01-27 00:00:00
end: 2024-02-26 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Support Resistance Trend Strategy", overlay=true)
// Input parameters
supportLevel = input(100, title="Support Level")
resistanceLevel = input(200, title="Resistance Level")
riskRewardRatio = input(2, title="Risk-Reward Ratio")
trailStopLoss = input(true, title="Use Trailing Stop Loss")
// Calculate trend direction based on trend lines
trendUp = close > request.security(syminfo.tickerid, "D", close[1])
trendDown = close < request.security(syminfo.tickerid, "D", close[1])
// Buy signal condition
buySignal = close < supportLevel and trendUp
// Sell signal condition
sellSignal = close > resistanceLevel and trendDown
// Entry point and exit conditions
strategy.entry("Buy", strategy.long, when=buySignal)
strategy.entry("Sell", strategy.short, when=sellSignal)
// Calculate targets and stop-loss levels
targetPrice = close + (close - supportLevel) * riskRewardRatio
stopLossLevel = supportLevel
// Plot support and resistance levels
plot(supportLevel, color=color.green, linewidth=2, title="Support Level")
plot(resistanceLevel, color=color.red, linewidth=2, title="Resistance Level")
// Plot targets and stop-loss levels
plot(targetPrice, color=color.blue, linewidth=2, title="Target Price")
plot(stopLossLevel, color=color.orange, linewidth=2, title="Stop Loss Level")
// Trailing stop-loss
strategy.exit("Take Profit/Stop Loss", from_entry="Buy", loss=stopLossLevel, profit=targetPrice)
strategy.exit("Take Profit/Stop Loss", from_entry="Sell", loss=targetPrice, profit=stopLossLevel)
// Plot trail stop loss
if (trailStopLoss)
strategy.exit("Trailing Stop Loss", from_entry="Buy", loss=stopLossLevel)
strategy.exit("Trailing Stop Loss", from_entry="Sell", loss=stopLossLevel)