In addition as gimmicks the fractals tops can be highlighted (the default is blue) and a line can be drawn based on the tops.This top line is colored by the top average trend in combination with the breakout condition.
This strategy works better on higher time-frames (weekly and monthly), but it also works on the daily and some other time-frames. This strategy does not repaint, no repainting.
P.S. I thank Tradingview user barracuda who helped me with the time based exit condition code. And user RicardoSantos for coding the definition of the top, which he uses in his "Fractals" scripts.
All trading involves high risk; past performance is not necessarily indicative of future results. Hypothetical or simulated performance results have certain inherent limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not actually been executed, the results may have under- or over-compensated for the impact , if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown.
진정한 TradingView의 정신에 따라, 이 스크립트의 작성자는 스크립트를 오픈소스로 게시했기에 거래자들이 이해하고 확인할 수 있습니다. 작가님께 건배! 스크립트를 무료로 사용할 수 있지만, 게시물에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 당신은 스크립트를 차트에 사용하기 위해 그것을 즐겨찾기 할 수 있습니다.
//@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, type=integer) 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 > high and high > high and high > high and high > high 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 + fractal_price + fractal_price ) / 3 : (fractal_price + fractal_price) / 2 fractal_trend = fractal_average > fractal_average no_repainting = input(true,title='Use the price of the last bar to prevent repainting?') fractal_breakout = no_repainting?price > fractal_price:price > fractal_price // 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')
This fractal indicator has a minimum lag of 3 bars, meaning the earliest this strategy can go long is on the bar number 4 after a certain combination of recent highs and lows has appeared (as signaled by the blue colored fractal top). In addition there is the calculation of the fractal average which might add more lag, which is why I made the option in the strategy to use more or less fractals to determine the average of them. Therefore it takes 3 bars until a candle can turn blue. And it could take in some cases longer until the strategy goes long due to the extra calculation of fractal averages.