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

Chande Kroll 止损

Author: 雨幕(youquant), Date: 2022-06-01 15:56:37
Tags: ADX

亲爱的优宽er们:,

在此,我编写了一个脚本,其中我使用了被低估的chande kroll止损指示器创建了一个简单的策略。短线信号是指橙色线下的近线交叉,蓝线的近线蜡烛交叉时产生长信号。 此外,您还可以选择使用ADX进行过滤,从而在动荡的市场中最大限度地减少重复次数。

祝你交易好运!

回测测试

img

img

img


/*backtest
start: 2021-12-01 00:00:00
end: 2022-05-31 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["ContractType","rb2210",360008]]
*/

//@version=5
strategy(title = "Chande Kroll Stop", overlay=true)
p = input.int(10, minval=1, title="Chande Kroll Stop的p值")
x = input.int(1, minval=1, title="Chande Kroll Stop的x值")
q = input.int(9, minval=1, title="Chande Kroll Stop的q值")
first_high_stop = ta.highest(high, p) - x * ta.atr(p)
first_low_stop = ta.lowest(low, p) + x * ta.atr(p)
stop_short = ta.highest(first_high_stop, q)
stop_long = ta.lowest(first_low_stop, q)
plot(stop_long, color=color.blue)
plot(stop_short, color=color.orange)

adxlen = input(14, title="ADX 平滑")
dilen = input(14, title="DI 周期")
ADX_sig = input.int(20, title="信号的最小ADX阈值")
dirmov(len) =>
	up = ta.change(high)
	down = -ta.change(low)
	plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
	minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
	truerange = ta.rma(ta.tr, len)
	plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
	minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
	[plus, minus]
adx(dilen, adxlen) =>
	[plus, minus] = dirmov(dilen)
	sum = plus + minus
	adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)


if ta.crossunder(close, stop_long) and sig>ADX_sig
    strategy.entry("long", strategy.long)
if ta.crossover(close, stop_short) and sig>ADX_sig
    strategy.entry("short", strategy.short)
template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6