该策略主要将高低指标、均线指标与超级趋势指标相结合,判断市场趋势而建仓。
通过高低指标判断最近一定周期内价格是否创出新高或新低,并累加得分。当分数上涨时,代表着多头力量增强;当分数下降时,代表着空头力量增强。
通过均线指标,判断价格是否处于由下往上的阶梯型上升趋势,或者由上往下的阶梯型下降趋势。当均线呈现阶梯型上升,代表着多头力量增强;当均线呈现阶梯型下降,代表着空头力量增强。
结合高低指标和均线指标的判断结果,确定市场趋势;再结合超级趋势指标的方向,寻找建仓机会。具体来说,当高低指标和均线指标都显示多头力量增强,且超级趋势指标方向为向下时,进行长仓建仓;当高低指标和均线指标都显示空头力量增强,且超级趋势指标方向为向上时,进行空仓建仓。
高低指标能有效判断价格走势和力量变化,均线指标能有效判断价格趋势,两者结合能更准确判断市场走向。
结合超级趋势指标进行建仓,可避免建仓过早或过晚。超级趋势指标可有效识别价格反转点。
多种指标相互验证,可减少假信号。
若高低指标和均线指标发出错误信号,可能造成亏损建仓。
若参与度不高,超级趋势指标参数设置不当,可能发出错误信号。
若趋势反转过快,止损设置不当,可能造成较大亏损。
可通过优化指标参数,调整止损点位等方式降低风险。
可测试不同类型的均线指标,寻找最佳参数组合。
可优化高低指标和均线指标的参数,使信号更稳定可靠。
可结合其他指标进行验证,如MACD,KD等,减少假信号。
可结合机器学习算法自动优化参数和信号权重。
可结合情绪分析等判断市场热度,避免交易低热度品种。
该策略通过高低指标和均线指标判断市场趋势和力量,再结合超级趋势指标过滤信号,在多空力量对抗且超级趋势指标反转时建仓,实现低风险交易。策略优势在于多指标验证和及时建仓,可有效控制风险。存在的问题在于假信号和趋势判断错误。可通过参数优化、止损设置、信号过滤等多种方式进行改进,使策略更稳健可靠。
/*backtest
start: 2023-10-21 00:00:00
end: 2023-11-20 00:00:00
period: 1h
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/
// © HeWhoMustNotBeNamed
//@version=4
strategy("AlignedMA and Cumulative HighLow Strategy", overlay=true, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01, calc_on_order_fills = true)
MAType = input(title="Moving Average Type", defval="sma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])
includePartiallyAligned = input(true)
HighLowPeriod = input(50, minval=1,step=1)
LookbackPeriod = input(10, minval=1,step=1)
supertrendMult = input(2, minval=1, maxval=10, step=0.5)
supertrendLength = input(10, minval=1)
tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])
backtestYears = input(10, minval=1, step=1)
f_getMovingAverage(source, MAType, length)=>
ma = sma(source, length)
if(MAType == "ema")
ma := ema(source,length)
if(MAType == "hma")
ma := hma(source,length)
if(MAType == "rma")
ma := rma(source,length)
if(MAType == "vwma")
ma := vwma(source,length)
if(MAType == "wma")
ma := wma(source,length)
ma
f_getMaAlignment(MAType, includePartiallyAligned)=>
ma5 = f_getMovingAverage(close,MAType,5)
ma10 = f_getMovingAverage(close,MAType,10)
ma20 = f_getMovingAverage(close,MAType,20)
ma30 = f_getMovingAverage(close,MAType,30)
ma50 = f_getMovingAverage(close,MAType,50)
ma100 = f_getMovingAverage(close,MAType,100)
ma200 = f_getMovingAverage(close,MAType,200)
upwardScore = 0
upwardScore := close > ma5? upwardScore+1:upwardScore
upwardScore := ma5 > ma10? upwardScore+1:upwardScore
upwardScore := ma10 > ma20? upwardScore+1:upwardScore
upwardScore := ma20 > ma30? upwardScore+1:upwardScore
upwardScore := ma30 > ma50? upwardScore+1:upwardScore
upwardScore := ma50 > ma100? upwardScore+1:upwardScore
upwardScore := ma100 > ma200? upwardScore+1:upwardScore
upwards = close > ma5 and ma5 > ma10 and ma10 > ma20 and ma20 > ma30 and ma30 > ma50 and ma50 > ma100 and ma100 > ma200
downwards = close < ma5 and ma5 < ma10 and ma10 < ma20 and ma20 < ma30 and ma30 < ma50 and ma50 < ma100 and ma100 < ma200
upwards?1:downwards?-1:includePartiallyAligned ? (upwardScore > 5? 0.5: upwardScore < 2?-0.5:upwardScore>3?0.25:-0.25) : 0
f_getHighLowValue(HighLowPeriod)=>
currentHigh = highest(high,HighLowPeriod) == high
currentLow = lowest(low,HighLowPeriod) == low
currentHigh?1:currentLow?-1:0
inDateRange = time >= timestamp(syminfo.timezone, year(timenow) - backtestYears, 01, 01, 0, 0)
maAlignment = f_getMaAlignment(MAType,includePartiallyAligned)
alignedMaIndex = sum(maAlignment,LookbackPeriod)
maAlignmentDirection = alignedMaIndex > alignedMaIndex[1] ? 1 : alignedMaIndex < alignedMaIndex[1] ? -1 : 0
maAlignmentDirection := maAlignmentDirection == 0? nz(maAlignmentDirection[1],0):maAlignmentDirection
highLowIndex = f_getHighLowValue(HighLowPeriod)
cumulativeHighLowIndex = sum(highLowIndex,LookbackPeriod)
hlDirection = cumulativeHighLowIndex > cumulativeHighLowIndex[1] ? 1 : cumulativeHighLowIndex < cumulativeHighLowIndex[1] ? -1 : 0
hlDirection := hlDirection == 0? nz(hlDirection[1],0):hlDirection
[superTrend, dir] = supertrend(supertrendMult, supertrendLength)
buyEntry = (dir == -1 and maAlignmentDirection == 1 and hlDirection == 1)
sellEntry = (dir == 1 and maAlignmentDirection == -1 and hlDirection == -1)
barColor = buyEntry?color.lime:sellEntry?color.orange:color.gray
barcolor(barColor)
// strategy.risk.allow_entry_in(tradeDirection)
strategy.entry("Buy", strategy.long, when=barColor == color.lime and inDateRange, oca_name="oca_buy")
strategy.close("Buy", when=dir == 1)
strategy.entry("Sell", strategy.short, when=barColor == color.orange and inDateRange, oca_name="oca_sell")
strategy.close("Sell", when=dir == -1)