趋势反转型跨时间幅特异波动率交易策略

Author: ChaoZhang, Date: 2024-02-26 17:15:54
Tags:

趋势反转型跨时间幅特异波动率交易策略

概述

本策略通过计算不同时间窗口内的成交量买卖压力差异,结合MACD指标的多空信号,设计了一套趋势反转型的交易策略。该策略主要利用成交量的异动作为判断趋势反转的信号,并通过MACD的多空信号进行验证,从而捕捉反转机会。

策略原理

该策略的核心逻辑基于以下几点:

  1. 计算不同时间窗口(长短窗口)内的成交量买入压力和卖出压力。通过买卖压力的差异判断未来趋势方向。

  2. 利用MACD的差值(MACD线与信号线的差距)判断多空状态。结合成交量的买卖压力信号,验证趋势反转。

  3. 当成交量买入压力异动放大,且MACD线发生穿越时,认为行情可能出现由空转多的趋势反转。

  4. 当成交量卖出压力异动放大,且MACD线发生穿越时,认为行情可能出现由多转空的趋势反转。

  5. 进入反转信号后,利用止盈止损策略控制风险。

优势分析

该策略具有以下几点优势:

  1. 利用成交量的多空差异判断趋势反转点,避免单纯依赖均线等趋势判断指标而忽略成交量的作用。

  2. 结合MACD指标的多空信号验证反转,可以提高判断的准确性。

  3. 运用长短时间窗口判断成交量的异动方向,使反转信号更加可靠。

  4. 反转型策略的平均盈利率较高。

风险分析

该策略也存在以下风险:

  1. 成交量和MACD信号都可能发出错误信号,从而导致反转判断失误的风险。

  2. 反转信号发出后,行情可能再次调整,无法直接反转的风险。

  3. 止盈止损点设定不当,可能导致亏损扩大的风险。

  4. 回撤率较高,不适合追求稳定收益的投资者。

优化方向

该策略可以从以下几个方面进行优化:

  1. 优化长短时间窗口的区间,使反转判断更加精确。

  2. 优化MACD参数,提高多空判断的准确性。

  3. 优化止盈止损算法,降低亏损风险。

  4. 增加更多异动判断指标,提高反转成功率。

  5. 增加仓位控制和资金管理模块。

总结

本策略总体来说是一个典型的趋势反转型算法交易策略。它主要依靠成交量的异动放大与MACD信号的验证,判断并捕捉价格从多头进入空头或者从空头转向多头的反转机会。该策略具有判断准确率较高,收益率较好的优点,但也存在一定的风险。通过参数优化与功能扩展,可以使该策略的表现更加出色。


