
阳光超级趋势策略是一种基于ATR和SuperTrend指标的趋势跟踪策略。它可以准确预测趋势反转,非常适合作为时序指标使用。该策略可以增强投资者的耐心和定力,帮助它们在合适的时机进入和退出市场。
该策略使用SuperTrend指标判断当前趋势方向。当SuperTrend指标发生方向变化时,我们认为可能发生了趋势反转。此外,策略还使用K线实体的方向进行辅助判断。当潜在反转信号出现而K线实体的方向与此前一致时,过滤掉无效信号。
具体来说,策略根据以下逻辑生成交易信号: 1. 使用SuperTrend指标判断主要趋势方向 2. 当SuperTrend指标方向发生变化时,产生潜在反转信号 3. 如果此时K线实体方向与之前一致,过滤掉该反转信号 4. 如果K线实体方向发生变化,确认反转信号,产生交易信号
阳光超级趋势策略是一种基于SuperTrend指标判断趋势反转的高效策略。它结合K线实体方向进行辅助判断,能有效过滤无效信号,提高信号质量。该策略操作简单,适应性强,可广泛应用于多个品种和时间周期。通过合理参数优化和止损机制增加,可以进一步提升策略表现。
/*backtest
start: 2023-11-12 00:00:00
end: 2023-12-12 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Sunny Supertrend Strategy", overlay=true, default_qty_type=strategy.percent_of_equity)
atrPeriod = input(10, "ATR Length")
factor = input.float(3.0, "Factor", step = 0.01)
[_, direction] = ta.supertrend(factor, atrPeriod)
shor= close > open and close[1] > open[1] and close[2] > open[2]
lon = open > close and open[1] > close[1] and open[2] > close[2]
tt= ta.change(direction) < 0
ss= ta.change(direction) > 0
long= tt
longexit = lon or ss
short= ss
shortexit = shor or tt
longPosMem = false
longexitPosMem = false
shortPosMem = false
shortexitPosMem = false
longPosMem := long ? true : short ? false : longPosMem[1]
longexitPosMem := longexit ? true : shortexit ? false : longexitPosMem[1]
shortPosMem := short ? true : long ? false : shortPosMem[1]
shortexitPosMem := shortexit ? true : longexit ? false : shortexitPosMem[1]
longy = long and not(longPosMem[1])
longexity = longexit and not(longexitPosMem[1])
shorty = short and not(shortPosMem[1])
shortexity = shortexit and not(shortexitPosMem[1])
//Use this to customize the look of the arrows to suit your needs.
plotshape(longy, location=location.abovebar, color=color.green, style=shape.arrowup, text="Buy")
plotshape(longexity, location=location.top, color=color.green, style=shape.xcross, text="Buy exit")
plotshape(shorty, location=location.belowbar, color=color.red, style=shape.arrowdown, text="Sell")
plotshape(shortexity, location=location.bottom, color=color.red, style=shape.xcross, text="Sell exit")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
// STEP 1:
// Make input options that configure backtest date range
startDate = input.int(title="Start Date", defval=1, minval=1, maxval=31)
startMonth = input.int(title="Start Month",
defval=1, minval=1, maxval=12)
startYear = input.int(title="Start Year",
defval=2021, minval=1800, maxval=2100)
endDate = input.int(title="End Date",
defval=1, minval=1, maxval=31)
endMonth = input.int(title="End Month",
defval=2, minval=1, maxval=12)
endYear = input.int(title="End Year",
defval=2021, minval=1800, maxval=2100)
// STEP 2:
// Look if the close time of the current bar
// falls inside the date range
inDateRange = true
// STEP 3:
// Submit entry orders, but only when bar is inside date range
if (inDateRange and longy)
strategy.entry("enter long",strategy.long,when= longy)
strategy.close("long",when=longexity)
if (inDateRange and shorty)
strategy.entry("enter short",strategy.short,when = shorty)
strategy.close("short", when=shortexity)