SuperTrend历史回测与实时/复盘结果不一致问题求助
问题:SuperTrend策略历史回测与实时/复盘结果不一致
问题描述
- 基于SuperTrend开发的策略,历史回测表现优异,但实时图表或Replay Tool复盘时表现极差,核心逻辑为:SuperTrend显示上涨趋势开多单,下跌趋势开空单
- 测试条件完全一致:3m图表,SuperTrend时间框架设为30m,ATR长度1,Factor1;RRR1.5,止损为前一波段高低点,测试时段均为11月4日
- 核心差异:复盘时SuperTrend趋势切换频率远高于历史回测,胜率和收益数据差距极大
可复现代码
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © marketcalls_in // Rajandran - Founder - Marketcalls / Co-Founder - Algomojo //@version=4 study("Supertrend - Buy or Sell Signal", overlay = true) //inputs Periods = input(title="ATR Period", type=input.integer, defval=10) Source = input(hl2, title="Source") Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0) //Compute ATR Levels atr= atr(Periods) //Creating Upper Channel cclose = security(syminfo.tickerid, "30", close) up=Source-(Multiplier*atr) up1 = nz(up[1],up) up := cclose[1] > up1 ? max(up,up1) : up //Creating Down Channel dn=Source+(Multiplier*atr) dn1 = nz(dn[1], dn) dn := cclose[1] < dn1 ? min(dn, dn1) : dn //Compute the Trend Stream +1/-1 trend = 1 trend := nz(trend[1], trend) trend := trend == -1 and cclose > dn1 ? 1 : trend == 1 and cclose < up1 ? -1 : trend //Create Stoploss for Longs upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green) //Buy Signal Buy = trend == 1 and trend[1] == -1 plotshape(Buy ? up : na, title="Go Long", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0) plotshape(Buy ? up : na, title="Buy", text="Buy Mode", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0) dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red) //Sell Signal Sell = trend == -1 and trend[1] == 1 plotshape(Sell ? dn : na, title="Go Short", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0) plotshape(Sell ? dn : na, title="Sell", text="Sell Mode", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0) iPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0) longFillColor = trend == 1 ? color.green : color.white shortFillColor = trend == -1 ? color.red : color.white fill(iPlot, upPlot, title="UpTrend Highligter", color=longFillColor) fill(iPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor) //Alerts alertcondition(Buy, title="SuperTrend Buy", message="SuperTrend Buy!") alertcondition(Sell, title="SuperTrend Sell", message="SuperTrend Sell!") buycontiue = barssince(Sell) > barssince(Buy) sellcontinue = barssince(Buy) > barssince(Sell) color = buycontiue[1] ? color.green : sellcontinue ? color.red : na barcolor(color)
已排查与临时方案
- 发现部分问题源于
security()函数默认启用barmerge.lookahead_on(未来数据引用),改为barmerge.lookahead_off后差异减小,但未完全解决 - 临时方案:添加趋势切换阈值,待突破反向趋势X%后再确认切换,但未彻底解决问题,寻求彻底解决方案
内容的提问来源于stack exchange,提问作者Zathrus Writer
相关产品推荐
相关产品推荐

