//@Name:SE Channel Auto Log Form //@Description:Standard Error Channel from highest to lowest (or lowest to highest) of the linear regression. /*In effect an automatically chosen Partial Trend in Sharescopespeak. The peak and valley of the channel are chosen to be the latest highest high of the past lb lookback periods and similarly the lowest low. I most often find 35 to be value where I drew partial trends, but choose your own. 7 bars can be useful for following the latest swing. This version for log charts. If you use an arithmetic scale you will need the arithmetic version or your channels will be curved and not apparently parallel. Try putting a weekly and a daily version on the same chart.*/ //this code by Roger Harmer //@Future:Yes var mult = 2;//how many standard errors var lb = 35;//maximum of minimum price channel function init() { setTitle("SE Channel"); setRange(Range.Parent); setSeriesColour(0, Colour.Blue); setSeriesLineStyle(0, Pen.Solid); setSeriesColour(1, Colour.Blue); setSeriesLineStyle(1, Pen.Solid); setSeriesColour(2, Colour.Black); setSeriesLineStyle(2, Pen.Dot); } function getGraph(share, data) { var sterr = new Array();// standard error var grad = new Array();//slope var trhi = new Array();//upper channel line var trlo = new Array();//lower channel line var trmid = new Array();//linear regression line var mx, mn, posmx, posmn, tlen, last, first; var trendline = new Array();//the linear trendline var noresult = new Array(); var counthi, countlo; var num = 0; var tlexp = new Array(); var trhiexp = new Array(); var trloexp = new Array(); counthi = countlo = 0; mx = mn = data[data.length - 1].close; posmx = posmn = data.length - 1; // Find highest high of lb bars while (counthi < lb) { num++; if (num > data.length - 1) return noresult; if (data[data.length - 1 - num].close <= mx) counthi++; if (data[data.length - 1 - num].close > mx) { mx = data[data.length -1 - num].close; posmx = data.length -1 - num; counthi = 0; } } // Find lowest low of lb bars num = 0; while (countlo < lb) { num++; if (num > data.length - 1) return noresult; if (data[data.length - 1 - num].close >= mn) countlo++; if (data[data.length - 1 - num].close < mn) { mn = data[data.length - 1 - num].close; posmn = data.length -1 - num; countlo = 0; } } // Find first and last positions and trend length last = Math.max(posmn, posmx); first = Math.min(posmn, posmx); tlen = last - first; if (first == last) return noresult; //Calculate trend values and slope and standard deviation (although only need the last one) var tr1 = new Trend(tlen); for (var i=first; i