三重超级趋势策略

Author: 雨幕(youquant), Date: 2022-05-27 14:06:21
Tags: supertrendATR

第一重 超级趋势 参数:周期12,系数1 第二重 超级趋势 参数:周期8, 系数2 第三重 超级趋势 参数:周期5, 系数3

回测测试

img

img

img


/*backtest
start: 2022-01-01 00:00:00
end: 2022-05-09 23:59:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["ContractType","i2209",360008]]
*/

//@version=5
indicator("Supertrend", overlay=true, timeframe="", timeframe_gaps=true)

NEW1_atrPeriod = input(12, "ATR1周期")
NEW1_factor = input.float(1.0, "ATR1系数", step = 0.01)

[supertrend_1, direction_1] = ta.supertrend(NEW1_factor, NEW1_atrPeriod)

bodyMiddle_1 = plot((open + close) / 2, display=display.none)

upTrend_1 = plot(direction_1 < 0 ? supertrend_1 : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend_1 = plot(direction_1 < 0? na : supertrend_1, "Down Trend", color = color.red, style=plot.style_linebr)

fill(bodyMiddle_1, upTrend_1, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle_1, downTrend_1, color.new(color.red, 90), fillgaps=false)


NEW2_atrPeriod = input(8, "ATR2周期")
NEW2_factor = input.float(2.0, "ATR2系数", step = 0.01)

[supertrend_2, direction_2] = ta.supertrend(NEW2_factor, NEW2_atrPeriod)

bodyMiddle_2 = plot((open + close) / 2, display=display.none)
upTrend_2 = plot(direction_2 < 0 ? supertrend_2 : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend_2 = plot(direction_2 < 0? na : supertrend_2, "Down Trend", color = color.red, style=plot.style_linebr)

fill(bodyMiddle_2, upTrend_2, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle_2, downTrend_2, color.new(color.red, 90), fillgaps=false)


NEW3_atrPeriod = input(5, "ATR3周期")
NEW3_factor = input.float(3.0, "ATR3系数", step = 0.01)

[supertrend_3, direction_3] = ta.supertrend(NEW3_factor, NEW3_atrPeriod)

bodyMiddle_3 = plot((open + close) / 2, display=display.none)
upTrend_3 = plot(direction_3 < 0 ? supertrend_3 : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend_3 = plot(direction_3 < 0? na : supertrend_3, "Down Trend", color = color.red, style=plot.style_linebr)

fill(bodyMiddle_3, upTrend_3, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle_3, downTrend_3, color.new(color.red, 90), fillgaps=false)



if direction_1<0 and direction_2 <0 and direction_3 <0
    strategy.entry("Enter Long", strategy.long)
else if direction_1>0 and direction_2 >0 and direction_3 >0
    strategy.entry("Enter Short", strategy.short)

相关内容

更多内容