资源加载中... loading...

动力追踪交易策略

Author: ChaoZhang, Date: 2023-12-20 16:06:26
Tags:

动力追踪交易策略

策略概述

动力追踪交易策略是一种以追踪市场动力的趋势为主线,结合多种技术指标作为辅助判断的自动化交易策略。该策略通过解析K线信息,判断当前市场主力资金的方向和力度,然后结合量价指标、移动平均线等技术指标发出交易信号,实现趋势跟踪。

整体而言,该策略适合于中长线趋势交易,能够有效捕捉市场趋势,降低交易频率,追求更高的单笔盈利。同时,策略参数优化后,也可用于短线交易。

策略原理

主力判断

动力追踪策略的核心在于判断市场的主力资金方向。策略通过计算ATR指标,实时监测市场的波动力度。当波动加大时,代表主力正在进行积累或分配,策略会暂时退出市场,避开主力操作的时间段。

当波动减弱时,代表主力积累或分配完毕,策略会重新进场,判断主力的具体方向。判断方式是通过计算市场的支撑压力位置,看是否有突破的迹象。如果有明确的突破,则证实主力选择了该方向。

辅助判断

在确定主力方向后,策略还会引入多种辅助技术指标进行再次验证,避免出现误判。具体而言,会计算MACD、KDJ等指标,判断其是否与主力方向一致。

只有当主力方向和辅助指标都发出同向信号时,策略才会开仓建立头寸。这有效控制了交易频率,只在高概率情况下入场。

止损退出

建仓后,动力追踪策略会实时跟踪价格变动,并以ATR值的扩大作为止损信号。这代表市场再次进入主力操作阶段,必须立即退出至现金,避免被套。

另外,若价格运行超过一定范围后回调也会止损。这属于正常的技术性回调,跟风险控制需立即止损。

策略优势

系统性强

动力追踪策略最大的优势在于高度系统化和规范化。其交易逻辑清晰,每次入场和退出都有明确的原则和规则,不会出现随意交易的情况。

这使得该策略可复制性非常强,用户可以配置后长期应用,而不需要人工干预。

风险控制到位

策略内置了多级风险控制机制,如主力判断、辅助验证、止损线制定等,可有效控制非系统性风险。

具体来说,策略只在高概率情况下开仓,并设置科学的止损位,最大程度避免损失扩大。这保证了资金的稳定增长。

收益较为可持续

相比短线策略,动力追踪策略的持仓周期更长,每次获利也更高。这使得策略整体收益较为稳定可持续。

并且,策略追踪中长线趋势,可充分捕捉行情的波动性,这在大趋势行情中尤为明显。

风险警示

参数优化难度大

动力追踪策略涉及较多参数,如ATR参数、突破参数、止损参数等。这些参数间存在一定相关性,需要反复测试才能找到最优参数组合。

如果参数配置不当,极易造成交易频率过大或风险控制不足的问题。这需要用户具备一定的策略优化经验。

突破容易被套

策略判断主力和指标信号时,都依赖于价格的突破来证实。但突破操作中,容易出现假突破的情况,这会导致被套仓的概率较大。

如果遭遇关键性突破失败,则可能带来较大亏损。这是策略的内在弱点。

优化思路

引入机器学习

可以通过机器学习算法自动探测参数间的相关性,寻找最优参数组合。这比人工测试要高效得多。

具体来说,可以使用 EnvironmentError算法,基于强化学习不断迭代 parameter,使策略收益最大化。

增加过滤器

可以在现有指标的基础上,引入更多辅助过滤器,如交易量指标、资金流指标等,对突破信号进行三次四次验证,可靠性更高。

但过滤器太多也会导致错过机会,需要平衡过滤强度。此外,过滤器自身也要避免产生相关性。

策略融合

将动力追踪策略与其他策略组合使用,可以利用不同策略的优势,实现正交化,提高整体稳定性。

比如,融合短期反转策略,在突破后打开反转交易,可锁定更多利润。

总结

动力追踪交易策略整体而言是一个值得推荐的系统化趋势跟踪策略。它交易逻辑清晰,风险控制到位,可为用户带来稳定而高效的投资回报。

但策略本身也存在一定固有缺陷,需要用户具备参数优化和策略融合的能力,方可发挥该策略的最大效用。总体而言,动力追踪策略是一款适合有一定量化基础的策略爱好者使用的量化产品。