/*backtest
start: 2024-01-26 00:00:00
end: 2024-02-25 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("3 10 Oscillator Profile Flagging", shorttitle="3 10 Oscillator Profile Flagging", overlay=false)

signalBiasValue = input(title="Signal Bias", defval=0.26)
macdBiasValue = input(title="MACD Bias", defval=0.8)
shortLookBack = input( title="Short LookBack", defval=3)
longLookBack = input( title="Long LookBack", defval=10)
takeProfit = input( title="Take Profit", defval=0.75)
stopLoss = input( title="Stop Loss", defval=0.5)

fast_ma = ta.sma(close, 3)
slow_ma = ta.sma(close, 10)
macd = fast_ma - slow_ma
signal = ta.sma(macd, 16)
hline(0, "Zero Line", color = color.black)

buyVolume = volume*((close-low)/(high-low))
sellVolume = volume*((high-close)/(high-low))
buyVolSlope = buyVolume - buyVolume[1]
sellVolSlope = sellVolume - sellVolume[1]
signalSlope = ( signal - signal[1] )
macdSlope = ( macd - macd[1] )
plot(macd, color=color.blue, title="Total Volume")
plot(signal, color=color.orange, title="Total Volume")
intrabarRange = high - low

getLookBackSlope(lookBack) => signal - signal[lookBack]
getBuyerVolBias(lookBack) =>
    j = 0
    for i = 1 to lookBack
        if buyVolume[i] > sellVolume[i]
            j += 1
    j

getSellerVolBias(lookBack) =>
    j = 0
    for i = 1 to lookBack
        if sellVolume[i] > buyVolume[i]
            j += 1
    j

getVolBias(lookBack) =>
    float b = 0
    float s = 0
    for i = 1 to lookBack
        b += buyVolume[i]
        s += sellVolume[i]
    b > s

getSignalBuyerBias(lookBack) =>
    j = 0
    for i = 1 to lookBack
        if signal[i] > signalBiasValue
            j += 1
    j

getSignalSellerBias(lookBack) =>
    j = 0
    for i = 1 to lookBack
        if signal[i] < ( 0 - signalBiasValue )
            j += 1
    j

getSignalNoBias(lookBack) =>
    j = 0
    for i = 1 to lookBack
        if signal[i] < signalBiasValue and signal[i] > ( 0 - signalBiasValue )
            j += 1
    j

getPriceRising(lookBack) =>
    j = 0
    for i = 1 to lookBack
        if close[i] > close[i + 1]
            j += 1
    j


getPriceFalling(lookBack) =>
    j = 0
    for i = 1 to lookBack
        if close[i] < close[i + 1] 
            j += 1
    j

getRangeNarrowing(lookBack) =>
    j = 0
    for i = 1 to lookBack
        if intrabarRange[i] < intrabarRange[i + 1] 
            j+= 1
    j

getRangeBroadening(lookBack) =>
    j = 0
    for i = 1 to lookBack
        if intrabarRange[i] > intrabarRange[i + 1] 
            j+= 1
    j

bool isNegativeSignalReversal = signalSlope < 0 and signalSlope[1] > 0
bool isNegativeMacdReversal = macdSlope < 0 and macdSlope[1] > 0

bool isPositiveSignalReversal = signalSlope > 0 and signalSlope[1] < 0
bool isPositiveMacdReversal = macdSlope > 0 and macdSlope[1] < 0

bool hasBearInversion = signalSlope > 0 and macdSlope < 0
bool hasBullInversion = signalSlope < 0 and macdSlope > 0

bool hasSignalBias = math.abs(signal) >= signalBiasValue
bool hasNoSignalBias = signal < signalBiasValue and signal > ( 0 - signalBiasValue )

bool hasSignalBuyerBias = hasSignalBias and signal > 0
bool hasSignalSellerBias = hasSignalBias and signal < 0

bool hasPositiveMACDBias = macd > macdBiasValue
bool hasNegativeMACDBias = macd < ( 0 - macdBiasValue )

bool hasBullAntiPattern = ta.crossunder(macd, signal)
bool hasBearAntiPattern = ta.crossover(macd, signal)

bool hasSignificantBuyerVolBias = buyVolume > ( sellVolume * 1.5 )
bool hasSignificantSellerVolBias = sellVolume > ( buyVolume * 1.5 )

// 7.48 Profit 52.5% 
if ( hasSignificantBuyerVolBias and getPriceRising(shortLookBack) == shortLookBack  and getBuyerVolBias(shortLookBack) == shortLookBack and hasPositiveMACDBias and hasBullInversion)
    strategy.entry("Short1", strategy.short, qty=10)
strategy.exit("TPS", "Short1", limit=strategy.position_avg_price - takeProfit, stop=strategy.position_avg_price + stopLoss)

// 32.53 Profit 47.91%
if ( getPriceFalling(shortLookBack) and (getVolBias(shortLookBack) == false) and signalSlope < 0 and hasSignalSellerBias)
    strategy.entry("Long1", strategy.long, qty=10)
strategy.exit("TPS", "Long1", limit=strategy.position_avg_price + takeProfit, stop=strategy.position_avg_price - stopLoss)

更多内容