VWAP 거래 전략 및 거래량 이상 모니터링

VWAP RSI YTD SMA
생성 날짜: 2024-06-07 15:44:04 마지막으로 수정됨: 2024-06-07 15:44:04
복사: 0 클릭수: 717
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

VWAP 거래 전략 및 거래량 이상 모니터링

개요

이 전략은 여러 VWAP (거래량 중화 평균) 수준을 기반으로 하며, 개시 가격, 최고 가격, 최저 가격, 그리고 거래량이 비정상적으로 높은 그래프의 VWAP를 포함한다. 이 전략은 VWAP를 지지점과 저항점으로 사용하며, 거래량의 비정상적 상황을 고려한다. 가격이 VWAP 수준을 돌파하고 특정 조건을 충족하면, 이 전략은 거래 신호를 발생시킨다. 또한, 이 전략은 RSI 지표를 사용하여 운동량 변화를 검출하고, 평형 조건으로 사용한다.

전략 원칙

  1. 오픈 가격 VWAP, 최고 가격 VWAP, 최저 가격 VWAP, 그리고 비정상적으로 높은 거래량으로 표시된 VWAP를 포함한 여러 VWAP 레벨을 계산한다.
  2. 비정상적으로 높은 트래픽을 검출하고 그 트래픽에 비정상적으로 높은 VWAP의 축적 변수를 재배치한다.
  3. 거래 신호의 트리거 조건으로 VWAP 수준 이상의 오차 값을 설정한다.
  4. VWAP의 반대편에 가격대기가 있는지 확인하여 잘못된 신호를 피하십시오.
  5. VWAP에 대한 가격의 위치와 닫기 가격과 열기 가격의 관계에 따라, Wick (그림) 와 Crossover (교차) 를 포함한 두 가지 유형의 거래 신호가 생성됩니다.
  6. RSI 지표를 사용하여 운동량 변화를 감지하고, RSI가 70 이상 또는 30 이하일 때 평지상태에 해당하는 거래를 한다.

우위 분석

  1. 이 전략은 여러 VWAP 레벨을 활용하여 보다 포괄적인 지지점과 저항점 정보를 제공한다.
  2. 트래픽이 비정상적으로 높은 그램을 탐지함으로써 전략은 시장의 중요한 변화를 포착할 수 있다.
  3. 오차값을 설정하면 일부 노이즈 신호를 필터링하여 거래 신호의 품질을 향상시킬 수 있습니다.
  4. VWAP의 반대편에서 가격의 폭등을 고려하여 몇 가지 잘못된 신호를 피했습니다.
  5. 가격과 VWAP의 상대적인 위치와 닫기 가격과 열기 가격의 관계에 따라 여러 거래 신호를 생성하여 전략의 유연성을 증가시킨다.
  6. RSI 지표를 평준화 조건으로 사용하면 동력이 변하면 전략이 거래에서 조기에 빠져 나갈 수 있습니다.

위험 분석

  1. 이 전략은 VWAP 수준에 의존하며, 시장에서 극단적인 상황이 발생하면 VWAP는 효력을 상실할 수 있다.
  2. 비정상적으로 높은 거래량을 판단하는 것은 고정된 하락값을 기반으로 하며, 다른 시장 상황에 적응하지 못할 수도 있다.
  3. 다른 시장과 거래 품종에 따라 오차 값의 설정이 조정될 수 있습니다.
  4. 이 전략은 여러 거래 신호를 발생시켜 과도한 거래와 높은 거래 비용을 초래할 수 있습니다.
  5. RSI 지표는 지연된 평지 신호를 생성할 수 있으며, 이는 전략에 더 큰 위험을 초래할 수 있다.

최적화 방향

  1. VWAP 수준을 계산하는 방법을 최적화하여, 예를 들어 더 긴 시간 주기를 고려하거나 가중치 방법을 사용한다.
  2. 비정상적으로 높은 거래량을 판단하는 기준을 최적화합니다. 예를 들어, 적응된 마이너스를 사용하거나 다른 거래량 지표와 결합합니다.
  3. 오차값에 대한 변수 최적화를 통해 최적의 오차폭을 찾는다.
  4. 단편 거래에 대한 리스크 을 제어하기 위해 스톱 로즈와 스톱 스톱을 설정하는 것과 같은 리스크 관리 조치를 도입하십시오.
  5. 다른 동력 지표를 시도하거나 여러 지표를 조합하여 더 정확한 평지 신호를 얻으십시오.
  6. 거래 신호를 필터링하여 과도한 거래를 줄이고 거래 비용을 절감합니다.

요약하다

이 전략은 여러 VWAP 레벨과 거래량 변칙을 탐지하여 다양한 거래 신호를 생성한다. 가격과 VWAP의 상대적인 위치, 종결 가격과 개시 가격의 관계, RSI 지표를 고려하여 전략은 시장의 중요한 변화를 포착하고 거래에서 조기에 빠져나가려고 한다. 그러나, 이 전략에는 극단적인 상황에 대한 적응, 과도한 거래 및 지연된 평점 신호와 같은 몇 가지 위험이 있습니다.

