
Chiến lược này kết hợp các chỉ số kỹ thuật đơn giản như đường trung bình di chuyển (SMA), hỗ trợ mức kháng cự và tăng khối lượng giao dịch, để xây dựng một chiến lược giao dịch toàn diện. Ý tưởng chính của chiến lược là giao dịch khi giá vượt qua đường trung bình SMA, hỗ trợ mức kháng cự và đi kèm với khối lượng giao dịch lớn hơn, đồng thời thiết lập điều kiện dừng lỗ để kiểm soát rủi ro.
Chiến lược này xây dựng một chiến lược giao dịch toàn diện bằng cách kết hợp đường trung bình SMA, mức kháng cự hỗ trợ và chỉ số khối lượng giao dịch. Ưu điểm của chiến lược là có thể nắm bắt cơ hội theo xu hướng, đồng thời kiểm soát rủi ro giao dịch. Tuy nhiên, chiến lược cũng có một số hạn chế, chẳng hạn như khả năng thích ứng với tình huống cực đoan của thị trường sẽ được cải thiện.
/*backtest
start: 2023-06-08 00:00:00
end: 2024-06-13 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Advanced Entry Conditions with Support/Resistance, SMA, and Volume", overlay=true)
// Inputs
length = input(20, title="SMA Length")
stopLossPerc = input(1, title="Stop Loss Percentage", type=input.float) / 100
leftBars = input(15, title="Left Bars")
rightBars = input(15, title="Right Bars")
distanceThresh = input(1, title="Distance Threshold from Support/Resistance", type=input.float) / 100
// Calculations
smaValue = sma(close, length)
highUsePivot = fixnan(pivothigh(leftBars, rightBars)[1])
lowUsePivot = fixnan(pivotlow(leftBars, rightBars)[1])
// Volume Calculation
volumeIncrease = volume > volume[1]
// Entry Conditions
longEntryCondition = close[0] > close[1] and close[1] > smaValue and close[0] > smaValue and close[0] > lowUsePivot and close[1] > lowUsePivot and abs(close[0] - highUsePivot) > distanceThresh and volumeIncrease
shortEntryCondition = close[0] < close[1] and close[1] < smaValue and close[0] < smaValue and close[0] < lowUsePivot and close[1] < lowUsePivot and abs(close[0] - highUsePivot) > distanceThresh and volumeIncrease
// Calculate stop loss levels
longStopLoss = close * (1 - stopLossPerc)
shortStopLoss = close * (1 + stopLossPerc)
// Strategy Logic
strategy.entry("Long", strategy.long, when=longEntryCondition)
strategy.exit("Exit Long", "Long", stop=longStopLoss)
strategy.entry("Short", strategy.short, when=shortEntryCondition)
strategy.exit("Exit Short", "Short", stop=shortStopLoss)
// Plotting
plot(smaValue, color=color.blue, title="SMA")
plot(highUsePivot, color=color.red, linewidth=2, title="Resistance")
plot(lowUsePivot, color=color.green, linewidth=2, title="Support")
plotshape(series=longEntryCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Long Entry")
plotshape(series=shortEntryCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Short Entry")
// Background Color
bgcolor(longEntryCondition ? color.new(color.green, 90) : shortEntryCondition ? color.new(color.red, 90) : na)