策略回测
/*backtest start: 2021-01-01 09:00:00 end: 2022-06-14 15:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}] args: [["ContractType","hc888",360008]] */ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © ceyhun //@version=4 study("Accurate Swing Trading System",overlay=true) no=input(3,title="摆动") Barcolor=input(true,title="K线BAR颜色着色") Bgcolor=input(false,title="背景着色") res=highest(high,no) sup=lowest(low,no) avd=iff(close>res[1],1,iff(close<sup[1],-1,0)) avn=valuewhen(avd!=0,avd,0) tsl=iff(avn==1,sup,res) Buy=crossover(close,tsl) Sell=crossunder(close,tsl) plotshape(Buy,"BUY", shape.labelup, location.belowbar, color.green, text="BUY",textcolor=color.black) plotshape(Sell,"SELL", shape.labeldown, location.abovebar, color.red, text="SELL",textcolor=color.black) colr = close>=tsl ? color.green : close<=tsl ? color.red : na plot(tsl, color=colr, linewidth=3, title="TSL") barcolor(Barcolor ? colr : na) bgcolor(Bgcolor ? colr :na) alertcondition(Buy, title="Buy Signal", message="Buy") alertcondition(Sell, title="Sell Signal", message="Sell") if Buy strategy.entry("long", strategy.long) else if Sell strategy.entry("short", strategy.short)