该策略是一种判断价格趋势的长线趋势跟踪策略。它通过计算历史价格的分形点,判断最后一个分形点的突破来决定建仓。同时,它通过计算最后N个分形点的平均价来判断趋势方向,当趋势转向时平仓。
这种基于分形点判断趋势的策略,最大的优势是能有效过滤市场噪音,判断更长线的趋势方向。相比简单的移动平均线等指标,它对突发异常波动的抵抗能力更强。
另外,该策略判断建仓和平仓标准非常明确,不会出现频繁交易的问题。这也使得它特别适合长线持有。
这种策略最大的风险在于分形点本身判断的概率性。分形点无法百分百预判价格必然反转,也就是说判断错误的概率依然存在。当出现错判时,将面临亏损的风险。
此外,分形点判断的时间跨度较长,不能适应高频交易。如果追求短线交易,这种策略也不太适合。
考虑到分形点判断的误差概率,我们可以通过以下几个方法优化:
结合其他指标确认,如布林线通道、移动平均线等,避免单一分形点判断错误。
调整分形点的参数,如判断的前后周期数量,来优化分形点的判断。
增加止损策略,在亏损扩大到一定程度时止损。
该突破型分形策略整体来说非常适合判断长线趋势,也十分适合长线投资者使用。我们只需要在确保判断准确率的前提下,适当调整参数,增加其他过滤指标,就可以大幅优化该策略,使其成为量化Decision的重要组成部分。
/*backtest
start: 2023-11-18 00:00:00
end: 2023-12-18 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy("Fractal Breakout Strategy (by ChartArt)", shorttitle="CA_-_Fractal_Breakout_Strat", overlay=true)
// ChartArt's Fractal Breakout Strategy
//
// Version 1.0
// Idea by ChartArt on April 24, 2016.
//
// This long only strategy determines the last fractal top
// and enters a trade when the price breaks above the last
// fractal top. The strategy also calculates the average
// price of the last 2 (or 3) fractal tops to get the trend.
//
// The strategy exits the long trade when the average of the
// fractal tops is falling (when the trend is lower highs).
// And the user can manually set a delay of this exit.
//
// In addition the fractals tops can be colored in blue
// and a line can be drawn based on the fractal tops.
// This fractal top line is colored by the fractal trend.
//
// List of my work:
// https://www.tradingview.com/u/ChartArt/
//
// __ __ ___ __ ___
// / ` |__| /\ |__) | /\ |__) |
// \__, | | /~~\ | \ | /~~\ | \ |
//
//
// input
n_time = input(title='Always exit each trade after this amount of bars later (Most important strategy setting)', defval=3)
price = input(hl2,title='Price type to determine the last fractal top and the fractal breakout, the default is (high+low)/2')
// fractal calculation
fractal_top = high[2] > high[3] and high[2] > high[4] and high[2] > high[1] and high[2] > high[0]
fractal_price = valuewhen(fractal_top, price, 1)
use_longer_average = input(true,title='Use Fractal price average of the last 3 fractals instead of the last 2 fractals?')
fractal_average = use_longer_average?(fractal_price[1] + fractal_price[2] + fractal_price[3] ) / 3 : (fractal_price[1] + fractal_price[2]) / 2
fractal_trend = fractal_average[0] > fractal_average[1]
no_repainting = input(true,title='Use the price of the last bar to prevent repainting?')
fractal_breakout = no_repainting?price[1] > fractal_price[0]:price[0] > fractal_price[0]
// highlight fractal tops
show_highlight = input(true,title='Highlight fractal tops in blue and color all other bars in gray?')
highlight = fractal_top?blue:silver
barcolor(show_highlight?highlight:na,offset=-2)
show_fractal_top_line = input(true,title='Draw a colored line based on the fractal tops?')
fractal_top_line = change(fractal_top) != 0 ? price : na
fractal_top_line_color = change(fractal_price) > 0 and fractal_breakout == true ? green : change(fractal_price) < 0 and fractal_breakout == false ? red : blue
plot(show_fractal_top_line?fractal_top_line:na,offset=-2,color=fractal_top_line_color,linewidth=4)
// strategy
trade_entry = fractal_trend and fractal_breakout
trade_exit = fractal_trend[n_time] and fractal_trend == false
if (trade_entry)
strategy.entry('Long', strategy.long)
if (trade_exit)
strategy.close('Long')