本文将详细讲解一种基于价格回调比例来进行趋势追踪的量化交易策略。该策略通过识别局部高点,以一定回调比例进行定点入场。
一、策略原理
该策略的核心逻辑是识别特定周期内的最高价,随后在一定比例的回调位置进行追踪交易。具体步骤如下:
首先计算最近90根K线的最高价,作为局部高点;
当价格从该高点回调一定比例(如3%)后,进行买入追踪;
止盈设置为从入场价上涨一定比例(如6%),当价格达到止盈点时平仓;
不设置止损,以追踪趋势为主。
这样,通过局部高点回调的比例来判断入场时机,可以有效过滤震荡,仅在趋势确认后入场。止盈设置也使每单获利有一定的预期管理。
二、策略优势
该策略最大的优势是利用回调比例来判断趋势,过滤掉大量噪音。相比直接在转折点入场,它可以减少被套入场的概率。
另一个优势是设置了止盈逻辑。这使每单交易的盈亏都可控,符合积极的资金管理原则。
最后,追踪止盈大于回调比例也使策略具有一定的风险回报机制。
三、潜在风险
尽管该策略具备一定优势,但实际运用中也应注意以下风险:
首先,回调比例需要谨慎设置。过深或过浅的回调都会影响获利空间。
其次,没有止损设置使策略面临较大的单笔风险。强势趋势反转可能带来较大损失。
最后,参数优化不当也会产生过拟合问题,导致信号质量下降。
四、内容总结
本文详细介绍了一种基于价格回调比例进行趋势追踪的量化策略。它可以有效辨别趋势方向,利用回调进行入场。同时设置止盈管理也使策略具备一定的风控机制。总体来说,该策略以局部高点回调为依据构建交易规则,可成为趋势跟踪策略的选型方案之一。
/*backtest
start: 2022-09-07 00:00:00
end: 2023-09-13 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © luboremenar
//@version=4
strategy("test_%_down_up", overlay = false, initial_capital = 1000, pyramiding = 0, default_qty_value = 1000,
default_qty_type = strategy.cash, precision = 8, commission_type = strategy.commission.percent, commission_value = 0.1)
// inputs
range_of_tops = input(title="Range of candles to find highest value from.", defval=90, type=input.integer, minval=1 )
basis_points = input(title="Basis points, if asset has two decimals use 100, three decimals 1000, etc.", defval=100, type=input.integer, minval=1)
retrace_percent = input(title="Percent value retrace from the top.", type=input.integer, defval=3, minval = 1, maxval=99)
take_profit_percent = input(title="Percent value of take profit from entry price.", type=input.integer, defval=6, minval=1)
// strategy definition
three_months_top = highest(range_of_tops)
longCondition1 = (close <= float((three_months_top*(1-(take_profit_percent/100)))) and strategy.position_size == 0)
if (longCondition1)
strategy.entry("Long1", strategy.long, qty = strategy.equity/close)
strategy.exit(id="TP1", from_entry="Long1", profit=((close*(1 + take_profit_percent/100)-close)*basis_points),
when= crossover(strategy.position_size, 0))
// plot
plot(strategy.equity)
// for testing, debugging
//test=0.0
//if(crossover(strategy.position_size, 0))
// test := (close*1.06-close)*basis_points
//plot(test)