
本策略基于著名交易专家比尔·威廉姆斯设计的威廉指标中的精妙震荡器(Awesome Oscillator,简称AO),通过计算不同周期的中价均线的差值,形成诊断趋势和市场动量的震荡指标,并设计了相应的交易信号来指导买入卖出。
该策略的核心指标是精妙震荡器(AO),其计算公式为: AO = SMA(中价, 5日) - SMA(中价, 34日) 其中,中价定义为(最高价+最低价)/2。该公式从两个不同周期的中价SMA中抽取价格动量信息。通过计算快线SMA(5日)和慢线SMA(34日)的差值,当快线高于慢线时为买入信号,当快线低于慢线时为卖出信号。
在本策略中,为了滤波误差信号,又对AO进行了5日SMA操作。并设置了一个反转模式,可以通过反转long/short信号来实现不同的交易方向。当AO值高于之前时,视为买入机会,标记为蓝色柱状;当AO值不高于之前时,视为卖出机会,标记为红色柱状。
本策略利用中价快慢SMA结构设计的精妙震荡器,对市场动量变化进行诊断,买卖信号直观明了。但可能受到震荡和反转的影响,需适当调整参数和止损策略以提高稳定性。在控制风险的前提下,该策略简单实用,值得进一步优化应用。
/*backtest
start: 2022-12-11 00:00:00
end: 2023-12-17 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 28/12/2016
// This indicator plots the oscillator as a histogram where blue denotes
// periods suited for buying and red . for selling. If the current value
// of AO (Awesome Oscillator) is above previous, the period is considered
// suited for buying and the period is marked blue. If the AO value is not
// above previous, the period is considered suited for selling and the
// indicator marks it as red.
//
// 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("Bill Williams. Awesome Oscillator (AC)")
nLengthSlow = input(34, minval=1, title="Length Slow")
nLengthFast = input(5, minval=1, title="Length Fast")
reverse = input(false, title="Trade reverse")
xSMA1_hl2 = sma(hl2, nLengthFast)
xSMA2_hl2 = sma(hl2, nLengthSlow)
xSMA1_SMA2 = xSMA1_hl2 - xSMA2_hl2
xSMA_hl2 = sma(xSMA1_SMA2, nLengthFast)
nRes = xSMA1_SMA2 - xSMA_hl2
cClr = nRes > nRes[1] ? blue : red
pos = iff(nRes > nRes[1], 1,
iff(nRes < nRes[1], -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, style=histogram, linewidth=1, color=cClr)