谱龄策略是一种基于价格通道的趋势跟踪策略。它使用快速和慢速的唐奇安通道来识别趋势方向,并在回调时进行逢低买入和逢高卖出。该策略优点是可以自动跟踪趋势,在趋势变化时及时止损和反向开仓。但也存在回撤和止损点过于接近的风险。
该策略首先定义快速通道周期为20根K线,慢速通道周期为50根K线。快速通道用于设置止损价格,慢速通道用于判断趋势方向和入场时机。
策略首先计算快速通道的最高价和最低价,并取中线作为止损线。同时计算慢速通道的最高价和最低价,通道上沿和下沿作为入场线。
当价格突破慢速通道上沿时,做多;当价格突破慢速通道下沿时,做空。入场后,止损点设在快速通道中线。
这样,慢速通道判断大趋势方向,快速通道跟踪小范围内突破判断止损点。当大趋势反转时,价格会首先突破快速通道止损线,实现止损。
自动跟踪趋势,及时止损。使用双通道结构,可以自动跟踪趋势,在趋势反转时快速止损。
回调开仓,具有一定的趋势过滤效果。只在价格突破通道边界时开仓,可以滤除部分非趋势性假突破。
风险可控。止损距离较近,可以控制单笔损失。
回撤较大。趋势跟踪策略回撤可以较大,需要有心理准备。
止损点过于接近。快速通道周期较短,止损距离较近,容易被套。可以适当放宽快速通道周期。
容易产生过多交易。双通道结构导致买卖点较多,需要合理控制仓位。
增加开仓过滤条件。可以在开仓条件中加入volatility等指标,过滤趋势性不强的突破。
优化通道周期参数。可以通过更系统的方法寻找最优通道参数组合。
结合多个时间周期决策。可以在更高时间周期确定大趋势,在较低周期进行具体交易。
动态调整止损距离。可以根据市场波动程度动态调整止损距离。
谱龄策略整体是一个较为标准的趋势跟踪策略。它利用价格通道判断趋势方向,并设定止损来控制风险。该策略具有一定的优势,但也存在回撤和止损点过近的问题。通过优化通道参数、增加过滤条件等方法,可以获得更好的策略效果。但需要注意的是,趋势跟踪策略对交易者的心态要求较高,需要做好回撤的心理准备。
/*backtest
start: 2023-09-30 00:00:00
end: 2023-10-30 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//Noro
//2020
//@version=4
strategy("Noro's RiskTurtle Strategy", shorttitle = "RiskTurtle str", overlay = true, default_qty_type = strategy.percent_of_equity, initial_capital = 100, default_qty_value = 100, commission_value = 0.1)
//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
risk = input(2, minval = 0.1, maxval = 99, title = "Risk size, %")
fast = input(20, minval = 1, title = "Fast channel (for stop-loss)")
slow = input(50, minval = 1, title = "Slow channel (for entries)")
showof = input(true, defval = true, title = "Show offset")
showll = input(true, defval = true, title = "Show lines")
showdd = input(true, defval = true, title = "Show label (drawdown)")
showbg = input(true, defval = true, title = "Show background")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")
//Donchian price channel fast
hf = highest(high, fast)
lf = lowest(low, fast)
center = (hf + lf) / 2
//Donchian price chennal slow
hs = highest(high, slow)
ls = lowest(low, slow)
//Lines
colorpc = showll ? color.blue : na
colorsl = showll ? color.red : na
offset = showof ? 1 : 0
plot(hs, offset = offset, color = colorpc, title = "Slow channel high")
plot(ls, offset = offset, color = colorpc, title = "Slow channel low")
plot(center, offset = offset, color = colorsl, title = "Fast channel stop-loss")
//Background
size = strategy.position_size
colorbg = showbg == false ? na : size > 0 ? color.lime : size < 0 ? color.red : na
bgcolor(colorbg, transp = 70)
//Var
loss = 0.0
maxloss = 0.0
equity = 0.0
truetime = true
//Lot size
risksize = -1 * risk
risklong = ((center / hs) - 1) * 100
coeflong = abs(risksize / risklong)
lotlong = (strategy.equity / close) * coeflong
riskshort = ((center / ls) - 1) * 100
coefshort = abs(risksize / riskshort)
lotshort = (strategy.equity / close) * coefshort
//Orders
strategy.entry("Long", strategy.long, lotlong, stop = hs, when = needlong and strategy.position_size == 0 and hs > 0 and truetime)
strategy.entry("Short", strategy.short, lotshort, stop = ls, when = needshort and strategy.position_size == 0 and ls > 0 and truetime)
strategy.exit("LongExit", "Long", stop = center, when = needlong and strategy.position_size > 0)
strategy.exit("Short", stop = center, when = needshort and strategy.position_size < 0)
if time > timestamp(toyear, tomonth, today, 23, 59)
strategy.close_all()
strategy.cancel("Long")
strategy.cancel("Short")
if showdd
//Drawdown
max = 0.0
max := max(strategy.equity, nz(max[1]))
dd = (strategy.equity / max - 1) * 100
min = 100.0
min := min(dd, nz(min[1]))
//Max loss size
equity := strategy.position_size == 0 ? strategy.equity : equity[1]
loss := equity < equity[1] ? ((equity / equity[1]) - 1) * 100 : 0
maxloss := min(nz(maxloss[1]), loss)
//Label
min := round(min * 100) / 100
maxloss := round(maxloss * 100) / 100
labeltext = "Drawdown: " + tostring(min) + "%" + "\nMax.loss " + tostring(maxloss) + "%"
var label la = na
label.delete(la)
tc = min > -100 ? color.white : color.red
osx = timenow + round(change(time)*10)
osy = highest(100)
// la := label.new(x = osx, y = osy, text = labeltext, xloc = xloc.bar_time, yloc = yloc.price, color = color.black, style = label.style_labelup, textcolor = tc)