
Đây là một chiến lược giao dịch thông minh kết hợp các chỉ số siêu xu hướng và chỉ số RSI trong hai chu kỳ thời gian. Chiến lược phối hợp với chỉ số siêu xu hướng trong hai chu kỳ thời gian 5 phút và 60 phút và xác nhận tín hiệu giao dịch kết hợp với chỉ số RSI, cùng với cơ chế quản lý vị trí hoàn chỉnh. Chiến lược hỗ trợ cả hai mô hình giao dịch trong ngày và giao dịch giữ vị trí và cung cấp tùy chọn dừng lỗ và dừng lỗ di động linh hoạt.
Chiến lược này được sử dụng để giao dịch dựa trên các logic cốt lõi sau:
Đây là một chiến lược theo dõi xu hướng được thiết kế hợp lý, nghiêm ngặt về mặt logic. Nó có hiệu quả trong việc nâng cao độ tin cậy của tín hiệu giao dịch thông qua sự đồng bộ nhiều chu kỳ và cơ chế xác nhận RSI. Cơ chế kiểm soát rủi ro hoàn chỉnh và cài đặt tham số linh hoạt, làm cho nó có giá trị ứng dụng thực tế tốt.
/*backtest
start: 2024-10-01 00:00:00
end: 2024-10-31 23:59:59
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
// Author: Debabrata Saha
strategy("Supertrend Dual Timeframe with RSI", overlay=true)
// Input for System Mode (Positional/Intraday)
systemMode = input.string("Intraday", title="System Mode", options=["Intraday", "Positional"])
// Input for Intraday Session Times
startSession = input(timestamp("2023-10-01 09:15"), title="Intraday Start Session (Time From)")
endSession = input(timestamp("2023-10-01 15:30"), title="Intraday End Session (Time To)")
// Input for Target Settings (Off/Points/%)
targetMode = input.string("Off", title="Target Mode", options=["Off", "Points", "%"])
target1Value = input.float(10, title="Target 1 Value", step=0.1)
target2Value = input.float(20, title="Target 2 Value", step=0.1)
// Input for Stoploss Settings (Off/Points/%)
stoplossMode = input.string("Off", title="Stoploss Mode", options=["Off", "Points", "%"])
stoplossValue = input.float(10, title="Stoploss Value", step=0.1)
// Input for Trailing Stop Loss (Off/Points/%)
trailStoplossMode = input.string("Off", title="Trailing Stoploss Mode", options=["Off", "Points", "%"])
trailStoplossValue = input.float(5, title="Trailing Stoploss Value", step=0.1)
// Supertrend settings
atrPeriod = input(10, title="ATR Period")
factor = input(3.0, title="Supertrend Factor")
// Timeframe definitions
timeframe5min = "5"
timeframe60min = "60"
// Supertrend 5-min and 60-min (ta.supertrend returns two values: [Supertrend line, Buy/Sell direction])
[st5minLine, st5minDirection] = ta.supertrend(factor, atrPeriod)
[st60minLine, st60minDirection] = request.security(syminfo.tickerid, timeframe60min, ta.supertrend(factor, atrPeriod))
// RSI 5-min
rsi5min = ta.rsi(close, 14)
// Conditions for Buy and Sell signals
isSupertrendBuy = (st5minDirection == 1) and (st60minDirection == 1)
isSupertrendSell = (st5minDirection == -1) and (st60minDirection == -1)
buyCondition = isSupertrendBuy and (rsi5min > 60)
sellCondition = isSupertrendSell and (rsi5min < 40)
// Exit conditions
exitBuyCondition = st5minDirection == -1
exitSellCondition = st5minDirection == 1
// Intraday session check
inSession = true
// Strategy Logic (Trades only during the intraday session if systemMode is Intraday)
if (buyCondition and inSession)
strategy.entry("Buy", strategy.long)
if (sellCondition and inSession)
strategy.entry("Sell", strategy.short)
// Exit logic using strategy.close() to close the position at market price
if (exitBuyCondition)
strategy.close("Buy")
if (exitSellCondition)
strategy.close("Sell")
// No Sell when 60-min Supertrend is green and no Buy when 60-min Supertrend is red
if isSupertrendSell and (st60minDirection == 1)
strategy.close("Sell")
if isSupertrendBuy and (st60minDirection == -1)
strategy.close("Buy")
// Target Management
if (targetMode == "Points")
strategy.exit("Target 1", "Buy", limit=close + target1Value)
strategy.exit("Target 2", "Sell", limit=close - target2Value)
if (targetMode == "%")
strategy.exit("Target 1", "Buy", limit=close * (1 + target1Value / 100))
strategy.exit("Target 2", "Sell", limit=close * (1 - target2Value / 100))
// Stoploss Management
if (stoplossMode == "Points")
strategy.exit("Stoploss", "Buy", stop=close - stoplossValue)
strategy.exit("Stoploss", "Sell", stop=close + stoplossValue)
if (stoplossMode == "%")
strategy.exit("Stoploss", "Buy", stop=close * (1 - stoplossValue / 100))
strategy.exit("Stoploss", "Sell", stop=close * (1 + stoplossValue / 100))
// Trailing Stop Loss
if (trailStoplossMode == "Points")
strategy.exit("Trail SL", "Buy", trail_price=na, trail_offset=trailStoplossValue)
strategy.exit("Trail SL", "Sell", trail_price=na, trail_offset=trailStoplossValue)
if (trailStoplossMode == "%")
strategy.exit("Trail SL", "Buy", trail_price=na, trail_offset=trailStoplossValue / 100 * close)
strategy.exit("Trail SL", "Sell", trail_price=na, trail_offset=trailStoplossValue / 100 * close)