Estratégia de negociação VWAP e monitoramento de anomalias de volume

VWAP RSI YTD SMA
Data de criação: 2024-06-07 15:44:04 última modificação: 2024-06-07 15:44:04
cópia: 0 Cliques: 717
1
focar em
1617
Seguidores

Estratégia de negociação VWAP e monitoramento de anomalias de volume

Visão geral

A estratégia é baseada em vários níveis de VWAP, incluindo o preço de abertura, o preço máximo, o preço mínimo e o gráfico de volume de transação anormalmente alto. A estratégia usa o VWAP como ponto de suporte e resistência, levando em consideração situações excepcionais de volume de transação. A estratégia gera um sinal de negociação quando o preço supera o nível de VWAP e atende a certas condições.

Princípio da estratégia

  1. Calcule vários níveis de VWAP, incluindo VWAP de preço de abertura, VWAP de preço máximo, VWAP de preço mínimo e VWAP de gráfico de volume de transação anormalmente alto.
  2. Detectar um diagrama de tráfego anormalmente alto e reinstalar a variável acumulada de VWAP anormalmente alto no diagrama.
  3. Defina um valor de desvio acima ou abaixo do nível VWAP como condição de disparo do sinal de negociação.
  4. Verifique se há salto de preço no outro lado do VWAP para evitar sinais errados.
  5. Dependendo da posição do preço em relação ao VWAP e da relação entre o preço de fechamento e o preço de abertura, são gerados vários sinais de negociação, incluindo dois tipos de Wick (linha de sombra) e Crossover (cruzamento).
  6. O indicador RSI é usado para detectar mudanças de volume, e quando o RSI é superior a 70 ou inferior a 30, o equilíbrio de posição correspondente é negociado.

Análise de vantagens

  1. A estratégia utiliza vários níveis de VWAP para fornecer informações mais abrangentes sobre os pontos de suporte e resistência.
  2. A estratégia pode capturar mudanças importantes no mercado através da detecção de gráficos de volume anormalmente altos.
  3. A configuração de desvio pode filtrar alguns sinais de ruído e melhorar a qualidade do sinal de negociação.
  4. O preço do VWAP, por outro lado, foi levado em consideração para evitar alguns sinais errados.
  5. Dependendo da posição relativa do preço em relação ao VWAP e da relação entre o preço de fechamento e o preço de abertura, são gerados vários sinais de negociação, aumentando a flexibilidade da estratégia.
  6. O uso do indicador RSI como condição de parada pode ajudar a estratégia a sair da negociação em tempo hábil quando a dinâmica muda.

Análise de Riscos

  1. A estratégia depende do nível do VWAP, que pode perder a sua eficácia se ocorrerem situações extremas no mercado.
  2. O julgamento de volume de negócios anormalmente elevado baseia-se em valores-limite fixos que podem não ser adequados a diferentes situações de mercado.
  3. A configuração do valor de desvio pode necessitar de ajustes de acordo com diferentes mercados e variedades de negociação.
  4. A estratégia gerou vários sinais de negociação, o que pode ter levado a um excesso de negociação e a altos custos de negociação.
  5. O RSI pode gerar sinais de equilíbrio atrasados, levando a uma estratégia de maior risco.

Direção de otimização

  1. Otimização de métodos de cálculo de níveis de VWAP, como considerar períodos de tempo mais longos ou usar métodos ponderados.
  2. Otimização de critérios de avaliação de volume de negócios anormalmente elevado, como a adoção de um limiar adaptado ou a combinação de outros indicadores de volume de negócios.
  3. Optimizar os parâmetros para os valores de desvio e encontrar a melhor amplitude de desvio.
  4. A introdução de medidas de gestão de risco, tais como o estabelecimento de paradas e paradas, para controlar o limite de risco de transações individuais.
  5. Tente outros indicadores de movimento ou combinações de vários indicadores para obter um sinal de equilíbrio mais preciso.
  6. Filtração de sinais de negociação para reduzir o excesso de negociação e os custos de negociação.

Resumir

A estratégia usa vários níveis de VWAP e detecção de anomalias de volume de transação para gerar uma variedade de sinais de negociação. Considerando a posição relativa do preço em relação ao VWAP, a relação entre o preço de fechamento e o preço de abertura e o indicador RSI, a estratégia tenta capturar mudanças importantes no mercado e sair de negociação em tempo hábil. No entanto, a estratégia também apresenta alguns riscos, como adaptabilidade a situações extremas, excesso de negociação e sinais de liquidação atrasados.

Código-fonte da estratégia
/*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")