本策略名称为“基于价格去趋势振荡器的量化交易策略”(Detrended Price Oscillator Quantitative Trading Strategy)。该策略通过构建价格去趋势振荡器指标,并以其为基础发出交易信号,属于典型的技术指标策略。
该策略的核心是价格去趋势振荡器(DPO)指标。DPO指标类似于移动平均线,可以滤除价格中较长周期的趋势,使得价格中的周期性波动更加明显。具体来说,DPO指标是将价格与其N日简单移动平均线进行对比,当价格高于移动平均线时,DPO为正;当价格低于移动平均线时,DPO为负。这样就得到了一个振荡在0轴左右的指标。我们可以以DPO指标的正负来判断价格相对于趋势的涨跌。
本策略设置参数N为14,构建14日DPO指标。当DPO指标为正,则发出做多信号;当DPO指标为负,则发出做空信号。
为降低风险,可以考虑以下几个方面进行优化: 1. 加入止损机制,控制单笔损失。 2. 调整参数N的值,寻找最优参数。 3. 结合趋势指标,避免在明确趋势下仍按原策略交易。
本策略基于价格去趋势振荡器指标发出交易信号。该指标通过与移动平均线比较,滤除价格中的长周期趋势,使得价格周期性特征更加明显。这有助于发现一些不易察觉的交易机会。同时也存在参数选择敏感、止损及过滤等问题。通过不断优化,该策略的效果还有很大提升空间。
/*backtest
start: 2023-11-16 00:00:00
end: 2023-11-20 08:00:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 31/03/2017
// The Detrend Price Osc indicator is similar to a moving average,
// in that it filters out trends in prices to more easily identify
// cycles. The indicator is an attempt to define cycles in a trend
// by drawing a moving average as a horizontal straight line and
// placing prices along the line according to their relation to a
// moving average. It provides a means of identifying underlying
// cycles not apparent when the moving average is viewed within a
// price chart. Cycles of a longer duration than the Length (number
// of bars used to calculate the Detrend Price Osc) are effectively
// filtered or removed by the oscillator.
//
// You can change long to short in the Input Settings
// Please, use it only for learning or paper trading. Do not for real trading.
////////////////////////////////////////////////////////////
strategy(title="Detrended Price Oscillator", shorttitle="DPO")
Length = input(14, minval=1)
Series = input(title="Price", defval="close")
reverse = input(false, title="Trade reverse")
hline(0, color=green, linestyle=line)
xPrice = close
xsma = sma(xPrice, Length)
nRes = xPrice - xsma
pos = iff(nRes > 0, 1,
iff(nRes < 0, -1, nz(pos[1], 0)))
possig = iff(reverse and pos == 1, -1,
iff(reverse and pos == -1, 1, pos))
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(nRes, color=red, title="Detrended Price Oscillator")