黄金VWAP MACD SMO交易策略是一个在12小时时间周期下设计的完整交易策略。它结合了VWAP月线、SMO振荡器和MACD指标来识别黄金市场的交易机会。
该策略使用VWAP月线作为主要的趋势指标。VWAP代表价格的平均成交价,月线意味着计算VWAP的时间范围是过去一个月。如果当前收盘价高于VWAP月线,那么表明目前是处于趋势上涨的阶段;如果收盘价低于VWAP月线,则意味着趋势正在下跌。
SMO振荡器则用来判断目前的超买超卖情况。它由一个长周期组分和一个短周期组分构成。当振荡器高于0时表示处于超买状况,而低于0时则代表超卖。
而MACD直方图可以判断动量方向。当柱子向上突破时,代表动量正转强劲,可以做多;当柱子向下突破时,意味着动量转弱,应该考虑做空。
根据这三个指标,可以建立交易策略的具体规则:
多头进入:当收盘价高于VWAP月线,MACD直方柱上涨突破,且SMO振荡器高于0时做多 空头进入:当收盘价低于VWAP月线,MACD直方柱下跌突破,且SMO振荡器低于0时做空
止盈止损根据输入的百分比设置。
该策略结合多个时间范围和指标,可以有效判断趋势方向和力度,具有如下优势:
尽管该策略设计合理,但仍存在一定的风险需要注意:
为控制上述风险,应该合理优化VWAP和MACD的参数,幅度不宜过大。同时,止盈止损比例不宜过大,应控制单笔亏损在3%左右为宜。
该策略还可从以下方面进行优化:
黄金VWAP MACD SMO策略综合多个指标判断趋势和超买超卖情况,可以有效抓住黄金的中长线机会。虽有一定的风险,但可通过参数优化和风控手段进行控制。该策略具有非常强大的延展性,可根据实际需要进行模块化优化,是一套值得长期跟踪的交易系统。
/*backtest
start: 2023-09-19 00:00:00
end: 2023-10-19 00:00:00
period: 4h
basePeriod: 15m
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/
// © exlux99
//@version=4
// strategy("VWAP Gold strategy", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 10000, calc_on_every_tick = true, commission_type = strategy.commission.percent, commission_value = 0.005)
source = input(low)
//vwap monthly
timeframeM = time("M")
beginningM = na(timeframeM[1]) or timeframeM > timeframeM[1]
sumsourceM = source * volume
sumVolM = volume
sumsourceM := beginningM ? sumsourceM : sumsourceM + sumsourceM[1]
sumVolM := beginningM ? sumVolM : sumVolM + sumVolM[1]
vwapMonthly= sumsourceM / sumVolM
//macd
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
src = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
fast_ma = ema(src, fast_length)
slow_ma = ema(src, slow_length)
macd = fast_ma - slow_ma
signal = ema(macd, signal_length)
hist = macd - signal
//SMO
longlen = input(22, minval=1, title="Long Length SMO")
shortlen = input(6, minval=1, title="Short Length SMO")
siglen = input(5, minval=1, title="Signal Line Length SMO")
erg = tsi(close, shortlen, longlen)
sig = ema(erg, siglen)
osc = erg - sig
shortCondition = close < vwapMonthly and hist < hist[1] and osc < 0
longCondition = close > vwapMonthly and hist> hist[1] and osc > 0
tplong=input(0.085, step=0.005, title="Take profit % for long")
sllong=input(0.03, step=0.005, title="Stop loss % for long")
tpshort=input(0.05, step=0.005, title="Take profit % for short")
slshort=input(0.025, step=0.005, title="Stop loss % for short")
strategy.entry("long",1,when=longCondition)
strategy.entry("short",0,when=shortCondition)
strategy.exit("short_tp/sl", "long", profit=close * tplong / syminfo.mintick, loss=close * sllong / syminfo.mintick, comment='LONG EXIT', alert_message = 'closeshort')
strategy.exit("short_tp/sl", "short", profit=close * tpshort / syminfo.mintick, loss=close * slshort / syminfo.mintick, comment='SHORT EXIT', alert_message = 'closeshort')