
이 전략은 VWAP(거래량 가중 평균 가격)과 표준편차 채널을 기반으로 한 추세 돌파 전략입니다. VWAP와 상한 및 하한 표준 편차 채널을 계산하여 역동적인 가격 변동 범위를 구성하여 가격이 상승할 때 거래 기회를 포착합니다. 이 전략은 거래를 위한 표준편차대의 돌파 신호에 주로 의존하며, 위험을 통제하기 위해 이익 목표와 주문 간격을 설정합니다.
이는 통계적 원리와 기술적 분석을 결합한 양적 거래 전략입니다. VWAP와 표준편차대의 조정을 통해 비교적 신뢰할 수 있는 거래 시스템이 구축됩니다. 이 전략의 핵심적인 장점은 과학적인 통계적 기초와 완벽한 위험 관리 메커니즘에 있지만, 실제 응용 프로그램에서는 여전히 매개변수와 거래 논리를 지속적으로 최적화해야 합니다.
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("VWAP Stdev Bands Strategy (Long Only)", overlay=true)
// Standard Deviation Inputs
devUp1 = input.float(1.28, title="Stdev above (1)")
devDn1 = input.float(1.28, title="Stdev below (1)")
// Show Options
showPrevVWAP = input(false, title="Show previous VWAP close?")
profitTarget = input.float(2, title="Profit Target ($)", minval=0) // Profit target for closing orders
gapMinutes = input.int(15, title="Gap before new order (minutes)", minval=0) // Gap for placing new orders
// VWAP Calculation
var float vwapsum = na
var float volumesum = na
var float v2sum = na
var float prevwap = na // Track the previous VWAP
var float lastEntryPrice = na // Track the last entry price
var int lastEntryTime = na // Track the time of the last entry
start = request.security(syminfo.tickerid, "D", time)
newSession = ta.change(start)
vwapsum := newSession ? hl2 * volume : vwapsum[1] + hl2 * volume
volumesum := newSession ? volume : volumesum[1] + volume
v2sum := newSession ? volume * hl2 * hl2 : v2sum[1] + volume * hl2 * hl2
myvwap = vwapsum / volumesum
dev = math.sqrt(math.max(v2sum / volumesum - myvwap * myvwap, 0))
// Calculate Upper and Lower Bands
lowerBand1 = myvwap - devDn1 * dev
upperBand1 = myvwap + devUp1 * dev
// Plot VWAP and Bands with specified colors
plot(myvwap, style=plot.style_line, title="VWAP", color=color.green, linewidth=1)
plot(upperBand1, style=plot.style_line, title="VWAP Upper (1)", color=color.blue, linewidth=1)
plot(lowerBand1, style=plot.style_line, title="VWAP Lower (1)", color=color.red, linewidth=1)
// Trading Logic (Long Only)
longCondition = close < lowerBand1 and close[1] >= lowerBand1 // Price crosses below the lower band
// Get the current time in minutes
currentTime = timestamp("GMT-0", year(timenow), month(timenow), dayofmonth(timenow), hour(timenow), minute(timenow))
// Check if it's time to place a new order based on gap
canPlaceNewOrder = na(lastEntryTime) or (currentTime - lastEntryTime) >= gapMinutes * 60 * 1000
// Close condition based on profit target
if (strategy.position_size > 0)
if (close - lastEntryPrice >= profitTarget)
strategy.close("B")
lastEntryTime := na // Reset last entry time after closing
// Execute Long Entry
if (longCondition and canPlaceNewOrder)
strategy.entry("B", strategy.long)
lastEntryPrice := close // Store the entry price
lastEntryTime := currentTime // Update the last entry time
// Add label for the entry
label.new(bar_index, close, "B", style=label.style_label_down, color=color.green, textcolor=color.white, size=size.small)
// Optional: Plot previous VWAP for reference
prevwap := newSession ? myvwap[1] : prevwap[1]
plot(showPrevVWAP ? prevwap : na, style=plot.style_circles, color=close > prevwap ? color.green : color.red)