var fibo_ratios = array.new_float(0) var colors = array.new_color(2) if barstate.isfirst array.unshift(colors, upcol) array.unshift(colors, dncol) array.push(fibo_ratios, 0.236) array.push(fibo_ratios, 0.382) array.push(fibo_ratios, 0.618) array.push(fibo_ratios, 0.786)
get_channel(src, len)=> mid = sum(src, len) / len slope = linreg(src, len, 0) - linreg(src, len, 1) intercept = mid - slope * floor(len / 2) + ((1 - (len % 2)) / 2) * slope endy = intercept + slope * (len - 1) dev = 0.0 for x = 0 to len - 1 dev := dev + pow(src[x] - (slope * (len - x) + intercept), 2) dev := sqrt(dev/len) [intercept, endy, dev, slope]
[y1_, y2_, dev, slope] = get_channel(src, len)
outofchannel = (slope > 0 and close < y2_ - dev * devlen) ? 0 : (slope < 0 and close > y2_ + dev * devlen) ? 2 : -1
var reglines = array.new_line(3) var fibolines = array.new_line(4) for x = 0 to 2 if not showbroken or outofchannel != x or nz(outofchannel[1], -1) != -1 line.delete(array.get(reglines, x)) else line.set_color(array.get(reglines, x), color = brokencol) line.set_width(array.get(reglines, x), width = 2) line.set_style(array.get(reglines, x), style = line.style_dotted) line.set_extend(array.get(reglines, x), extend = extend.none)
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.