资源加载中... loading...

标记反转点策略

Author: 雨幕(youquant), Date: 2022-06-13 10:29:20
Tags: Reversal

回测测试

img

img

img


/*backtest
start: 2022-01-01 09:00:00
end: 2022-06-12 15:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["v_input_int_1",12],["v_input_int_2",12],["ContractType","rb888",360008]]
*/

//@version=5
// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)
// Demark Reversal Points [CC] script may be freely distributed under the MIT license.
indicator('Demark Reversal Points [CC]', max_bars_back=3000, overlay=true)

inp = input(title='数据源', defval=close)
res = input.timeframe(title='时间解析度', defval='')
rep = input(title='允许重新绘制?', defval=false)
bar = input(title='允许修改BAR颜色?', defval=true)
src = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length = input.int(title='周期', defval=9, minval=1)
lbLength = input.int(title='Lb周期', defval=4, minval=1)

uCount = 0
dCount = 0
for i = 0 to length - 1 by 1
    uCount += (nz(src[i]) > nz(src[i + lbLength]) ? 1 : 0)
    dCount += (nz(src[i]) < nz(src[i + lbLength]) ? 1 : 0)
    dCount

drp = dCount == length ? 1 : uCount == length ? -1 : 0

sig = drp > 0 or uCount > dCount ? 1 : drp < 0 or dCount > uCount ? -1 : 0
drpColor = sig > 0 ? color.green : sig < 0 ? color.red : color.black
alertcondition(ta.crossover(drp, 0), 'Buy Signal', 'Bullish Change Detected')
alertcondition(ta.crossunder(drp, 0), 'Sell Signal', 'Bearish Change Detected')
barcolor(bar ? drpColor : na)
plotshape(ta.crossover(drp, 0), 'Buy', shape.labelup, location.belowbar, color.new(color.green, 0), text='Buy', textcolor=color.new(color.white, 0))
plotshape(ta.crossunder(drp, 0), 'Sell', shape.labeldown, location.abovebar, color=color.new(color.red, 0), text='Sell', textcolor=color.new(color.white, 0))
buy=ta.crossover(drp, 0),
sell=ta.crossunder(drp, 0)
if buy
   strategy.entry("buy", strategy.long)
else if sell
    strategy.entry("sell", strategy.short)



相关内容

更多内容