Fractal Breakout Strategy (by ChartArt)

This long only strategy determines the price of 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 fractal tops to get the trend direction. The strategy exits the long trade, when the average of the fractal tops is falling (when the trend is lower highs as measured by fractals). And the user can manually set a time delay of this exit condition. The default setting is a long strategy exit always 3 bars after the long entry condition appeared.

In addition as gimmicks the fractals tops can be highlighted (the default is blue) and a line can be drawn based on the fractal tops.This fractal top line is colored by the fractal top average trend in combination with the fractal 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 fractal 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.
从常用脚本中删除 添加到常用脚本
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: 
//  __             __  ___       __  ___ 
// /  ` |__|  /\  |__)  |   /\  |__)  |  
// \__, |  | /~~\ |  \  |  /~~\ |  \  |  

// 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[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
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

// 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)


does this repaint?
+8 回复
ps8322 CarlORourke
@CarlORourke, No , it does not repaint.
How does one get access to this?
+7 回复
interesting have you consider testing with lower capital in every trade like $100
+2 回复
you can change the capital in the strategy to your liking.
+1 回复
Awesome strategy. Quick question, does the fractal candle show blue right after it closes, or do a couple of bars have to pass before the fractal candle turns blue? Hope my question makes sense. Thanks!
+1 回复
ChartArt Sigep1901dl
Thank you. The question you asked is a good question. Every technical indicator has a certain lag (length of delay). Most indicators have a lag of around 3-9 bars (moving averages have much more lag), meaning on a monthly chart that you are able to measure the trend direction 3-9 months later after the trend has already changed and if the same indicator with the same setting is used on a 1 hour chart that would mean you see the trend 3-9 hours later after it has happened.

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.
I'm looking at GBPUSD on 5m and getting a good backtest, so want to test this out going forwards with alerts, but I'm getting one every 5 minutes with just the placeholders, regardless of whether a long has been triggered or not. Am I doing something wrong with the alert settings or is it to do with the script, as I don't see any alert code? New here so sorry if this is very obvious!
首页 股票筛选器 外汇筛选器 加密货币筛选器 财经日历 如何运作 图表功能 价格 推荐朋友 网站规则 帮助中心 网站 & 经纪商解决方案 插件 图表解决方案 轻量图表库 博客 & 新闻 Twitter
概览 个人资料设置 账户和账单 推荐朋友 代币 我的客服工单 帮助中心 已发表观点 粉丝 正在关注 私人消息 在线聊天 退出