/*backtest
start: 2023-12-12 00:00:00
end: 2023-12-15 01:00:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Created by frasmac2k Strategy credit to Alex Morris

//@version=5
strategy("Mechanical", shorttitle="MECH", overlay=true)

// Get the current date and time
currentYear = year
currentMonth = month
currentDay = dayofmonth

// Create a timestamp for the present date and time
currentTimestamp = timestamp(currentYear, currentMonth, currentDay)

// Define time interval for backtesting
dStart = input(timestamp('2023-07-01'), title='Set Start date', tooltip='Select a start date to run the script from')

// Define direction of strategy
direction = input.string('Forward',title='Direction', tooltip='Forward will go LONG on a Green anchor candle. Inverse will go short on a Green anchor candle and vice versa for Red candle', options=['Forward', 'Inverse'])

// Define the anchor hour as user input with a range of 0 to 23
anchorHour = input.int(11, title="Anchor Hour", tooltip='Set the hour to trade', minval=0, maxval=23)

// Define the take profit and stop loss in pips
takeProfitPips = input.int(10, title='Define TP Pips', tooltip='How many pips do you want to set TP. Choose a sensible value related to the instrument', minval=5)
stopLossPips = input.int(10,'Define SL Pips', tooltip='How many pips do you want to set SL. Choose a sensible value related to the instrument', minval=5)

// Define Tick size
tick10p = input.int(100, title='tick size', tooltip='Choose how many ticks equal 10 pips. This can vary by broker so measure 10 pips on the chart and select how many ticks that equates to. Forex is typically 100. Some instruments such as indices can be 1000', options=[100,1000])

// Declare TP/SL variables
var float takeProfit = na
var float stopLoss = na

// Calculate take profit and stop loss levels in ticks
if tick10p == 100
    takeProfit := takeProfitPips * 10
    stopLoss := stopLossPips * 10
if tick10p == 1000
    takeProfit := takeProfitPips * 100
    stopLoss := stopLossPips * 100

// Declare offset time
var int offset = na

if currentTimestamp > timestamp('2023-10-29')
    offset := 4
else
    offset := 5

//adjust for exchange time
anchorHour := anchorHour - offset

// Define the anchor hour as user input with a range of 0 to 23
tradeHour = anchorHour

// Define logical check for strategy date range
isStratTime = true

// Calculate the time condition for placing the order at the user-defined hour (start of the next hour)
isTradeTime = true

// Logic condition for forwards or inverse
isForward = direction == 'Forward'
isInverse = direction == 'Inverse'

// Declare entry condition variables
var bool longCondition = na
var bool shortCondition = na

// Declare and initialize variables for anchorCandle open and close prices
var float anchorOpen = na
var float anchorClose = na
var float tradeOpen = na
var float tradeClose = na

// Set logic by direction

if isForward
    // Strategy logic
    if isTradeTime and isStratTime
        //Obtain candle open/close
        anchorOpen := open
        anchorClose := close
        // Define entry conditions
        longCondition := anchorClose > anchorOpen
        shortCondition := anchorClose < anchorOpen
        
        // Entry logic
        if longCondition
            strategy.entry("Long", strategy.long)
            strategy.exit("Exit Long", from_entry="Long", profit=takeProfit, loss=stopLoss, comment_profit='TP', comment_loss='SL')
        if shortCondition
            strategy.entry("Short", strategy.short)
            strategy.exit("Exit Short", from_entry="Short", profit=takeProfit, loss=stopLoss, comment_profit='TP', comment_loss='SL')

if isInverse
    // Strategy logic
    if isTradeTime and isStratTime
        //Obtain candle open/close
        anchorOpen := open
        anchorClose := close
        // Define entry conditions
        shortCondition := anchorClose > anchorOpen
        longCondition := anchorClose < anchorOpen
        
        // Entry logic
        if longCondition
            strategy.entry("Long", strategy.long)
            strategy.exit("Exit Long", from_entry="Long", profit=takeProfit, loss=stopLoss, comment_profit='TP', comment_loss='SL')
        if shortCondition
            strategy.entry("Short", strategy.short)
            strategy.exit("Exit Short", from_entry="Short", profit=takeProfit, loss=stopLoss, comment_profit='TP', comment_loss='SL')

// Define the time range for the background shade
startHour = anchorHour
startMinute = 0
endHour = anchorHour
endMinute = 0

// Check if the current time is within the specified range
isInTimeRange = (hour == startHour and minute >= startMinute) or (hour == endHour and minute <= endMinute) or (hour > startHour and hour < endHour)

// Define the background color for the shade
backgroundColor = color.new(color.red, 90)

// Apply the background shade
bgcolor(isInTimeRange ? backgroundColor : na)



更多内容