전략 소스 코드
/*backtest
start: 2024-05-30 00:00:00
end: 2024-06-06 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("5 Anchored VWAP Strategy with Abnormally High Volume Candle", overlay=true)

// Initialize VWAP variables
var float vwap_open = na
var float vwap_high = na
var float vwap_low = na
var float vwap_high_volume = na

var float cum_v_open = 0
var float cum_v_high = 0
var float cum_v_low = 0
var float cum_v_high_volume = 0

var float cum_pv_open = 0
var float cum_pv_high = 0
var float cum_pv_low = 0
var float cum_pv_high_volume = 0

var float highest_volume = 0

// Initialize YTD high and low variables
var float ytd_high = na
var float ytd_low = na

// Parameters for abnormal volume detection
length = 20
volume_threshold = 2.0

// Displacement parameters
displacement_percentage = 0.01 // 1% displacement

// Calculate average volume
avg_volume = ta.sma(volume, length)

// Check if it's the first day of the year
is_first_day_of_year = year(time) != year(time[1])

// Reset YTD high and low on the first day of the year
if is_first_day_of_year
    ytd_high := high
    ytd_low := low

// Update YTD high and low
ytd_high := na(ytd_high) ? high : math.max(ytd_high, high)
ytd_low := na(ytd_low) ? low : math.min(ytd_low, low)

// Update cumulative variables for open VWAP
cum_v_open += volume
cum_pv_open += close * volume
if cum_v_open != 0
    vwap_open := cum_pv_open / cum_v_open

// Update cumulative variables for high VWAP
if high == ytd_high
    cum_v_high := 0
    cum_pv_high := 0

cum_v_high += volume
cum_pv_high += close * volume
if cum_v_high != 0
    vwap_high := cum_pv_high / cum_v_high

// Update cumulative variables for low VWAP
if low == ytd_low
    cum_v_low := 0
    cum_pv_low := 0

cum_v_low += volume
cum_pv_low += close * volume
if cum_v_low != 0
    vwap_low := cum_pv_low / cum_v_low

// Check for new high-volume candle that is also abnormally high and reset cumulative variables for high-volume VWAP
new_high_volume = false
if volume > highest_volume and volume > volume_threshold * avg_volume
    highest_volume := volume
    cum_v_high_volume := 0
    cum_pv_high_volume := 0
    new_high_volume := true

cum_v_high_volume += volume
cum_pv_high_volume += close * volume
if cum_v_high_volume != 0
    vwap_high_volume := cum_pv_high_volume / cum_v_high_volume

// Plot VWAPs
plot(vwap_open, color=color.red, linewidth=2, title="VWAP Open")
plot(vwap_high, color=color.green, linewidth=2, title="VWAP High")
plot(vwap_low, color=color.blue, linewidth=2, title="VWAP Low")
plot(vwap_high_volume, color=color.purple, linewidth=2, title="VWAP High Volume")

// Plot a vertical line on the chart only when a new high-volume VWAP anchor occurs
bgcolor(new_high_volume ? color.new(color.purple, 90) : na, offset=-1)

// Calculate displacement amounts
displacement_amount_open = vwap_open * displacement_percentage
displacement_amount_high = vwap_high * displacement_percentage
displacement_amount_low = vwap_low * displacement_percentage
displacement_amount_high_volume = vwap_high_volume * displacement_percentage

// Check for gaps on the opposite side of a VWAP
gap_up_opposite_open = na(close[1]) ? false : (open > close[1] and open < vwap_open and close[1] > vwap_open)
gap_down_opposite_open = na(close[1]) ? false : (open < close[1] and open > vwap_open and close[1] < vwap_open)

gap_up_opposite_high = na(close[1]) ? false : (open > close[1] and open < vwap_high and close[1] > vwap_high)
gap_down_opposite_high = na(close[1]) ? false : (open < close[1] and open > vwap_high and close[1] < vwap_high)

gap_up_opposite_low = na(close[1]) ? false : (open > close[1] and open < vwap_low and close[1] > vwap_low)
gap_down_opposite_low = na(close[1]) ? false : (open < close[1] and open > vwap_low and close[1] < vwap_low)

gap_up_opposite_high_volume = na(close[1]) ? false : (open > close[1] and open < vwap_high_volume and close[1] > vwap_high_volume)
gap_down_opposite_high_volume = na(close[1]) ? false : (open < close[1] and open > vwap_high_volume and close[1] < vwap_high_volume)

// RSI calculation for momentum change detection
rsi = ta.rsi(close, 14)
long_exit_condition = rsi > 70
short_exit_condition = rsi < 30

// Debugging Plots
plotshape(not gap_up_opposite_open and not gap_down_opposite_open and close > vwap_open and low < vwap_open - displacement_amount_open and close[1] < vwap_open, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Open Long Signal")
plotshape(not gap_up_opposite_open and not gap_down_opposite_open and close < vwap_open and high > vwap_open + displacement_amount_open and close[1] > vwap_open, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Open Short Signal")

plotshape(not gap_up_opposite_high and not gap_down_opposite_high and close > vwap_high and low < vwap_high - displacement_amount_high and close[1] < vwap_high, style=shape.triangledown, location=location.abovebar, color=color.blue, size=size.small, title="High Long Signal")
plotshape(not gap_up_opposite_high and not gap_down_opposite_high and close < vwap_high and high > vwap_high + displacement_amount_high and close[1] > vwap_high, style=shape.triangleup, location=location.belowbar, color=color.orange, size=size.small, title="High Short Signal")

plotshape(not gap_up_opposite_low and not gap_down_opposite_low and close > vwap_low and low < vwap_low - displacement_amount_low and close[1] < vwap_low, style=shape.triangledown, location=location.abovebar, color=color.purple, size=size.small, title="Low Long Signal")
plotshape(not gap_up_opposite_low and not gap_down_opposite_low and close < vwap_low and high > vwap_low + displacement_amount_low and close[1] > vwap_low, style=shape.triangleup, location=location.belowbar, color=color.yellow, size=size.small, title="Low Short Signal")

plotshape(not gap_up_opposite_high_volume and not gap_down_opposite_high_volume and close > vwap_high_volume and low < vwap_high_volume - displacement_amount_high_volume and close[1] < vwap_high_volume, style=shape.triangledown, location=location.abovebar, color=color.teal, size=size.small, title="High Volume Long Signal")
plotshape(not gap_up_opposite_high_volume and not gap_down_opposite_high_volume and close < vwap_high_volume and high > vwap_high_volume + displacement_amount_high_volume and close[1] > vwap_high_volume, style=shape.triangleup, location=location.belowbar, color=color.fuchsia, size=size.small, title="High Volume Short Signal")

// Trading signals based on VWAP support/resistance with displacement, no gaps on the opposite side, and bounce conditions
if not gap_up_opposite_open and not gap_down_opposite_open
    if (close > vwap_open and low < vwap_open)
        if close > open
            strategy.entry("Long_Open_Wick", strategy.long, comment="Wick")
        else
            strategy.entry("Long_Open_Crossover", strategy.long, comment="Crossover")
    
    if (close < vwap_open and high > vwap_open)
        if close < open
            strategy.entry("Short_Open_Wick", strategy.short, comment="Wick")
        else
            strategy.entry("Short_Open_Crossover", strategy.short, comment="Crossover")

if not gap_up_opposite_high and not gap_down_opposite_high
    if (close > vwap_high and low < vwap_high)
        if close > open
            strategy.entry("Long_High_Wick", strategy.long, comment="Wick")
        else
            strategy.entry("Long_High_Crossover", strategy.long, comment="Crossover")
    
    if (close < vwap_high and high > vwap_high)
        if close < open
            strategy.entry("Short_High_Wick", strategy.short, comment="Wick")
        else
            strategy.entry("Short_High_Crossover", strategy.short, comment="Crossover")

if not gap_up_opposite_low and not gap_down_opposite_low
    if (close > vwap_low and low < vwap_low)
        if close > open
            strategy.entry("Long_Low_Wick", strategy.long, comment="Wick")
        else
            strategy.entry("Long_Low_Crossover", strategy.long, comment="Crossover")
    
    if (close < vwap_low and high > vwap_low)
        if close < open
            strategy.entry("Short_Low_Wick", strategy.short, comment="Wick")
        else
            strategy.entry("Short_Low_Crossover", strategy.short, comment="Crossover")

if not gap_up_opposite_high_volume and not gap_down_opposite_high_volume
    if (close > vwap_high_volume and low < vwap_high_volume)
        if close > open
            strategy.entry("Long_High_Volume_Wick", strategy.long, comment="Wick")
        else
            strategy.entry("Long_High_Volume_Crossover", strategy.long, comment="Crossover")
    
    if (close < vwap_high_volume and high > vwap_high_volume)
        if close < open
            strategy.entry("Short_High_Volume_Wick", strategy.short, comment="Wick")
        else
            strategy.entry("Short_High_Volume_Crossover", strategy.short, comment="Crossover")

// Exit trades based on RSI momentum change
if strategy.position_size > 0 and long_exit_condition
    strategy.close("Long_Open_Wick")
    strategy.close("Long_Open_Crossover")
    strategy.close("Long_High_Wick")
    strategy.close("Long_High_Crossover")
    strategy.close("Long_Low_Wick")
    strategy.close("Long_Low_Crossover")
    strategy.close("Long_High_Volume_Wick")
    strategy.close("Long_High_Volume_Crossover")

if strategy.position_size < 0 and short_exit_condition
    strategy.close("Short_Open_Wick")
    strategy.close("Short_Open_Crossover")
    strategy.close("Short_High_Wick")
    strategy.close("Short_High_Crossover")
    strategy.close("Short_Low_Wick")
    strategy.close("Short_Low_Crossover")
    strategy.close("Short_High_Volume_Wick")
    strategy.close("Short_High_Volume_Crossover")